@Test
public void testSslSinkWithNonTrustedCert() throws InterruptedException,
EventDeliveryException, InstantiationException, IllegalAccessException {
setUp();
Event event = EventBuilder.withBody("test event 1", Charsets.UTF_8);
Server server = createSslServer(new MockAvroServer());
server.start();
Context context = new Context();
context.put("hostname", hostname);
context.put("port", String.valueOf(port));
context.put("ssl", String.valueOf(true));
context.put("batch-size", String.valueOf(2));
context.put("connect-timeout", String.valueOf(2000L));
context.put("request-timeout", String.valueOf(3000L));
Configurables.configure(sink, context);
sink.start();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.START_OR_ERROR, 5000));
Transaction transaction = channel.getTransaction();
transaction.begin();
for (int i = 0; i < 10; i++) {
channel.put(event);
}
transaction.commit();
transaction.close();
boolean failed = false;
try {
for (int i = 0; i < 5; i++) {
sink.process();
failed = true;
}
} catch (EventDeliveryException ex) {
logger.info("Correctly failed to send event", ex);
}
sink.stop();
Assert.assertTrue(LifecycleController.waitForOneOf(sink,
LifecycleState.STOP_OR_ERROR, 5000));
server.close();
if (failed) {
Assert.fail("SSL-enabled sink successfully connected to a server with an untrusted certificate when it should have failed");
}
}