private Dictionary <Node, CRDT.Application.Commutative.Set.OUR_SetWithVCService <TestType> > CreateCommutativeReplicas(List <Node> nodes) { var dictionary = new Dictionary <Node, CRDT.Application.Commutative.Set.OUR_SetWithVCService <TestType> >(); foreach (var node in nodes) { var repository = new OUR_SetWithVCRepository(); var service = new CRDT.Application.Commutative.Set.OUR_SetWithVCService <TestType>(repository); dictionary.Add(node, service); } return(dictionary); }
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); }