@Test(timeout = 10000)
public void testConnectWithMultipleFailures() throws Exception {
UUID cid = UUID.randomUUID();
PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT);
MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl();
ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
implementAsDirectExecutor(executor);
cf.setExecutor(executor);
MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf);
ClientConnection connection = mock(ClientConnection.class);
cf.provideConnection(uri, connection);
@Cleanup
SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, "");
output.reconnect();
verify(connection).send(new SetupAppend(1, cid, SEGMENT, ""));
cf.getProcessor(uri).processingFailure(new IOException());
verify(connection).send(new SetupAppend(2, cid, SEGMENT, ""));
cf.getProcessor(uri).connectionDropped();
verify(connection).send(new SetupAppend(3, cid, SEGMENT, ""));
cf.getProcessor(uri).wrongHost(new WireCommands.WrongHost(3, SEGMENT, "newHost", "SomeException"));
verify(connection).send(new SetupAppend(4, cid, SEGMENT, ""));
}