Example #1
0
        public void Remove_Concurrent_AddsOnlyOneElementToRemoveSet(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 0)));

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

            Assert.Equal(1, ourSet.Removes.Count(v => Equals(v, element)));
        }
Example #2
0
        public void Remove_BeforeAdd_HasNoEffect(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            var newOrSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 0)));

            Assert.Same(ourSet, newOrSet);
        }
Example #3
0
        public void Values_ReturnsNonRemovedValues(TestType one, TestType two, TestType three, Guid tagOne, Guid tagTwo, Guid tagThree, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(one, tagOne, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(one, tagTwo, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(one, tagTwo, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(two, tagTwo, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(two, tagOne, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(two, tagOne, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(three, tagThree, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(three, tagThree, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(three, tagThree, new VectorClock(clock.Add(node, 0)));

            var actualValues = ourSet.Values;

            Assert.Equal(2, actualValues.Count);
            Assert.Contains(one, actualValues);
            Assert.Contains(two, actualValues);
        }
Example #4
0
        public void Lookup_AddedAndRemoved_ReturnsFalse(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 0)));

            var lookup = ourSet.Lookup(value);

            Assert.False(lookup);
        }
Example #5
0
        public void Remove_AddsElementToRemovesSet(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 0)));

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

            Assert.Contains(element, ourSet.Removes);
        }
Example #6
0
        public void Lookup_SameValueWithSeveralTags_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(value, Guid.NewGuid(), new VectorClock(clock.Add(node, 1)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 2)));

            var lookup = ourSet.Lookup(value);

            Assert.True(lookup);
        }
Example #7
0
        public void Lookup_AddedRemovedAndUpdated_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            ourSet = ourSet.Add(value, tag, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Remove(value, tag, new VectorClock(clock.Add(node, 1)));

            var newValue = _builder.Build(value.Id);

            ourSet = ourSet.Update(newValue, tag, new VectorClock(clock.Add(node, 1)));

            var lookup = ourSet.Lookup(newValue);

            Assert.True(lookup);
        }