summary |
shortlog |
log |
commit | commitdiff |
review |
tree
raw |
patch |
inline | side by side (from parent 1:
350a98c)
Rather than using an anonymous listener, document the lifecycle event,
allowing us to refactor locking and extraction in the future. Also use
getException() to check for success.
JIRA: NETCONF-905
Change-Id: I8569ca007aefad634aff54294b475e565ac4f669
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
}
LOG.debug("Starting SSH to {} on channel: {}", remoteAddress, ctx.channel());
}
LOG.debug("Starting SSH to {} on channel: {}", remoteAddress, ctx.channel());
- final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), remoteAddress)
+ sshClient.connect(authenticationHandler.getUsername(), remoteAddress)
// FIXME: this is a blocking call, we should handle this with a concurrently-scheduled timeout. We do not
// have a Timer ready, so perhaps we should be using the event loop?
// FIXME: this is a blocking call, we should handle this with a concurrently-scheduled timeout. We do not
// have a Timer ready, so perhaps we should be using the event loop?
- .verify(ctx.channel().config().getConnectTimeoutMillis(), TimeUnit.MILLISECONDS);
- sshConnectionFuture.addListener(future -> {
- if (future.isConnected()) {
- handleSshSessionCreated(future, ctx);
- } else {
- handleSshSetupFailure(ctx, future.getException());
- }
- });
+ .verify(ctx.channel().config().getConnectTimeoutMillis(), TimeUnit.MILLISECONDS)
+ .addListener(future -> onConnectComplete(future, ctx));
+ }
+
+ private void onConnectComplete(final ConnectFuture future, final ChannelHandlerContext ctx) {
+ final var cause = future.getException();
+ if (cause != null) {
+ handleSshSetupFailure(ctx, cause);
+ return;
+ }
+
+ handleSshSessionCreated(future, ctx);
private static ConnectFuture getSuccessConnectFuture(final ClientSession sshSession) {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
private static ConnectFuture getSuccessConnectFuture(final ClientSession sshSession) {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
- doReturn(true).when(connectFuture).isConnected();
+ doReturn(null).when(connectFuture).getException();
doReturn(sshSession).when(connectFuture).getSession();
return connectFuture;
doReturn(sshSession).when(connectFuture).getSession();
return connectFuture;
private static ConnectFuture getFailedConnectFuture() {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
private static ConnectFuture getFailedConnectFuture() {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
- doReturn(false).when(connectFuture).isConnected();
doReturn(new IllegalStateException()).when(connectFuture).getException();
return connectFuture;
}
doReturn(new IllegalStateException()).when(connectFuture).getException();
return connectFuture;
}