Ejemplo n.º 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);
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
    public void CreatePackage(GameObject ranClientObj)
    {
        bool       isGreen    = (Random.value < 0.6f);
        ClientWire clientWire = ranClientObj.GetComponent <ClientWire>();

        ++clientWire.usedBy;
        packageObj = Instantiate(packagePrefab, ranClientObj.transform.position, Quaternion.identity);
        package    = packageObj.GetComponent <Package>();
        package.SetPackageSpeed(packageSpeed);
        package.SetClientWire(clientWire);
        clientWire.SetPackage(package);
        if (isGreen)
        {
            //Debug.Log("Green Green");
            package.SetSRColor(Color.green);
            clientWire.SetColor(2);
        }
        else
        {
            //Debug.Log("red red");
            package.SetSRColor(Color.red);
            clientWire.SetColor(1);
        }
        package.DoMove(serverPos.position);
    }
Ejemplo n.º 5
0
        public void Test()
        {
            var serverMap = BindToServer(LifetimeDefinition.Lifetime, new RdMap <int, Model> {
                IsMaster = true
            }, ourMapKey);
            var clientMap = BindToClient(LifetimeDefinition.Lifetime, new RdMap <int, Model> {
                IsMaster = false
            }, ourMapKey);

            ServerProtocol.Serializers.Register(Model.Read, Model.Write);
            ClientProtocol.Serializers.Register(Model.Read, Model.Write);

            // create model on client and transfer
            clientMap.Add(1, new Model());
            ClientWire.TransmitAllMessages();


            // capture model
            Model capturedModel = null;

            serverMap.View(LifetimeDefinition.Lifetime, (modelLifetime, key, model) =>
            {
                capturedModel = model;
            });



            Assert.NotNull(capturedModel);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
    public void StopClientWire(Transform clientWireObj)
    {
        ClientWire clientWire      = clientWireObj.GetComponent <ClientWire>();
        Color      clientWireColor = clientWire.GetColor();

        TextStatus(clientWireColor);
        clientWire.StopThisClientWire();
    }
Ejemplo n.º 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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 19
0
 private void PumpMessagesOnce_Master() => ClientWire.TransmitAllMessages();
Ejemplo n.º 20
0
 public void SetClientWire(ClientWire clientWire)
 {
     this.clientWire = clientWire;
 }