コード例 #1
0
        public void Bugfix_4198_PNCounterMapDeltas_must_merge_other_PNCounterMaps()
        {
            var m1 = PNCounterDictionary <string> .Empty
                     .Increment(_node1, "a", 1)
                     .Increment(_node1, "b", 3)
                     .Increment(_node1, "c", 2);

            var m2 = PNCounterDictionary <string> .Empty.Increment(_node2, "c", 5);

            // This is how deltas really get merged inside the replicator
            var dataEnvelope = new DataEnvelope(m1.Delta);

            if (dataEnvelope.Data is IReplicatedDelta withDelta)
            {
                dataEnvelope = dataEnvelope.WithData(withDelta.Zero.MergeDelta(withDelta));
            }

            // Bug: this is was an ORDictionary<string, PNCounter> under #4198
            var storedData = dataEnvelope.Data;

            // simulate merging an update
            var m3 = (PNCounterDictionary <string>)storedData.Merge(m2);

            var expected = new Dictionary <string, BigInteger>
            {
                { "a", 1 },
                { "b", 3 },
                { "c", 7 },
            }.ToImmutableDictionary();

            m3.Entries.ShouldBeEquivalentTo(expected);
        }
コード例 #2
0
        public async Task Bugfix_4400_LWWDictionary_Deltas_must_merge_other_LWWDictionary()
        {
            var m1 = LWWDictionary <string, string> .Empty
                     .SetItem(_node1, "a", "A")
                     .SetItem(_node1, "b", "B1");

            await Task.Delay(200);

            var m2 = LWWDictionary <string, string> .Empty
                     .SetItem(_node2, "c", "C")
                     .SetItem(_node2, "b", "B2");

            // This is how deltas really get merged inside the replicator
            var dataEnvelope = new DataEnvelope(m1.Delta);

            if (dataEnvelope.Data is IReplicatedDelta withDelta)
            {
                dataEnvelope = dataEnvelope.WithData(withDelta.Zero.MergeDelta(withDelta));
            }

            // Bug: this is was an ORDictionary<string, ORSet<string>> under #4302
            var storedData = dataEnvelope.Data;

            // simulate merging an update
            var merged1 = (LWWDictionary <string, string>)m2.Merge(storedData);

            merged1.Entries["a"].Should().BeEquivalentTo("A");
            merged1.Entries["b"].Should().BeEquivalentTo("B2");
            merged1.Entries["c"].Should().BeEquivalentTo("C");
        }
コード例 #3
0
        public void Bugfix_4367_ORMultiValueDictionary_Deltas_must_merge_other_ORMultiValueDictionary()
        {
            var m1 = ORMultiValueDictionary <string, string> .EmptyWithValueDeltas
                     .SetItems(_node1, "a", ImmutableHashSet.Create("A"))
                     .SetItems(_node1, "b", ImmutableHashSet.Create("B1"));

            var m2 = ORMultiValueDictionary <string, string> .EmptyWithValueDeltas
                     .SetItems(_node2, "c", ImmutableHashSet.Create("C"))
                     .SetItems(_node2, "b", ImmutableHashSet.Create("B2"));

            // This is how deltas really get merged inside the replicator
            var dataEnvelope = new DataEnvelope(m1.Delta);

            if (dataEnvelope.Data is IReplicatedDelta withDelta)
            {
                dataEnvelope = dataEnvelope.WithData(withDelta.Zero.MergeDelta(withDelta));
            }

            // Bug: this is was an ORDictionary<string, ORSet<string>> under #4302
            var storedData = dataEnvelope.Data;

            // simulate merging an update
            var merged1 = (ORMultiValueDictionary <string, string>)m2.Merge(storedData);

            merged1.Entries["a"].Should().BeEquivalentTo("A");
            merged1.Entries["b"].Should().BeEquivalentTo("B1", "B2");
            merged1.Entries["c"].Should().BeEquivalentTo("C");
        }