コード例 #1
0
        public void NetworkControllerSubscriptionCacheIsSentOnlyOnce()
        {
            byte[] b = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();
            FakeSender        sender = new FakeSender();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            SenderBase.FactoryMethod = e => sender;

            TestSubscriber subscriber = new TestSubscriber();

            subscriber.Subscribe();

            Message msg = new Message();

            msg.Data   = b;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            Thread.Sleep(3000);
            Assert.AreEqual(1, sender._messages[MessageType.Subscribe]);
        }
コード例 #2
0
        public void NetworkControllerSubscriptionMessageIsProcessed()
        {
            byte[] b = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            FakeSender sender = new FakeSender();

            SenderBase.FactoryMethod = e => sender;

            Message msg = new Message();

            msg.Data   = b;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            PublisherWithCallbackMethod p = new PublisherWithCallbackMethod();

            Start.Publisher(p);


            server.SubscriptionMessage(typeof(bool));
            Thread.Sleep(1000);
            Assert.IsTrue(sender._messages.ContainsKey(MessageType.SubscribeResponse));
        }
コード例 #3
0
        public void NetworkControllerSendShutDownMessage()
        {
            byte[] b = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();
            FakeSender        sender = new FakeSender();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            SenderBase.FactoryMethod = e => sender;

            Message msg = new Message();

            msg.Data   = b;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            Stop.Ella();

            Assert.AreEqual(1, sender._messages[MessageType.NodeShutdown]);
        }
コード例 #4
0
        public void MessageFromSubscriberIsSentToCorrectHost()
        {
            byte[] b = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            FakeSender sender = new FakeSender();

            SenderBase.FactoryMethod = e => sender;

            Message msg = new Message();

            msg.Data   = b;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            TestSubscriber s = new TestSubscriber();

            s.Subscribe();
            server.SubscribeResponseMessageEvent(sender._id);
            Thread.Sleep(1000);
            s.SendMessage();
            Thread.Sleep(1000);
            Assert.AreEqual(1, sender._messages[MessageType.ApplicationMessage]);
        }
コード例 #5
0
        public void NetworkControllerSendMessage()
        {
            byte[] data = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        server = new FakeServer();
            FakeSender        sender = new FakeSender();

            nc.Servers.Add(server);
            Networking.NetworkController = nc;
            Networking.Start();

            SenderBase.FactoryMethod = e => sender;

            Message msg = new Message();

            msg.Data   = data;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            server.DiscoveryMessageEvent(msg, ep);

            TestSubscriber s = new TestSubscriber();

            s.Subscribe();

            byte[] b = { 1, 2 };

            ApplicationMessage app = new ApplicationMessage();

            app.Data = b;

            RemoteSubscriptionHandle rh = new RemoteSubscriptionHandle();

            rh.PublisherNodeID = EllaConfiguration.Instance.NodeId + 1;

            Send.Message(app, rh, s);

            Thread.Sleep(1000);

            Assert.AreEqual(1, sender._messages[MessageType.ApplicationMessage]);
        }
コード例 #6
0
        public void NetworkControllerUnsubscribeFrom()
        {
            byte[] b = new byte[1024];

            NetworkController nc     = new NetworkController();
            FakeServer        fs     = new FakeServer();
            FakeSender        sender = new FakeSender();

            nc.Servers.Add(fs);
            Networking.NetworkController = nc;
            Networking.Start();

            SenderBase.FactoryMethod = e => sender;

            //this discoveryMessage is required to add the Instance to the RemoteHosts,
            //which is used in the NetworkController to send messages, subscribe, unsubscribe..
            //must call these MessageProcessor methods by hand, because the FakeSender just fakes the Send() implementation
            Message msg = new Message();

            msg.Data   = b;
            msg.Sender = EllaConfiguration.Instance.NodeId + 1;
            msg.Type   = MessageType.Discover;

            IPEndPoint ep = new IPEndPoint(IPAddress.Parse("234.234.234.4"), 3456);

            fs.DiscoveryMessageEvent(msg, ep);

            TestSubscriber s = new TestSubscriber();

            s.Subscribe();

            Thread.Sleep(1000);

            //after subscription is done: new MessageEvent of Type SubscribeResponse is faked in FakeServer
            fs.SubscribeResponseMessageEvent(sender._id);

            s.UnsubscribeFromRemote();

            Thread.Sleep(1000);

            Assert.AreEqual(1, sender._messages[MessageType.Unsubscribe]);
        }