public void TestTransportServer() { ICodec <string> codec = new StringCodec(); BlockingCollection <string> queue = new BlockingCollection <string>(); List <string> events = new List <string>(); IPEndPoint endpoint = new IPEndPoint(_localIpAddress, 0); var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <string>(endpoint, remoteHandler, codec, _tcpPortProvider)) { server.Run(); IPEndPoint remoteEndpoint = new IPEndPoint(_localIpAddress, server.LocalEndpoint.Port); using (var client = new TransportClient <string>(remoteEndpoint, codec, _tcpClientFactory)) { client.Send("TestTransportServer - 1"); client.Send("TestTransportServer - 2"); client.Send("TestTransportServer - 3"); events.Add(queue.Take()); events.Add(queue.Take()); events.Add(queue.Take()); } } Assert.Equal(3, events.Count); Assert.Equal("TestTransportServer - 1", events[0]); Assert.Equal("TestTransportServer - 2", events[1]); Assert.Equal("TestTransportServer - 3", events[2]); }
public void TestTransportServerEvent() { ICodec <TestEvent> codec = new TestEventCodec(); BlockingCollection <TestEvent> queue = new BlockingCollection <TestEvent>(); List <TestEvent> events = new List <TestEvent>(); IPEndPoint endpoint = new IPEndPoint(_localIpAddress, 0); var remoteHandler = Observer.Create <TransportEvent <TestEvent> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <TestEvent>(endpoint, remoteHandler, codec, _tcpPortProvider)) { server.Run(); IPEndPoint remoteEndpoint = new IPEndPoint(_localIpAddress, server.LocalEndpoint.Port); using (var client = new TransportClient <TestEvent>(remoteEndpoint, codec)) { client.Send(new TestEvent("Hello")); client.Send(new TestEvent(", ")); client.Send(new TestEvent("World!")); events.Add(queue.Take()); events.Add(queue.Take()); events.Add(queue.Take()); } } Assert.Equal(3, events.Count); Assert.Equal(events[0].Message, "Hello"); Assert.Equal(events[1].Message, ", "); Assert.Equal(events[2].Message, "World!"); }
public void TestTransportSenderStage() { ICodec <string> codec = new StringCodec(); IPEndPoint endpoint = new IPEndPoint(_localIpAddress, 0); List <string> events = new List <string>(); BlockingCollection <string> queue = new BlockingCollection <string>(); // Server echoes the message back to the client var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => tEvent.Link.Write(tEvent.Data)); using (TransportServer <string> server = new TransportServer <string>(endpoint, remoteHandler, codec, _tcpPortProvider)) { server.Run(); var clientHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); IPEndPoint remoteEndpoint = new IPEndPoint(_localIpAddress, server.LocalEndpoint.Port); using (var client = new TransportClient <string>(remoteEndpoint, codec, clientHandler)) { client.Send("Hello"); client.Send(", "); client.Send(" World"); events.Add(queue.Take()); events.Add(queue.Take()); events.Add(queue.Take()); } } Assert.Equal(3, events.Count); Assert.Equal(events[0], "Hello"); Assert.Equal(events[1], ", "); Assert.Equal(events[2], " World"); }
public void TestTransportServerEvent() { ICodec <TestEvent> codec = new TestEventCodec(); int port = NetworkUtils.GenerateRandomPort(6000, 7000); BlockingCollection <TestEvent> queue = new BlockingCollection <TestEvent>(); List <TestEvent> events = new List <TestEvent>(); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); var remoteHandler = Observer.Create <TransportEvent <TestEvent> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <TestEvent>(endpoint, remoteHandler, codec)) { server.Run(); IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); using (var client = new TransportClient <TestEvent>(remoteEndpoint, codec)) { client.Send(new TestEvent("Hello")); client.Send(new TestEvent(", ")); client.Send(new TestEvent("World!")); events.Add(queue.Take()); events.Add(queue.Take()); events.Add(queue.Take()); } } Assert.AreEqual(3, events.Count); }
public void TestTransportSenderStage() { ICodec <string> codec = new StringCodec(); int port = NetworkUtils.GenerateRandomPort(6000, 7000); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); List <string> events = new List <string>(); BlockingCollection <string> queue = new BlockingCollection <string>(); // Server echoes the message back to the client var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => tEvent.Link.Write(tEvent.Data)); using (TransportServer <string> server = new TransportServer <string>(endpoint, remoteHandler, codec)) { server.Run(); var clientHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); using (var client = new TransportClient <string>(remoteEndpoint, codec, clientHandler)) { client.Send("Hello"); client.Send(", "); client.Send(" World"); events.Add(queue.Take()); events.Add(queue.Take()); events.Add(queue.Take()); } } Assert.AreEqual(3, events.Count); }
public NameServer([Parameter(typeof(NamingConfigurationOptions.NameServerPort))] int port) { IObserver <TransportEvent <NamingEvent> > handler = CreateServerHandler(); _idToAddrMap = new Dictionary <string, IPEndPoint>(); ICodec <NamingEvent> codec = CreateServerCodec(); // Start transport server, get listening IP endpoint _logger.Log(Level.Info, "Starting naming server"); _server = new TransportServer <NamingEvent>(port, handler, codec); _server.Run(); LocalEndpoint = _server.LocalEndpoint; }
public void TestRaceCondition() { ICodec <string> codec = new StringCodec(); var port = 0; BlockingCollection <string> queue = new BlockingCollection <string>(); List <string> events = new List <string>(); int numEventsExpected = 150; IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <string>(endpoint, remoteHandler, codec, _tcpPortProvider)) { server.Run(); int counter = 0; for (int i = 0; i < numEventsExpected / 3; i++) { Task.Run(() => { IPEndPoint remoteEndpoint = new IPEndPoint(_localIpAddress, server.LocalEndpoint.Port); using (var client = new TransportClient <string>(remoteEndpoint, codec, _tcpClientFactory)) { for (int j = 0; j < 3; j++) { client.Send("TestRaceCondition - " + counter++); } } }); } for (int i = 0; i < numEventsExpected; i++) { string e; do { e = queue.Take(); }while (e == null); events.Add(e); } } Assert.Equal(numEventsExpected, events.Count); foreach (var e in events) { Assert.True(e.StartsWith("TestRaceCondition - "), "Unexpected event [" + e + "]"); } }
private NameServer( [Parameter(typeof(NamingConfigurationOptions.NameServerPort))] int port, ITcpPortProvider tcpPortProvider) { IObserver <TransportEvent <NamingEvent> > handler = CreateServerHandler(); _idToAddrMap = new Dictionary <string, IPEndPoint>(); ICodec <NamingEvent> codec = CreateServerCodec(); // Start transport server, get listening IP endpoint _logger.Log(Level.Info, "Starting naming server"); _server = new TransportServer <NamingEvent>( new IPEndPoint(NetworkUtils.LocalIPAddress, port), handler, codec, tcpPortProvider); _server.Run(); LocalEndpoint = _server.LocalEndpoint; }
public void TestRaceCondition() { ICodec <string> codec = new StringCodec(); int port = NetworkUtils.GenerateRandomPort(6000, 7000); BlockingCollection <string> queue = new BlockingCollection <string>(); List <string> events = new List <string>(); int numEventsExpected = 150; IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <string>(endpoint, remoteHandler, codec)) { server.Run(); for (int i = 0; i < numEventsExpected / 3; i++) { Task.Run(() => { IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port); using (var client = new TransportClient <string>(remoteEndpoint, codec)) { client.Send("Hello"); client.Send(", "); client.Send("World!"); } }); } for (int i = 0; i < numEventsExpected; i++) { events.Add(queue.Take()); } } Assert.AreEqual(numEventsExpected, events.Count); }
public void TestRaceCondition() { ICodec <string> codec = new StringCodec(); var port = 0; BlockingCollection <string> queue = new BlockingCollection <string>(); List <string> events = new List <string>(); int numEventsExpected = 150; IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, port); var remoteHandler = Observer.Create <TransportEvent <string> >(tEvent => queue.Add(tEvent.Data)); using (var server = new TransportServer <string>(endpoint, remoteHandler, codec, _tcpPortProvider)) { server.Run(); for (int i = 0; i < numEventsExpected / 3; i++) { Task.Run(() => { IPEndPoint remoteEndpoint = new IPEndPoint(_localIpAddress, server.LocalEndpoint.Port); using (var client = new TransportClient <string>(remoteEndpoint, codec)) { client.Send("Hello"); client.Send(", "); client.Send("World!"); } }); } for (int i = 0; i < numEventsExpected; i++) { events.Add(queue.Take()); } } Assert.Equal(numEventsExpected, events.Count); }