public void Cluster_CRDT_should_merge_the_update_with_existing_value() { RunOn(() => { var update = new Replicator.Update(KeyJ, new GSet <string>(), WriteLocal.Instance, x => ((GSet <string>)x).Add("a").Add("b")); _replicator.Tell(update); ExpectMsg(new Replicator.UpdateSuccess(KeyJ, null)); var update2 = new Replicator.Update(KeyJ, new GSet <string>(), WriteLocal.Instance, x => ((GSet <string>)x).Add("c")); _replicator.Tell(update2); ExpectMsg(new Replicator.UpdateSuccess(KeyJ, null)); _replicator.Tell(new Replicator.Get(KeyJ, ReadLocal.Instance)); ExpectMsg <Replicator.GetSuccess>(x => x.Data.Equals(new GSet <string>(new[] { "a", "b", "c" }.ToImmutableHashSet()))); }, _config.First); EnterBarrierAfterTestStep(); }
public void Cluster_CRDT_should_work_in_single_node_cluster() { Join(_config.First, _config.First); RunOn(() => { Within(TimeSpan.FromSeconds(5.0), () => { _replicator.Tell(Replicator.GetReplicaCount.Instance); ExpectMsg <Replicator.ReplicaCount>(); }); var changedProbe = CreateTestProbe(); _replicator.Tell(new Replicator.Subscribe(KeyA, changedProbe.Ref)); _replicator.Tell(new Replicator.Subscribe(KeyX, changedProbe.Ref)); Within(TimeSpan.FromSeconds(5.0), () => { _replicator.Tell(new Replicator.Get(KeyA, ReadLocal.Instance)); ExpectMsg(new Replicator.NotFound(KeyA, null)); }); var c3 = GCounter.Empty.Increment(_cluster.SelfUniqueAddress, 3); var update = new Replicator.Update(KeyA, GCounter.Empty, WriteLocal.Instance, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress, 3)); _replicator.Tell(update); ExpectMsg(new Replicator.UpdateSuccess(KeyA, null)); changedProbe.ExpectMsg(new Replicator.Changed(KeyA, c3)); _replicator.Tell(new Replicator.Get(KeyA, ReadLocal.Instance)); ExpectMsg(new Replicator.GetSuccess(KeyA, null, c3)); var changedProbe2 = CreateTestProbe(); _replicator.Tell(new Replicator.Subscribe(KeyA, changedProbe2.Ref)); changedProbe2.ExpectMsg(new Replicator.Changed(KeyA, c3)); var c4 = c3.Increment(_cluster.SelfUniqueAddress); _replicator.Tell(new Replicator.Update(KeyA, _writeTwo, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress))); ExpectMsg(new Replicator.UpdateTimeout(KeyA, null)); _replicator.Tell(new Replicator.Get(KeyA, ReadLocal.Instance)); ExpectMsg(new Replicator.GetSuccess(KeyA, null, c4)); changedProbe.ExpectMsg(new Replicator.Changed(KeyA, c4)); var c5 = c4.Increment(_cluster.SelfUniqueAddress); _replicator.Tell(new Replicator.Update(KeyA, _writeMajority, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress))); ExpectMsg(new Replicator.UpdateSuccess(KeyA, null)); _replicator.Tell(new Replicator.Get(KeyA, _readMajority)); ExpectMsg(new Replicator.GetSuccess(KeyA, null, c5)); changedProbe.ExpectMsg(new Replicator.Changed(KeyA, c5)); var c6 = c5.Increment(_cluster.SelfUniqueAddress); _replicator.Tell(new Replicator.Update(KeyA, _writeAll, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress))); ExpectMsg(new Replicator.UpdateSuccess(KeyA, null)); _replicator.Tell(new Replicator.Get(KeyA, _readAll)); ExpectMsg(new Replicator.GetSuccess(KeyA, null, c6)); changedProbe.ExpectMsg(new Replicator.Changed(KeyA, c6)); var c9 = GCounter.Empty.Increment(_cluster.SelfUniqueAddress, 9); _replicator.Tell(new Replicator.Update(KeyX, GCounter.Empty, WriteLocal.Instance, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress, 9))); ExpectMsg(new Replicator.UpdateSuccess(KeyX, null)); changedProbe.ExpectMsg(new Replicator.Changed(KeyX, c9)); _replicator.Tell(new Replicator.Delete(KeyX, WriteLocal.Instance)); ExpectMsg(new Replicator.DeleteSuccess(KeyX)); changedProbe.ExpectMsg(new Replicator.DataDeleted(KeyX), TimeSpan.FromMinutes(5.0)); _replicator.Tell(new Replicator.Get(KeyX, ReadLocal.Instance)); ExpectMsg(new Replicator.DataDeleted(KeyX)); _replicator.Tell(new Replicator.Get(KeyX, _readAll)); ExpectMsg(new Replicator.DataDeleted(KeyX)); _replicator.Tell(new Replicator.Update(KeyX, WriteLocal.Instance, x => ((GCounter)x).Increment(_cluster.SelfUniqueAddress))); ExpectMsg(new Replicator.DataDeleted(KeyX)); _replicator.Tell(new Replicator.Delete(KeyX, WriteLocal.Instance)); ExpectMsg(new Replicator.DataDeleted(KeyX)); _replicator.Tell(Replicator.GetKeyIds.Instance); ExpectMsg(new Replicator.GetKeysIdsResult(ImmutableHashSet <string> .Empty.Add("A"))); }, _config.First); EnterBarrierAfterTestStep(); }