@Test
public void testTimeout() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("foo", Charsets.UTF_8);
AtomicLong delay = new AtomicLong();
Server server = createServer(new DelayMockAvroServer(delay));
server.start();
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction txn = channel.getTransaction();
txn.begin();
for (int i = 0; i < 4; i++) {
channel.put(event);
}
txn.commit();
txn.close();
// should throw EventDeliveryException due to connect timeout
delay.set(3000L); // because connect-timeout = 2000
boolean threw = false;
try {
sink.process();
} catch (EventDeliveryException ex) {
logger.info("Correctly threw due to connect timeout. Exception follows.",
ex);
threw = true;
}
Assert.assertTrue("Must throw due to connect timeout", threw);
// now, allow the connect handshake to occur
delay.set(0);
sink.process();
// should throw another EventDeliveryException due to request timeout
delay.set(4000L); // because request-timeout = 3000
threw = false;
try {
sink.process();
} catch (EventDeliveryException ex) {
logger.info("Correctly threw due to request timeout. Exception follows.",