public void Lookup_SingleElementAdded_ReturnsTrue(OUR_SetWithVCElement <TestType> value) { _orSetService.Merge(new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet(), ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty); var lookup = _orSetService.Lookup(value.Value); Assert.True(lookup); }
public void Update_NotExistingValue_DoesNotAddToTheAddsSet(TestType value, Guid tag, Node node) { var clock = ImmutableSortedDictionary <Node, long> .Empty; var ourSet = new OUR_SetWithVC <TestType>(); ourSet = ourSet.Update(value, tag, new VectorClock(clock.Add(node, 0))); var element = new OUR_SetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0))); Assert.DoesNotContain(element, ourSet.Adds); }
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); }
public void Lookup_NonExistingElement_ReturnsFalse(OUR_SetWithVCElement <TestType> value) { _orSetService.Merge(new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet(), new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet()); var lookup = _orSetService.Lookup(value.Value); Assert.False(lookup); }
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))); }
public void MergeAdds_SingleValueWithEmptyRepository_AddsElementsToTheRepository(TestType value, Guid tag, Node node) { var clock = ImmutableSortedDictionary <Node, long> .Empty; var element = new OUR_SetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0))); _orSetService.Merge(new List <OUR_SetWithVCElement <TestType> > { element }.ToImmutableHashSet(), ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty); var repositoryValues = _repository.GetAdds(); Assert.Equal(1, repositoryValues.Count(x => Equals(x, element))); }
public void Merge_MergesAddsAndRemoves(OUR_SetWithVCElement <TestType> one, OUR_SetWithVCElement <TestType> two, OUR_SetWithVCElement <TestType> three, OUR_SetWithVCElement <TestType> four, OUR_SetWithVCElement <TestType> five) { var ourSet = new OUR_SetWithVC <TestType>(new[] { one, two }.ToImmutableHashSet(), new[] { three }.ToImmutableHashSet()); var newOrSet = ourSet.Merge(new[] { three, four }.ToImmutableHashSet(), new[] { five }.ToImmutableHashSet()); Assert.Equal(4, newOrSet.Adds.Count); Assert.Equal(2, newOrSet.Removes.Count); Assert.Contains(one, newOrSet.Adds); Assert.Contains(two, newOrSet.Adds); Assert.Contains(three, newOrSet.Adds); Assert.Contains(four, newOrSet.Adds); Assert.Contains(three, newOrSet.Removes); Assert.Contains(five, newOrSet.Removes); }
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); }
public void MergeAdds_IsIdempotent(List <OUR_SetWithVCElement <TestType> > values, TestType value, Guid tag, Node node) { var clock = ImmutableSortedDictionary <Node, long> .Empty; _repository.PersistAdds(values.ToImmutableHashSet()); var element = new OUR_SetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 0))); values.Add(element); _orSetService.Merge(values.ToImmutableHashSet(), ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty); _orSetService.Merge(values.ToImmutableHashSet(), ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty); _orSetService.Merge(values.ToImmutableHashSet(), ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty); var repositoryValues = _repository.GetAdds(); AssertContains(values, repositoryValues); }
public void MergeAdds_UpdatedElementWithLowerTimestamp_DoesNotDoAnything(TestType value, Guid tag, Node node) { var clock = ImmutableSortedDictionary <Node, long> .Empty; var element = new OUR_SetWithVCElement <TestType>(value, tag, new VectorClock(clock.Add(node, 1))); _repository.PersistAdds(new List <OUR_SetWithVCElement <TestType> > { element }.ToImmutableHashSet()); var newElement = new OUR_SetWithVCElement <TestType>(_builder.Build(value.Id), tag, new VectorClock(clock.Add(node, 0))); _orSetService.LocalAdd(newElement.Value, newElement.Tag, newElement.VectorClock); var repositoryValues = _repository.GetAdds(); Assert.Equal(1, repositoryValues.Count(x => Equals(x, element))); Assert.Equal(0, repositoryValues.Count(x => Equals(x, newElement))); }
public void MergeRemoves_IsCommutative(Guid firstTag, Guid secondTag, Node node) { var clock = ImmutableSortedDictionary <Node, long> .Empty; var firstElement = new OUR_SetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0))); var secondElement = new OUR_SetWithVCElement <TestType>(_builder.Build(), secondTag, new VectorClock(clock.Add(node, 0))); var thirdElement = new OUR_SetWithVCElement <TestType>(_builder.Build(), secondTag, new VectorClock(clock.Add(node, 0))); var fourthElement = new OUR_SetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0))); var fifthElement = new OUR_SetWithVCElement <TestType>(_builder.Build(), firstTag, new VectorClock(clock.Add(node, 0))); var firstRepository = new OUR_SetWithVCRepository(); var firstService = new OUR_SetWithVCService <TestType>(firstRepository); firstRepository.PersistRemoves(new List <OUR_SetWithVCElement <TestType> > { firstElement, secondElement, thirdElement }.ToImmutableHashSet()); firstRepository.PersistAdds(new List <OUR_SetWithVCElement <TestType> > { fourthElement, fifthElement }.ToImmutableHashSet()); firstService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, new List <OUR_SetWithVCElement <TestType> > { fourthElement, fifthElement }.ToImmutableHashSet()); var firstRepositoryValues = firstRepository.GetRemoves(); var secondRepository = new OUR_SetWithVCRepository(); var secondService = new OUR_SetWithVCService <TestType>(secondRepository); secondRepository.PersistRemoves(new List <OUR_SetWithVCElement <TestType> > { fourthElement, fifthElement }.ToImmutableHashSet()); secondRepository.PersistAdds(new List <OUR_SetWithVCElement <TestType> > { firstElement, secondElement, thirdElement }.ToImmutableHashSet()); secondService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, new List <OUR_SetWithVCElement <TestType> > { firstElement, secondElement, thirdElement }.ToImmutableHashSet()); var secondRepositoryValues = firstRepository.GetRemoves(); Assert.Equal(firstRepositoryValues, secondRepositoryValues); }
public void Create_CreatesSetWithElements(OUR_SetWithVCElement <TestType> one, OUR_SetWithVCElement <TestType> two, OUR_SetWithVCElement <TestType> three) { var adds = new[] { one, two }.ToImmutableHashSet(); var removes = new[] { two, three }.ToImmutableHashSet(); var ourSet = new OUR_SetWithVC <TestType>(adds, removes); Assert.Equal(adds.Count, ourSet.Adds.Count); Assert.Equal(removes.Count, ourSet.Removes.Count); foreach (var add in adds) { Assert.Contains(add, ourSet.Adds); } foreach (var remove in removes) { Assert.Contains(remove, ourSet.Removes); } }
public void MergeRemoves_IsIdempotent(List <OUR_SetWithVCElement <TestType> > values, OUR_SetWithVCElement <TestType> value) { _repository.PersistRemoves(values.ToImmutableHashSet()); _repository.PersistAdds(new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet()); values.Add(value); _orSetService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, values.ToImmutableHashSet()); _orSetService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, values.ToImmutableHashSet()); _orSetService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, values.ToImmutableHashSet()); var repositoryValues = _repository.GetRemoves(); AssertContains(values, repositoryValues); }
public void MergeRemoves_SingleElement_AddsElementsToTheRepository(List <OUR_SetWithVCElement <TestType> > existingValues, OUR_SetWithVCElement <TestType> value) { _repository.PersistRemoves(existingValues.ToImmutableHashSet()); _repository.PersistAdds(new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet()); _orSetService.Merge(ImmutableHashSet <OUR_SetWithVCElement <TestType> > .Empty, new List <OUR_SetWithVCElement <TestType> > { value }.ToImmutableHashSet()); var repositoryValues = _repository.GetRemoves(); Assert.Equal(1, repositoryValues.Count(x => Equals(x, value))); }