public void A_LWWDictionary_should_be_able_to_remove_entry() { var m1 = LWWDictionary.Create( Tuple.Create(_node1, "a", 1), Tuple.Create(_node2, "b", 2)); var m2 = LWWDictionary.Create(_node2, "c", 3); var merged1 = m1.Merge(m2); var m3 = merged1.Remove(_node1, "b"); Assert.Equal(merged1.Merge(m3).Entries, ImmutableDictionary.CreateRange(new[] { new KeyValuePair <string, int>("a", 1), new KeyValuePair <string, int>("c", 3) })); // but if there is a conflicting update the entry is not removed var m4 = merged1.SetItem(_node2, "b", 22); Assert.Equal(m3.Merge(m4).Entries, ImmutableDictionary.CreateRange(new[] { new KeyValuePair <string, int>("a", 1), new KeyValuePair <string, int>("b", 22), new KeyValuePair <string, int>("c", 3) })); }
public void A_LWWDictionary_should_be_able_to_set_entries() { var m = LWWDictionary.Create( Tuple.Create(_node1, "a", 1), Tuple.Create(_node2, "b", 2)); Assert.Equal(m.Entries, ImmutableDictionary.CreateRange(new[] { new KeyValuePair <string, int>("a", 1), new KeyValuePair <string, int>("b", 2) })); }
protected Update CreateUpdateStateCompletedCommand(string innerKey, IWriteConsistency writeConsistency = null) { return(Dsl.Update( key: new LWWDictionaryKey <string, DeduplicationState>( _receiver.ReplicatorKey), initial: LWWDictionary.Create(node: _receiver.SelfUniqueAddress, key: innerKey, value: new DeduplicationState() { NumberAttempts = 0, ProcessingState = DeduplicationProcessingState.Processed, PruneAfter = _receiver.PruningConfiguration .PruneAttemptedAfter != null ? DateTime.UtcNow + _receiver .PruningConfiguration.PruneAttemptedAfter : null }) , consistency: writeConsistency, modify: dds => { if (dds.TryGetValue(innerKey, out DeduplicationState state)) { state.ProcessingState = DeduplicationProcessingState.Processed; state.PruneAfter = DateTime.UtcNow + _receiver .PruningConfiguration.PruneCompletedAfter; return dds.SetItem(_receiver.SelfUniqueAddress, innerKey, state); } else { return dds.SetItem(_receiver.SelfUniqueAddress, innerKey, new DeduplicationState() { NumberAttempts = 0, ProcessingState = DeduplicationProcessingState .Processed, PruneAfter = DateTime.UtcNow + _receiver .PruningConfiguration .PruneCompletedAfter }); } })); }
public void A_LWWDictionary_should_be_able_to_have_its_entries_correctly_merged_with_another_LWWMap_with_other_entries() { var m1 = LWWDictionary.Create( Tuple.Create(_node1, "a", 1), Tuple.Create(_node1, "b", 2)); var m2 = LWWDictionary.Create(_node2, "c", 3); var expected = ImmutableDictionary.CreateRange(new[] { new KeyValuePair <string, int>("a", 1), new KeyValuePair <string, int>("b", 2), new KeyValuePair <string, int>("c", 3), }); // merge both ways Assert.Equal(expected, m1.Merge(m2).Entries); Assert.Equal(expected, m2.Merge(m1).Entries); }
protected Update CreateAdvanceAndGetStateCommand(string innerKey, IWriteConsistency writeConsistency) { return(Dsl.Update( key: new LWWDictionaryKey <string, DeduplicationState>( _receiver.ReplicatorKey), initial: LWWDictionary.Create(node: _receiver.SelfUniqueAddress, key: innerKey, value: new DeduplicationState() { NumberAttempts = 0, ProcessingState = DeduplicationProcessingState.NotAttempted, PruneAfter = _receiver.PruningConfiguration .PruneNotAttemptedAfter != null ? DateTime.UtcNow + _receiver .PruningConfiguration.PruneNotAttemptedAfter : (DateTime?)null } ) , consistency: writeConsistency, modify: dds => { if (dds.TryGetValue(innerKey, out DeduplicationState state)) { if (state.ProcessingState == DeduplicationProcessingState.Error || state.ProcessingState == DeduplicationProcessingState.Processed) { return dds; } else if (state.NumberAttempts < _receiver.MaxAttempts) { state.NumberAttempts = state.NumberAttempts + 1; state.ProcessingState = DeduplicationProcessingState .Attempted; state.PruneAfter = _receiver.PruningConfiguration .PruneAttemptedAfter != null ? DateTime.UtcNow + _receiver .PruningConfiguration.PruneAttemptedAfter : (DateTime?)null; return dds.SetItem(_receiver.SelfUniqueAddress, innerKey, state); } else { state.ProcessingState = DeduplicationProcessingState.Error; state.PruneAfter = DateTime.UtcNow + _receiver .PruningConfiguration.PruneErroredAfter; return dds.SetItem(_receiver.SelfUniqueAddress, innerKey, state); } } else { return dds.SetItem(_receiver.SelfUniqueAddress, innerKey, new DeduplicationState() { NumberAttempts = 0, ProcessingState = DeduplicationProcessingState .NotAttempted, PruneAfter = _receiver.PruningConfiguration .PruneNotAttemptedAfter != null ? DateTime.UtcNow + _receiver .PruningConfiguration.PruneNotAttemptedAfter : (DateTime?)null }); } })); }