public void DeltaPropagationSelector_must_bump_version_for_each_update() { var delta1 = GSet <string> .Empty.Add("a1"); var delta2 = GSet <string> .Empty.Add("a2"); var delta3 = GSet <string> .Empty.Add("a3"); var selector = new TestSelector(selfUniqueAddress, nodes.Take(1).ToImmutableArray()); selector.Update("A", delta1); selector.CurrentVersion("A").Should().Be(1L); selector.Update("A", delta2); selector.CurrentVersion("A").Should().Be(2L); var expected1 = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty .Add("A", new Delta(new DataEnvelope(delta1.Merge(delta2)), 1L, 2L))); selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[] { new KeyValuePair <Address, DeltaPropagation>(nodes[0], expected1), })); selector.Update("A", delta3); selector.CurrentVersion("A").Should().Be(3L); var expected2 = new DeltaPropagation(selfUniqueAddress, false, ImmutableDictionary <string, Delta> .Empty .Add("A", new Delta(new DataEnvelope(delta3), 3L, 3L))); selector.CollectPropagations().Should().Equal(ImmutableDictionary.CreateRange(new[] { new KeyValuePair <Address, DeltaPropagation>(nodes[0], expected2), })); selector.CollectPropagations().Should().BeEmpty(); }
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(); }