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

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

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

            Assert.Same(ourSet, newOrSet);
        }
        public void Update_NotExistingValue_DoesNotAddToTheAddsSet(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

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

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

            Assert.DoesNotContain(element, ourSet.Elements);
        }
        public void Add_AddsElementToAddsSet(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

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

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

            Assert.Contains(element, ourSet.Elements);
        }
        public void Lookup_AddedAndNotRemoved_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

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

            var lookup = ourSet.Lookup(value);

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

            var ourSet = new OUR_OptimizedSetWithVC <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_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0)), false);

            Assert.Equal(1, ourSet.Elements.Count(v => Equals(v, element)));
        }
        public void Create_CreatesSetWithElements(OUR_OptimizedSetWithVCElement <TestType> one, OUR_OptimizedSetWithVCElement <TestType> two,
                                                  OUR_OptimizedSetWithVCElement <TestType> three)
        {
            var elements = new[] { one, two, three }.ToImmutableHashSet();

            var ourSet = new OUR_OptimizedSetWithVC <TestType>(elements);

            Assert.Equal(elements.Count, ourSet.Elements.Count);

            foreach (var element in elements)
            {
                Assert.Contains(element, ourSet.Elements);
            }
        }
        public void Lookup_SameValueWithSeveralTags_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <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);
        }
示例#8
0
        public void Lookup_SameValueWithSeveralTags_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0)), false) }.ToImmutableHashSet());
            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(value, Guid.NewGuid(), new VectorClock(clock.Add(node, 0)), false) }.ToImmutableHashSet());

            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 2)), true) }.ToImmutableHashSet());

            var lookup = ourSet.Lookup(value);

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

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

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

            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_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0)), false);

            Assert.Contains(newElement, ourSet.Elements);
            Assert.DoesNotContain(element, ourSet.Elements);
        }
示例#10
0
        public void Lookup_AddedRemovedAndUpdated_ReturnsTrue(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var ourSet = new OUR_OptimizedSetWithVC <TestType>();

            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0)), false) }.ToImmutableHashSet());
            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 1)), true) }.ToImmutableHashSet());

            var newValue = new TestTypeBuilder(new Random()).Build(value.Id);

            ourSet = ourSet.Merge(new[] { new OUR_OptimizedSetWithVCElement <TestType>(newValue, tag, new VectorClock(clock.Add(node, 3)), false) }.ToImmutableHashSet());

            var lookup = ourSet.Lookup(newValue);

            Assert.True(lookup);
        }
        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_OptimizedSetWithVC <TestType>();

            ourSet = ourSet.Add(one, tagOne, new VectorClock(clock.Add(node, 0)));
            ourSet = ourSet.Add(one, tagTwo, new VectorClock(clock.Add(node, 1)));
            ourSet = ourSet.Remove(one, tagTwo, new VectorClock(clock.Add(node, 2)));
            ourSet = ourSet.Add(two, tagTwo, new VectorClock(clock.Add(node, 3)));
            ourSet = ourSet.Add(two, tagOne, new VectorClock(clock.Add(node, 4)));
            ourSet = ourSet.Remove(two, tagOne, new VectorClock(clock.Add(node, 5)));
            ourSet = ourSet.Remove(three, tagThree, new VectorClock(clock.Add(node, 6)));
            ourSet = ourSet.Add(three, tagThree, new VectorClock(clock.Add(node, 7)));
            ourSet = ourSet.Remove(three, tagThree, new VectorClock(clock.Add(node, 8)));

            var actualValues = ourSet.Values;

            Assert.Equal(2, actualValues.Count);
            Assert.Contains(one, actualValues);
            Assert.Contains(two, actualValues);
        }
示例#12
0
        public void Merge_MergesAddsAndRemoves(TestType one, TestType two, TestType three, Guid tagOne, Guid tagTwo, Guid tagThree, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var orSet = new OUR_OptimizedSetWithVC <TestType>(new[] {
                new OUR_OptimizedSetWithVCElement <TestType>(one, tagOne, new VectorClock(clock.Add(node, 1)), false),
                new OUR_OptimizedSetWithVCElement <TestType>(two, tagOne, new VectorClock(clock.Add(node, 7)), true),
                new OUR_OptimizedSetWithVCElement <TestType>(three, tagThree, new VectorClock(clock.Add(node, 3)), false),
            }.ToImmutableHashSet());

            var newOrSet = orSet.Merge(new[] {
                new OUR_OptimizedSetWithVCElement <TestType>(one, tagOne, new VectorClock(clock.Add(node, 4)), false),
                new OUR_OptimizedSetWithVCElement <TestType>(one, tagTwo, new VectorClock(clock.Add(node, 5)), true),
                new OUR_OptimizedSetWithVCElement <TestType>(two, tagOne, new VectorClock(clock.Add(node, 6)), false),
                new OUR_OptimizedSetWithVCElement <TestType>(three, tagThree, new VectorClock(clock.Add(node, 7)), false),
            }.ToImmutableHashSet());

            Assert.Equal(7, newOrSet.Elements.Count);
            Assert.Contains(new OUR_OptimizedSetWithVCElement <TestType>(one, tagOne, new VectorClock(clock.Add(node, 4)), false), newOrSet.Elements);
            Assert.Contains(new OUR_OptimizedSetWithVCElement <TestType>(two, tagOne, new VectorClock(clock.Add(node, 7)), true), newOrSet.Elements);
            Assert.Contains(new OUR_OptimizedSetWithVCElement <TestType>(three, tagThree, new VectorClock(clock.Add(node, 7)), false), newOrSet.Elements);
            Assert.Contains(new OUR_OptimizedSetWithVCElement <TestType>(one, tagTwo, new VectorClock(clock.Add(node, 5)), true), newOrSet.Elements);
        }