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

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

            _repository.PersistElements(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                new(value, tag, new VectorClock(clock.Add(node, 0)), false)
            }.ToImmutableHashSet());
        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 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);
            }
        }
Beispiel #6
0
        public void MergeAdds_SingleValueWithEmptyRepository_AddsElementsToTheRepository(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

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

            _ourSetService.Merge(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                element
            }.ToImmutableHashSet());

            var repositoryValues = _repository.GetElements();

            Assert.Equal(1, repositoryValues.Count(x => Equals(x, element)));
        }
        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);
        }
Beispiel #8
0
        public void MergeAdds_IsIdempotent(HashSet <OUR_OptimizedSetWithVCElement <TestType> > values, TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            _repository.PersistElements(values.ToImmutableHashSet());

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

            values.Add(element);

            _ourSetService.Merge(values.ToImmutableHashSet());
            _ourSetService.Merge(values.ToImmutableHashSet());
            _ourSetService.Merge(values.ToImmutableHashSet());

            var repositoryValues = _repository.GetElements();

            AssertContains(values, repositoryValues);
        }
Beispiel #9
0
        public void MergeAdds_UpdatedElementWithLowerTimestamp_DoesNotDoAnything(TestType value, Guid tag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

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

            _repository.PersistElements(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                element
            }.ToImmutableHashSet());

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

            _ourSetService.LocalAdd(newElement.Value, newElement.Tag, newElement.VectorClock);

            var repositoryValues = _repository.GetElements();

            Assert.Equal(1, repositoryValues.Count(x => Equals(x, element)));
            Assert.Equal(0, repositoryValues.Count(x => Equals(x, newElement)));
        }
Beispiel #10
0
        public void MergeAdds_IsCommutative(Guid firstTag, Guid secondTag, Node node)
        {
            var clock = ImmutableSortedDictionary <Node, long> .Empty;

            var firstElement  = new OUR_OptimizedSetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0)), false);
            var secondElement = new OUR_OptimizedSetWithVCElement <TestType>(_builder.Build(), secondTag, new VectorClock(clock.Add(node, 0)), false);
            var thirdElement  = new OUR_OptimizedSetWithVCElement <TestType>(_builder.Build(), secondTag, new VectorClock(clock.Add(node, 0)), false);
            var fourthElement = new OUR_OptimizedSetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0)), false);
            var fifthElement  = new OUR_OptimizedSetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0)), false);

            var firstRepository = new OUR_OptimizedSetWithVCRepository();
            var firstService    = new OUR_OptimizedSetWithVCService <TestType>(firstRepository);

            _repository.PersistElements(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                firstElement, secondElement, thirdElement
            }.ToImmutableHashSet());
            firstService.Merge(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                fourthElement, fifthElement
            }.ToImmutableHashSet());

            var firstRepositoryValues = firstRepository.GetElements();

            var secondRepository = new OUR_OptimizedSetWithVCRepository();
            var secondService    = new OUR_OptimizedSetWithVCService <TestType>(secondRepository);

            _repository.PersistElements(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                fourthElement, fifthElement
            }.ToImmutableHashSet());
            secondService.Merge(new HashSet <OUR_OptimizedSetWithVCElement <TestType> > {
                firstElement, secondElement, thirdElement
            }.ToImmutableHashSet());

            var secondRepositoryValues = firstRepository.GetElements();

            Assert.Equal(firstRepositoryValues, secondRepositoryValues);
        }