public void DeltaPropagationSelector_must_collect_none_when_no_nodes()
        {
            var selector = new TestSelector(selfUniqueAddress, ImmutableArray <Address> .Empty);

            selector.Update("A", DeltaA);
            selector.CollectPropagations().Should().BeEmpty();
            selector.CleanupDeltaEntries();
            selector.HasDeltaEntries("A").Should().BeFalse();
        }
        public void DeltaPropagationSelector_must_collect_1_when_one_node()
        {
            var selector = new TestSelector(selfUniqueAddress, nodes.Take(1).ToImmutableArray());

            selector.Update("A", DeltaA);
            selector.Update("B", DeltaB);
            selector.CleanupDeltaEntries();
            selector.HasDeltaEntries("A").Should().BeTrue();
            selector.HasDeltaEntries("B").Should().BeTrue();
            var expected = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty
                                                .Add("A", new Delta(new DataEnvelope(DeltaA), 1L, 1L))
                                                .Add("B", new Delta(new DataEnvelope(DeltaB), 1L, 1L)));

            selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[] { new KeyValuePair <Address, DeltaPropagation>(nodes[0], expected), }));
            selector.CollectPropagations().Should().BeEmpty();
            selector.CleanupDeltaEntries();
            selector.HasDeltaEntries("A").Should().BeFalse();
            selector.HasDeltaEntries("B").Should().BeFalse();
        }
        public void DeltaPropagationSelector_must_keep_track_of_deltas_per_node()
        {
            var selector = new TestSelector(selfUniqueAddress, nodes.Take(3).ToImmutableArray());

            selector.Update("A", DeltaA);
            selector.Update("B", DeltaB);
            var expected = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty
                                                .Add("A", new Delta(new DataEnvelope(DeltaA), 1L, 1L))
                                                .Add("B", new Delta(new DataEnvelope(DeltaB), 1L, 1L)));

            selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[]
            {
                new KeyValuePair <Address, DeltaPropagation>(nodes[0], expected),
                new KeyValuePair <Address, DeltaPropagation>(nodes[1], expected),
            }));
            // new update before previous was propagated to all nodes
            selector.Update("C", DeltaC);
            var expected2 = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty
                                                 .Add("A", new Delta(new DataEnvelope(DeltaA), 1L, 1L))
                                                 .Add("B", new Delta(new DataEnvelope(DeltaB), 1L, 1L))
                                                 .Add("C", new Delta(new DataEnvelope(DeltaC), 1L, 1L)));
            var expected3 = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty
                                                 .Add("C", new Delta(new DataEnvelope(DeltaC), 1L, 1L)));

            selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[]
            {
                new KeyValuePair <Address, DeltaPropagation>(nodes[2], expected2),
                new KeyValuePair <Address, DeltaPropagation>(nodes[0], expected3),
            }));
            selector.CleanupDeltaEntries();
            selector.HasDeltaEntries("A").Should().BeFalse();
            selector.HasDeltaEntries("B").Should().BeFalse();
            selector.HasDeltaEntries("C").Should().BeTrue();
            selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[] { new KeyValuePair <Address, DeltaPropagation>(nodes[1], expected3), }));
            selector.CollectPropagations().Should().BeEmpty();
            selector.CleanupDeltaEntries();
            selector.HasDeltaEntries("C").Should().BeFalse();
        }