@Test public void SocketAppender_should_retry_appending_until_get_connection() throws IOException, InterruptedException { server.shutdown(); Executors.newScheduledThreadPool(1).schedule(() -> server.start(), 1000, TimeUnit.MILLISECONDS); SocketAppender appender = new SocketAppender(new FixedConnection("localhost", 8080)); appender.append(randomByteArray(200)); AsyncTestHelper.tryDuring(2000, () -> server.verifyReceiveMsg()); }
public void append(byte[] event) { boolean sent = false; while (!sent) { if (!connection.isConnected()) { connection.establishConnection(); } try { connection.write(event); sent = true; } catch (IOException e) { e.printStackTrace(); connection.close(); } } }
SocketAppender { public void append(byte[] event) { boolean sent = false; while (!sent) { if (!connection.isConnected()) { connection.establishConnection(); } try { connection.write(event); sent = true; } catch (IOException e) { e.printStackTrace(); connection.close(); } } } }
SocketAppender { public void append(byte[] event) { boolean sent = false; while (!sent) { if (!connection.isConnected()) { connection.establishConnection(); } try { connection.write(event); sent = true; } catch (IOException e) { e.printStackTrace(); connection.close(); } } } SocketAppender(Connection connection); }
SocketAppender { public void append(byte[] event) { boolean sent = false; while (!sent) { if (!connection.isConnected()) { connection.establishConnection(); } try { connection.write(event); sent = true; } catch (IOException e) { e.printStackTrace(); connection.close(); } } } SocketAppender(Connection connection); void append(byte[] event); boolean isConnected(); }
SocketAppender { public void append(byte[] event) { boolean sent = false; while (!sent) { if (!connection.isConnected()) { connection.establishConnection(); } try { connection.write(event); sent = true; } catch (IOException e) { e.printStackTrace(); connection.close(); } } } SocketAppender(Connection connection); void append(byte[] event); boolean isConnected();  }