public void Add_NoExistingValues_AddsElementToTheRepository(LWW_SetWithVCElement <TestType> element)
        {
            _lwwSetService.Merge(new HashSet <LWW_SetWithVCElement <TestType> > {
                element
            }.ToImmutableHashSet(), ImmutableHashSet <LWW_SetWithVCElement <TestType> > .Empty);

            var repositoryValues = _repository.GetAdds();

            Assert.Contains(element, repositoryValues);
        }
        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);
        }
Exemplo n.º 3
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)));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 7
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);
        }
        public void Remove_AddExistsWithLowerTimestamp_AddsElementToTheRepository(TestType value, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

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

            _lwwSetService.Merge(new HashSet <LWW_SetWithVCElement <TestType> > {
                addElement
            }.ToImmutableHashSet(), new HashSet <LWW_SetWithVCElement <TestType> > {
                removeElement
            }.ToImmutableHashSet());

            var repositoryValues = _repository.GetRemoves();

            Assert.Contains(value, repositoryValues.Select(v => v.Value));
        }
        public void Lookup_Removed_ReturnsFalse(HashSet <LWW_SetWithVCElement <TestType> > existingAdds, HashSet <LWW_SetWithVCElement <TestType> > existingRemoves, TestType value, Node node)
        {
            _repository.PersistAdds(existingAdds.ToImmutableHashSet());
            _repository.PersistRemoves(existingRemoves.ToImmutableHashSet());

            var clock = ImmutableSortedDictionary <Node, long> .Empty;

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

            _lwwSetService.Merge(new HashSet <LWW_SetWithVCElement <TestType> > {
                addElement
            }.ToImmutableHashSet(), new HashSet <LWW_SetWithVCElement <TestType> > {
                removeElement
            }.ToImmutableHashSet());

            var lookup = _lwwSetService.Lookup(value);

            Assert.False(lookup);
        }
Exemplo n.º 12
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);
            }
        }
        public void Lookup_Added_ReturnsTrue(HashSet <LWW_SetWithVCElement <TestType> > existingAdds, HashSet <LWW_SetWithVCElement <TestType> > existingRemoves, LWW_SetWithVCElement <TestType> element)
        {
            _repository.PersistAdds(existingAdds.ToImmutableHashSet());
            _repository.PersistRemoves(existingRemoves.ToImmutableHashSet());

            _lwwSetService.Merge(new HashSet <LWW_SetWithVCElement <TestType> > {
                element
            }.ToImmutableHashSet(), ImmutableHashSet <LWW_SetWithVCElement <TestType> > .Empty);

            var lookup = _lwwSetService.Lookup(element.Value);

            Assert.True(lookup);
        }