Exemple #1
0
        public void Add_Concurrent_AddsOnlyOneElement(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, 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.Adds.Count(v => Equals(v, element)));
        }
Exemple #2
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);
        }
Exemple #3
0
        public void Add_AddsElementToAddsSet(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)));

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

            Assert.Contains(element, ourSet.Adds);
        }
Exemple #4
0
        public void Lookup_AddedAndNotRemoved_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)));

            var lookup = ourSet.Lookup(value);

            Assert.True(lookup);
        }
Exemple #5
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);
        }
Exemple #6
0
        public void Update_UpdatesElementInAddsSet(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_SetWithVC <TestType>();

            var newValue   = _builder.Build(value.Id);
            var newElement = new OUR_SetWithVCElement <TestType>(newValue, tag, new VectorClock(clock.Add(node, 1)));

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

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

            Assert.Contains(newElement, ourSet.Adds);
            Assert.DoesNotContain(element, ourSet.Adds);
        }