public void Remove_BeforeAdd_HasNoEffect(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var newLwwSet = lwwSet.Remove(value, new VectorClock(clock.Add(node, 0)));

            Assert.Same(lwwSet, newLwwSet);
        }
        public void Add_AddsElementToAddsSet(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);

            Assert.Contains(add, lwwSet.Adds);
        }
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            lwwSet = lwwSet.Assign(value, new VectorClock(clock.Add(node, 0)));

            var lookup = lwwSet.Lookup(value);

            Assert.True(lookup);
        }
Beispiel #4
0
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var element = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));

            lwwSet = lwwSet.Merge(new[] { element }.ToImmutableHashSet(), ImmutableHashSet <LWW_SetWithVCElement <TestType> > .Empty);

            var lookup = lwwSet.Lookup(value);

            Assert.True(lookup);
        }
        public void Add_ConcurrentAdds_AddsOnlyOne(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var firstAdd  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var secondAdd = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));

            lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.VectorClock);
            lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.VectorClock);

            Assert.Equal(1, lwwSet.Adds.Count(e => Equals(e.Value, value)));
        }
Beispiel #6
0
        public void Lookup_AddedAndRemoved_ReturnsFalse(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add    = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var remove = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));

            lwwSet = lwwSet.Merge(new[] { add }.ToImmutableHashSet(), new[] { remove }.ToImmutableHashSet());

            var lookup = lwwSet.Lookup(value);

            Assert.False(lookup);
        }
        public void Add_AddSameElementTwiceWithDifferentTimestamp_UpdatesExistingElement(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var firstAdd  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var secondAdd = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));

            lwwSet = lwwSet.Assign(firstAdd.Value, firstAdd.VectorClock);
            lwwSet = lwwSet.Assign(secondAdd.Value, secondAdd.VectorClock);

            Assert.True(lwwSet.Adds.Count(e => Equals(e, secondAdd)) == 1);
            Assert.True(lwwSet.Adds.Count(e => Equals(e, firstAdd)) == 0);
        }
Beispiel #8
0
        public void Merge_MergesAddsAndRemoves(LWW_SetWithVCElement <TestType> one, LWW_SetWithVCElement <TestType> two, LWW_SetWithVCElement <TestType> three, LWW_SetWithVCElement <TestType> four, LWW_SetWithVCElement <TestType> five)
        {
            var lwwSet = new LWW_SetWithVC <TestType>(new[] { one, two }.ToImmutableHashSet(), new[] { three }.ToImmutableHashSet());

            var newLwwSet = lwwSet.Merge(new[] { three, four }.ToImmutableHashSet(), new[] { five }.ToImmutableHashSet());

            Assert.Equal(4, newLwwSet.Adds.Count);
            Assert.Equal(2, newLwwSet.Removes.Count);
            Assert.Contains(one, newLwwSet.Adds);
            Assert.Contains(two, newLwwSet.Adds);
            Assert.Contains(three, newLwwSet.Adds);
            Assert.Contains(four, newLwwSet.Adds);
            Assert.Contains(three, newLwwSet.Removes);
            Assert.Contains(five, newLwwSet.Removes);
        }
        public void Lookup_AddedAndRemoved_ReturnsFalse(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add    = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var remove = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);
            lwwSet = lwwSet.Remove(remove.Value, remove.VectorClock);

            var lookup = lwwSet.Lookup(value);

            Assert.False(lookup);
        }
        public void Remove_RemoveSameElementTwiceWithDifferentTimestamp_AddsOneElement(TestType value, Node node)
        {
            var clock  = ImmutableSortedDictionary <Node, long> .Empty;
            var lwwSet = new LWW_SetWithVC <TestType>();

            var add          = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 0)));
            var firstRemove  = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 1)));
            var secondRemove = new LWW_SetWithVCElement <TestType>(value, new VectorClock(clock.Add(node, 2)));

            lwwSet = lwwSet.Assign(add.Value, add.VectorClock);
            lwwSet = lwwSet.Remove(firstRemove.Value, firstRemove.VectorClock);
            lwwSet = lwwSet.Remove(secondRemove.Value, secondRemove.VectorClock);

            Assert.True(lwwSet.Removes.Count(e => Equals(e.Value, value)) == 1);
        }
Beispiel #11
0
        public void Create_CreatesSetWithElements(LWW_SetWithVCElement <TestType> one, LWW_SetWithVCElement <TestType> two, LWW_SetWithVCElement <TestType> three)
        {
            var adds = new[] { one, two }.ToImmutableHashSet();
            var removes = new[] { two, three }.ToImmutableHashSet();

            var lwwSet = new LWW_SetWithVC <TestType>(adds, removes);

            Assert.Equal(adds.Count, lwwSet.Adds.Count);
            Assert.Equal(removes.Count, lwwSet.Removes.Count);

            foreach (var add in adds)
            {
                Assert.Contains(add, lwwSet.Adds);
            }

            foreach (var remove in removes)
            {
                Assert.Contains(remove, lwwSet.Removes);
            }
        }