@Test public void testClientSendsMessage() throws Exception { final AtomicReference<MessageEvent> message = new AtomicReference<MessageEvent>(); MessageListener listener = new MessageListener() { public void handle(MessageEvent event) { message.set(event); } }; Settings settings = newSettings(); Integer port = settings.get(PORT_KEY, Defaults.get(PORT_KEY)); ExecutorService threadPool = Executors.newCachedThreadPool(); SocketTCPConnectorServer connector = new SocketTCPConnectorServer(threadPool, settings); connector.addMessageListener(listener); connector.start(); try { Socket client = new Socket((String)null, port); OutputStream output = client.getOutputStream(); SrvRply reply = new SrvRply(); URLEntry entry = new URLEntry(); entry.setURL("url1"); reply.addURLEntry(entry); reply.setResponder("127.0.0.1"); byte[] messageBytes = reply.serialize(); output.write(messageBytes, 0, messageBytes.length); output.flush(); client.close(); Thread.sleep(500); assert connector.isRunning(); MessageEvent event = message.get(); assert event != null; Message receivedMessage = event.getMessage(); assert receivedMessage != null; SrvRply receivedRply = (SrvRply)receivedMessage; assert receivedRply.getURLEntries().equals(reply.getURLEntries()); client = new Socket((String)null, port); client.close(); } finally { connector.stop(); } }
@Override public boolean isRunning() { return super.isRunning() && stopBarrier.getCount() > 0; }
SocketTCPConnectorServer extends AbstractConnectorServer implements TCPConnectorServer { @Override public boolean isRunning() { return super.isRunning() && stopBarrier.getCount() > 0; } }
SocketTCPConnectorServer extends AbstractConnectorServer implements TCPConnectorServer { @Override public boolean isRunning() { return super.isRunning() && stopBarrier.getCount() > 0; } SocketTCPConnectorServer(ExecutorService threadPool);  SocketTCPConnectorServer(ExecutorService threadPool, Settings settings); }
SocketTCPConnectorServer extends AbstractConnectorServer implements TCPConnectorServer { @Override public boolean isRunning() { return super.isRunning() && stopBarrier.getCount() > 0; } SocketTCPConnectorServer(ExecutorService threadPool);  SocketTCPConnectorServer(ExecutorService threadPool, Settings settings); String[] getAddresses(); void setAddresses(String[] addresses); int getPort(); void setPort(int port); @Override boolean isRunning(); }
SocketTCPConnectorServer extends AbstractConnectorServer implements TCPConnectorServer { @Override public boolean isRunning() { return super.isRunning() && stopBarrier.getCount() > 0; } SocketTCPConnectorServer(ExecutorService threadPool);  SocketTCPConnectorServer(ExecutorService threadPool, Settings settings); String[] getAddresses(); void setAddresses(String[] addresses); int getPort(); void setPort(int port); @Override boolean isRunning();  }