void performRecovery(RetryableResource initialResource, RetryableResource recoveryResource,
int expectedConnectionRecoveryAttempts, int expectedChannelRecoveryAttempts) throws Throwable {
createResources();
int expectedResumes = expectedConnectionRecoveryAttempts + expectedChannelRecoveryAttempts;
final Waiter waiter = new Waiter();
waiter.expectResumes(expectedResumes);
config.withConnectionListeners(new DefaultConnectionListener() {
@Override
public void onChannelRecovery(Connection connection) {
waiter.resume();
}
@Override
public void onRecoveryFailure(Connection connection, Throwable failure) {
waiter.resume();
}
});
config.withChannelListeners(new DefaultChannelListener() {
@Override
public void onRecovery(Channel channel) {
waiter.resume();
}
@Override
public void onRecoveryFailure(Channel channel, Throwable failure) {
waiter.resume();
}
});
// Mock recovery handling
mockRecovery(recoveryResource instanceof ConnectionHandler ? connectionShutdownSignal()
: channelShutdownSignal(), recoveryResource);
// Call initial shutdown listener
callShutdownListener(initialResource,
initialResource instanceof ConnectionHandler ? connectionShutdownSignal()
: channelShutdownSignal());
if (expectedResumes > 0)
waiter.await(1000);
Thread.sleep(100);
}