@Test
public void testReset() throws Exception {
setUp();
Server server = createServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
context.put("reset-connection-interval", String.valueOf("5"));
sink.setChannel(channel);
Configurables.configure(sink, context);
sink.start();
RpcClient firstClient = sink.getUnderlyingClient();
Thread.sleep(6000);
// Make sure they are not the same object, connection should be reset
Assert.assertFalse(firstClient == sink.getUnderlyingClient());
sink.stop();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
context.put("reset-connection-interval", String.valueOf("0"));
sink.setChannel(channel);
Configurables.configure(sink, context);
sink.start();
firstClient = sink.getUnderlyingClient();
Thread.sleep(6000);
// Make sure they are the same object, since connection should not be reset
Assert.assertTrue(firstClient == sink.getUnderlyingClient());
sink.stop();
context.clear();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
sink.setChannel(channel);
Configurables.configure(sink, context);
sink.start();
firstClient = sink.getUnderlyingClient();
Thread.sleep(6000);
// Make sure they are the same object, since connection should not be reset
Assert.assertTrue(firstClient == sink.getUnderlyingClient());
sink.stop();
server.close();
}