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]); }
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)); }
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]); }
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]); }
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]); }
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]); }