Exemple #1
0
        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);
        }
Exemple #2
0
        public void Test1()
        {
            var serverList = BindToServer(TestLifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);
            var clientList = BindToClient(TestLifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);

            Assert.True(serverList.Count == 0);
            Assert.True(clientList.Count == 0);
            serverList.Add("Server value 1");
            serverList.Add("Server value 2");
            serverList.Add("Server value 3");
            ServerWire.TransmitOneMessage();
            ServerWire.TransmitOneMessage();
            ServerWire.TransmitOneMessage();
            Assert.AreEqual(3, clientList.Count);

            serverList.Add("Server value 4");
            ServerWire.TransmitOneMessage();
            clientList[3] = "Client value 4";
            ClientWire.TransmitOneMessage();

            Assert.AreEqual("Client value 4", clientList[3]);
            Assert.AreEqual("Client value 4", serverList[3]);

            serverList.RemoveAt(0);

            ServerWire.TransmitOneMessage();
            Assert.AreEqual("Server value 2", clientList[0]);
            Assert.AreEqual("Server value 2", serverList[0]);
        }
Exemple #3
0
        public void Test3()
        {
            var serverProperty = BindToServer(LifetimeDefinition.Lifetime, new RdProperty <string> {
                IsMaster = true
            }, ourKey);
            var clientProperty = BindToClient(LifetimeDefinition.Lifetime, new RdProperty <string> {
                IsMaster = false
            }, ourKey);

            // Client -> Server
            clientProperty.SetValue("Client value 1");
            ClientWire.TransmitOneMessage();

            // Change server
            var serverValue1 = "Server value 1";

            serverProperty.SetValue(serverValue1);

            // Client -> Server one more time (server should not be updated)
            clientProperty.SetValue("Client value 2");
            ClientWire.TransmitOneMessage();

            // Server -> Client one more time (client should be updated)
            ServerWire.TransmitOneMessage();

            Assert.AreEqual(serverValue1, serverProperty.Value);
            Assert.AreEqual(serverValue1, clientProperty.Value);
        }
Exemple #4
0
        public void TestLifetimes2()
        {
            var serverList = BindToServer(LifetimeDefinition.Lifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);
            var clientList = BindToClient(LifetimeDefinition.Lifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);

            var itemRemovedServer = false;
            var itemRemovedClient = false;

            serverList.View(Lifetime.Eternal, (lifetime, key, value) =>
            {
                lifetime.OnTermination(() => { itemRemovedServer = true; });
            });

            clientList.View(Lifetime.Eternal, (lifetime, key, value) =>
            {
                lifetime.OnTermination(() => { itemRemovedClient = true; });
            });

            serverList.Add("Server value");
            ServerWire.TransmitOneMessage();

            clientList.RemoveAt(0);
            Assert.IsFalse(itemRemovedServer);

            ClientWire.TransmitOneMessage();

            Assert.IsTrue(itemRemovedServer);
            Assert.IsTrue(itemRemovedClient);
        }
Exemple #5
0
        public void TestLifetimes2()
        {
            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 itemRemovedServer = false;
            var itemRemovedClient = false;

            serverMap.View(Lifetime.Eternal, (lifetime, key, value) =>
            {
                lifetime.OnTermination(() => { itemRemovedServer = true; });
            });

            clientMap.View(Lifetime.Eternal, (lifetime, key, value) =>
            {
                lifetime.OnTermination(() => { itemRemovedClient = true; });
            });

            serverMap.Add(1, "Server value");
            ServerWire.TransmitOneMessage();

            clientMap.Remove(1);
            ClientWire.TransmitOneMessage(); //ack
            Assert.IsFalse(itemRemovedServer);

            ClientWire.TransmitOneMessage();

            Assert.IsTrue(itemRemovedServer);
            Assert.IsTrue(itemRemovedClient);
        }
Exemple #6
0
        public void Test1()
        {
            var serverProperty = BindToServer(LifetimeDefinition.Lifetime, new RdProperty <string> {
                IsMaster = true
            }, ourKey);
            var clientProperty = BindToClient(LifetimeDefinition.Lifetime, new RdProperty <string> {
                IsMaster = false
            }, ourKey);

            // Everything is empty
            Assert.False(serverProperty.Maybe.HasValue);
            Assert.False(clientProperty.Maybe.HasValue);

            // Init server
            var serverValue1 = "Server value 1";

            serverProperty.SetValue(serverValue1);
            Assert.AreEqual(serverValue1, serverProperty.Value);
            Assert.False(clientProperty.Maybe.HasValue);

            // Server -> Client
            ServerWire.TransmitOneMessage();
            Assert.AreEqual(serverValue1, clientProperty.Value);

            // Client -> Server
            var clientValue1 = "Client value 1";

            clientProperty.SetValue(clientValue1);
            ClientWire.TransmitOneMessage();
            Assert.AreEqual(clientValue1, serverProperty.Value);
            Assert.AreEqual(clientValue1, clientProperty.Value);
        }
Exemple #7
0
        public void Test5()
        {
            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");
            ServerWire.TransmitOneMessage();

            clientProperty.SetValue("Client value 1");
            ClientWire.TransmitOneMessage();

            clientProperty.SetValue("Client value 2");
            ClientWire.MissOneMessage();

            clientProperty.SetValue("Client value 3");
            ClientWire.TransmitOneMessage();

            serverProperty.SetValue("Server value 2");
            ServerWire.MissOneMessage();

            serverProperty.SetValue("Server value 3");
            ServerWire.TransmitOneMessage();

            Assert.AreEqual("Server value 3", serverProperty.Value);
            Assert.AreEqual("Server value 3", clientProperty.Value);
        }
Exemple #8
0
        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);
        }
Exemple #9
0
        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);
        }
Exemple #10
0
        public void TestFireSignal()
        {
            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));

            serverSignal.Fire("server value");
            ServerWire.TransmitOneMessage();

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("server value", results[0]);
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        public void TestLifetimes1()
        {
            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 itemRemoved = "";

            serverMap.Add(1, "Server value");
            serverMap.View(LifetimeDefinition.Lifetime, (lifetime, i, s) => itemRemoved = i + ":" + s);
            ServerWire.TransmitOneMessage();

            clientMap.Remove(1);
            ClientWire.TransmitAllMessages();

            Assert.AreEqual("1:Server value", itemRemoved);
        }
Exemple #15
0
        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");
        }
Exemple #16
0
        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]);
        }
Exemple #17
0
        public void TestLifetimes1()
        {
            var serverList = BindToServer(TestLifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);
            var clientList = BindToClient(TestLifetime, new RdList <string> {
                OptimizeNested = true
            }, ourKey);

            var itemRemoved = "";

            serverList.Add("Server value");
            serverList.View(TestLifetime, (lifetime, i, s) => itemRemoved = i + ":" + s);
            ServerWire.TransmitOneMessage();

            clientList.Remove("Server value");
            clientList.Remove("Server value");
            ClientWire.TransmitAllMessages();

            Assert.AreEqual("0:Server value", itemRemoved);
        }
Exemple #18
0
        public void Test1()
        {
            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);

            Assert.True(serverMap.Count == 0);
            Assert.True(clientMap.Count == 0);
            serverMap.Add(1, "Server value 1");
            serverMap.Add(2, "Server value 2");
            serverMap.Add(3, "Server value 3");
            ServerWire.TransmitOneMessage();
            ServerWire.TransmitOneMessage();
            ServerWire.TransmitOneMessage();

            ClientWire.TransmitOneMessage(); //ack
            ClientWire.TransmitOneMessage(); //ack
            ClientWire.TransmitOneMessage(); //ack
            Assert.AreEqual(3, clientMap.Count);

            serverMap.Add(4, "Server value 4");
            clientMap.Add(4, "Client value 4");
            ServerWire.TransmitOneMessage();
            ClientWire.TransmitOneMessage(); //ack
            ClientWire.TransmitOneMessage();
            Assert.AreEqual("Server value 4", clientMap[4]);
            Assert.AreEqual("Server value 4", serverMap[4]);

            serverMap.Add(5, "Server value 5");
            clientMap.Add(5, "Client value 5");

            ClientWire.TransmitOneMessage();
            ServerWire.TransmitOneMessage();
            ClientWire.TransmitOneMessage(); //ack
            Assert.AreEqual("Server value 5", clientMap[5]);
            Assert.AreEqual("Server value 5", serverMap[5]);
        }
Exemple #19
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);
        }