public void Test2() { var serverList = BindToServer(TestLifetime, new RdList <string> { OptimizeNested = true }, ourKey); var clientList = BindToClient(TestLifetime, new RdList <string> { OptimizeNested = true }, ourKey); var log = new List <string>(); clientList.Advise(TestLifetime, (e) => log.Add(e.Kind + " " + e.Index + " " + e.NewValue)); serverList.Add("1"); serverList[0] = "2"; serverList[0] = "2"; //no value ServerWire.TransmitAllMessages(); clientList[0] = "1"; ClientWire.TransmitAllMessages(); serverList.Clear(); ServerWire.TransmitAllMessages(); Assert.AreEqual(new List <string> { "Add 0 1", "Update 0 2", "Update 0 1", "Remove 0 " }, log); }
public void Test2() { var serverMap = BindToServer(LifetimeDefinition.Lifetime, new RdMap <int, string> { IsMaster = true, OptimizeNested = true }, ourKey); var clientMap = BindToClient(LifetimeDefinition.Lifetime, new RdMap <int, string> { IsMaster = false, OptimizeNested = true }, ourKey); var log = new List <string>(); clientMap.Advise(LifetimeDefinition.Lifetime, (e) => log.Add(e.Kind + " " + e.Key + " " + e.NewValue)); serverMap.Add(1, "1"); serverMap[1] = "2"; serverMap[1] = "2"; //no value ServerWire.TransmitAllMessages(); clientMap[1] = "1"; ClientWire.TransmitAllMessages(); serverMap.Remove(1); ServerWire.TransmitAllMessages(); ClientWire.TransmitAllMessages(); //ack Assert.AreEqual(new List <string> { "Add 1 1", "Update 1 2", "Update 1 1", "Remove 1 " }, log); }
public void TestNullability() { var serverList = BindToServer(LifetimeDefinition.Lifetime, new RdList <string> { OptimizeNested = true }, ourKey); var clientList = BindToClient(LifetimeDefinition.Lifetime, new RdList <string> { OptimizeNested = true }, ourKey); Assert.Throws <ArgumentNullException>(() => { serverList.Add(null); }); ServerWire.TransmitAllMessages(); Assert.AreEqual(0, serverList.Count); Assert.AreEqual(0, clientList.Count); }
public void TestNullability() { var serverProperty = BindToServer(LifetimeDefinition.Lifetime, new RdProperty <string> { IsMaster = true }, ourKey); var clientProperty = BindToClient(LifetimeDefinition.Lifetime, new RdProperty <string> { IsMaster = false }, ourKey); serverProperty.SetValue("Server value 1"); Assert.Throws <Assertion.AssertionException>(() => { serverProperty.SetValue(null); }); ServerWire.TransmitAllMessages(); ClientWire.TransmitAllMessages(); Assert.AreEqual("Server value 1", serverProperty.Value); Assert.AreEqual("Server value 1", clientProperty.Value); }
public void TestNullability() { var serverMap = BindToServer(LifetimeDefinition.Lifetime, new RdMap <string, string> { IsMaster = true, OptimizeNested = true }, ourKey); var clientMap = BindToClient(LifetimeDefinition.Lifetime, new RdMap <string, string> { IsMaster = false, OptimizeNested = true }, ourKey); Assert.Throws <Assertion.AssertionException>(() => { serverMap.Add("", null); }); Assert.Throws <ArgumentNullException>(() => { serverMap.Add(null, ""); }); ServerWire.TransmitAllMessages(); ClientWire.TransmitAllMessages(); Assert.AreEqual(0, serverMap.Count); Assert.AreEqual(0, clientMap.Count); }
public void TestExtPreserveContextOnLateConnect(bool useHeavyContext) { var context = useHeavyContext ? RdContextBasicTest.TestKeyHeavy.Instance : (RdContext <string>)RdContextBasicTest.TestKeyLight.Instance; context.RegisterOn(ClientProtocol.Serializers); context.RegisterOn(ServerProtocol.Contexts); var serverModel = new InterningRoot1(LifetimeDefinition.Lifetime, ServerProtocol); var clientModel = new InterningRoot1(LifetimeDefinition.Lifetime, ClientProtocol); var serverExt = serverModel.GetOrCreateExtension("test", () => new InterningExt()); var fireValues = new[] { "a", "b", "c" }; ServerWire.AutoTransmitMode = false; ClientWire.AutoTransmitMode = false; foreach (var fireValue in fireValues) { context.Value = fireValue; serverExt.Root.Value = new InterningExtRootModel(); context.Value = null; } var numReceives = 0; var receivedContexts = new HashSet <string>(); var clientExt = clientModel.GetOrCreateExtension("test", () => new InterningExt()); clientExt.Root.AdviseNotNull(LifetimeDefinition.Lifetime, _ => { numReceives++; receivedContexts.Add(context.Value); }); ClientWire.AutoTransmitMode = true; ServerWire.AutoTransmitMode = true; ClientWire.TransmitAllMessages(); ServerWire.TransmitAllMessages(); Assert.AreEqual(3, numReceives); Assert.AreEqual(fireValues, receivedContexts); }
public void TestNullability() { var serverSet = BindToServer(LifetimeDefinition.Lifetime, new RdSet <string> { IsMaster = true }, ourKey); var clientSet = BindToClient(LifetimeDefinition.Lifetime, new RdSet <string> { IsMaster = false }, ourKey); serverSet.Add("Value"); Assert.Throws <Assertion.AssertionException>(() => { serverSet.Add(null); }); ServerWire.TransmitAllMessages(); ClientWire.TransmitAllMessages(); Assert.AreEqual(1, serverSet.Count); Assert.AreEqual(serverSet.First(), "Value"); Assert.AreEqual(1, clientSet.Count); Assert.AreEqual(clientSet.First(), "Value"); }
public void TestNullability() { var serverSignal = BindToServer(LifetimeDefinition.Lifetime, new RdSignal <string>(), ourKey); var clientSignal = BindToClient(LifetimeDefinition.Lifetime, new RdSignal <string>(), ourKey); var results = new List <string>(); clientSignal.Advise(LifetimeDefinition.Lifetime, value => results.Add(value)); Assert.Throws <Assertion.AssertionException>(() => { clientSignal.Fire(null); }); ServerWire.TransmitAllMessages(); serverSignal.Fire("server value"); ServerWire.TransmitAllMessages(); Assert.Throws <Assertion.AssertionException>(() => { clientSignal.Fire(null); }); ServerWire.TransmitAllMessages(); Assert.AreEqual(1, results.Count); Assert.AreEqual("server value", results[0]); }
private void PumpMessagesOnce_Slave() => ServerWire.TransmitAllMessages();
public void TestExtNoFailureOnQueuedNewContextValue(bool useHeavyContext) { var context = useHeavyContext ? RdContextBasicTest.TestKeyHeavy.Instance : (RdContext <string>)RdContextBasicTest.TestKeyLight.Instance; ServerWire.AutoTransmitMode = true; ClientWire.AutoTransmitMode = true; var barrierRegister = new Barrier(2); var barrier0 = new Barrier(2); var barrier1 = new Barrier(2); var barrier2 = new Barrier(2); var fireValues = new[] { "a", "b", "c" }; ServerProtocol.Scheduler.Queue(() => { barrierRegister.SignalAndWait(); context.RegisterOn(ServerProtocol.Contexts); var serverModel = new InterningRoot1(LifetimeDefinition.Lifetime, ServerProtocol); ServerWire.TransmitAllMessages(); barrier0.SignalAndWait(); // root model also uses ext semantics, so make sure both ends have created it and processed its connection message var serverExt = serverModel.GetOrCreateExtension("test", () => new InterningExt()); foreach (var fireValue in fireValues) { context.Value = fireValue; serverExt.Root.Value = new InterningExtRootModel(); context.Value = null; } barrier1.SignalAndWait(); }); var numReceives = 0; var receivedContexts = new HashSet <string>(); ClientProtocol.Scheduler.Queue(() => { context.RegisterOn(ClientProtocol.Serializers); barrierRegister.SignalAndWait(); var clientModel = new InterningRoot1(LifetimeDefinition.Lifetime, ClientProtocol); barrier0.SignalAndWait(); barrier1.SignalAndWait(); ServerProtocol.Scheduler.Queue(() => barrier2.SignalAndWait()); barrier2.SignalAndWait(); var clientExt = clientModel.GetOrCreateExtension("test", () => new InterningExt()); Thread.Sleep(500); clientExt.Root.AdviseNotNull(LifetimeDefinition.Lifetime, _ => { numReceives++; receivedContexts.Add(context.Value); }); }); SpinWait.SpinUntil(() => numReceives == 3, TimeSpan.FromMilliseconds(5_000)); Assert.AreEqual(3, numReceives); Assert.AreEqual(fireValues, receivedContexts); }