System.setProperty(KeepAliveManager.KEEP_ALIVE_INTERVAL_TIME_PROPERTY,
"1000");
log.info("Starting server");
JsonRpcServerThrift server = new JsonRpcServerThrift(
new EchoJsonRpcHandler(), "127.0.0.1", 19292);
server.start();
log.info("Server started");
long initTime = System.nanoTime();
log.info("Starting client");
JsonRpcClient client = new JsonRpcClientThrift("127.0.0.1", 19292,
"127.0.0.1", 7979);
if (!latch.await(15, TimeUnit.SECONDS)) {
Assert.fail("Timeout of 15s waiting for keepAlives");
} else {
long duration = ((System.nanoTime() - initTime) / 1000000);
Assert.assertTrue(
"Waiting time should be greather than estimated keepAlive time ("
+ duration + " > " + (NUM_KEEP_ALIVES * 1000) + ")",
duration > NUM_KEEP_ALIVES * 1000);
Assert.assertTrue("Waiting time should be a bit more than "
+ NUM_KEEP_ALIVES + " keepAlive times (" + duration + " < "
+ ((NUM_KEEP_ALIVES + 3) * 1000) + ")",
duration < (NUM_KEEP_ALIVES + 3) * 1000);
}
client.close();
log.info("Client finished");
server.destroy();
log.info("Server finished");
}