public void TestAlwaysUpdate() { // Setup var masterSystem = CreateSystem(); var master = masterSystem.CreateStreamWriter(); var slaveSystem = CreateSystem(); int slaveReplicaUpdated = 0; slaveSystem.ReplicaUpdated += x => ++ slaveReplicaUpdated; // Add var a = new Protobuf.TestObject() { Name = "A", State = 1 }; var idA = masterSystem.AddDynamicReplica(a, DynamicReplicaOptions.DefaultMaster | DynamicReplicaOptions.AlwaysUpdate); var b = new Protobuf.TestObject() { Name = "B", State = 1 }; var idB = masterSystem.AddDynamicReplica(a, DynamicReplicaOptions.DefaultMaster); master.WriteTo(slaveSystem); // Update slaveReplicaUpdated = 0; a.State = 2; b.State = 2; master.WriteTo(slaveSystem); Assert.AreEqual(slaveReplicaUpdated, 1); Assert.AreEqual(slaveSystem.GetReplica <Protobuf.TestObject>(idA).State, 2); Assert.AreEqual(slaveSystem.GetReplica <Protobuf.TestObject>(idB).State, 1); }
public void TestMultiMaster() { // Setup var masterSystem = CreateSystem(); var master = masterSystem.CreateStreamWriter(ReplicationStreamWriterOptions.AllowAllExceptAlwaysUpdate); var masterSpam = masterSystem.CreateStreamWriter(ReplicationStreamWriterOptions.AllowOnlyAlwaysUpdate); var slaveSystem = CreateSystem(); int slaveReplicaAdded = 0; int slaveReplicaUpdated = 0; slaveSystem.ReplicaAdded += x => ++ slaveReplicaAdded; slaveSystem.ReplicaUpdated += x => ++ slaveReplicaUpdated; // Add var a = new Protobuf.TestObject() { Name = "A" }; var idA = masterSystem.AddDynamicReplica(a, DynamicReplicaOptions.DefaultMaster | DynamicReplicaOptions.AlwaysUpdate); var b = new Protobuf.TestObject() { Name = "B" }; var idB = masterSystem.AddDynamicReplica(b, DynamicReplicaOptions.DefaultMaster); slaveReplicaAdded = 0; master.WriteTo(slaveSystem); masterSpam.WriteTo(slaveSystem); Assert.AreEqual(slaveReplicaAdded, 2); Assert.AreEqual(slaveSystem.Replicas.Count(), 2); // Update A a.State = 2; slaveReplicaUpdated = 0; master.WriteTo(slaveSystem); masterSpam.WriteTo(slaveSystem); Assert.AreEqual(slaveReplicaUpdated, 1); Assert.AreEqual(slaveSystem.GetReplica <Protobuf.TestObject>(idA).State, 2); // Update B masterSystem.UpdateReplica(idB, new Protobuf.TestObject() { State = 3 }); slaveReplicaUpdated = 0; master.WriteTo(slaveSystem); masterSpam.WriteTo(slaveSystem); Assert.AreEqual(slaveReplicaUpdated, 2); Assert.AreEqual(slaveSystem.GetReplica <Protobuf.TestObject>(idA).State, 2); Assert.AreEqual(slaveSystem.GetReplica <Protobuf.TestObject>(idB).State, 3); }