import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.channel.DefaultChannelPromise;
+import io.netty.util.concurrent.EventExecutor;
import java.io.IOException;
import java.net.SocketAddress;
import java.util.concurrent.TimeUnit;
private SocketAddress localAddress;
@Mock
private ChannelConfig channelConfig;
+ @Mock
+ private EventExecutor executor;
private AsyncSshHandler asyncSshHandler;
doReturn(ctx).when(ctx).fireChannelInactive();
doReturn(mock(ChannelFuture.class)).when(ctx).disconnect(any(ChannelPromise.class));
doReturn(getMockedPromise()).when(ctx).newPromise();
+ doReturn(executor).when(ctx).executor();
+ doAnswer(invocation -> {
+ invocation.getArgument(0, Runnable.class).run();
+ return null;
+ }).when(executor).execute(any());
}
private void stubChannel() {
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final IoWriteFuture ioWriteFuture = asyncIn.writePacket(new ByteArrayBuffer());
+ final IoWriteFuture ioWriteFuture = asyncIn.writeBuffer(new ByteArrayBuffer());
Futures.addCallback(stubAddListener(ioWriteFuture), new SuccessFutureListener<IoWriteFuture>() {
@Override
public void onSuccess(final SshFutureListener<IoWriteFuture> result) {
- doReturn(false).when(ioWriteFuture).isWritten();
doReturn(new IllegalStateException()).when(ioWriteFuture).getException();
result.operationComplete(ioWriteFuture);
}
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final IoWriteFuture ioWriteFuture = asyncIn.writePacket(new ByteArrayBuffer());
+ final IoWriteFuture ioWriteFuture = asyncIn.writeBuffer(new ByteArrayBuffer());
final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ChannelPromise secondWritePromise = getMockedPromise();
asyncSshHandler.write(ctx, Unpooled.copiedBuffer(new byte[]{0, 1, 2, 3, 4, 5}), secondWritePromise);
- doReturn(ioWriteFuture).when(asyncIn).writePacket(any(Buffer.class));
+ doReturn(ioWriteFuture).when(asyncIn).writeBuffer(any(Buffer.class));
verifyNoMoreInteractions(firstWritePromise, secondWritePromise);
final IoInputStream asyncOut = getMockedIoInputStream();
final IoOutputStream asyncIn = getMockedIoOutputStream();
- final IoWriteFuture ioWriteFuture = asyncIn.writePacket(new ByteArrayBuffer());
+ final IoWriteFuture ioWriteFuture = asyncIn.writeBuffer(new ByteArrayBuffer());
final NettyAwareChannelSubsystem subsystemChannel = getMockedSubsystemChannel(asyncOut, asyncIn);
final ClientSession sshSession = getMockedSshSession(subsystemChannel);
final ChannelPromise secondWritePromise = getMockedPromise();
// now make write throw pending exception
- doThrow(WritePendingException.class).when(asyncIn).writePacket(any(Buffer.class));
+ doThrow(WritePendingException.class).when(asyncIn).writeBuffer(any(Buffer.class));
for (int i = 0; i < 1001; i++) {
asyncSshHandler.write(ctx, Unpooled.copiedBuffer(new byte[]{0, 1, 2, 3, 4, 5}), secondWritePromise);
}
}
private static OpenFuture getSuccessOpenFuture() {
- final OpenFuture failedOpenFuture = mock(OpenFuture.class);
- doReturn(true).when(failedOpenFuture).isOpened();
- return failedOpenFuture;
+ final OpenFuture openFuture = mock(OpenFuture.class);
+ doReturn(null).when(openFuture).getException();
+ return openFuture;
}
private static AuthFuture getSuccessAuthFuture() {
final AuthFuture authFuture = mock(AuthFuture.class);
- doReturn(true).when(authFuture).isSuccess();
+ doReturn(null).when(authFuture).getException();
return authFuture;
}
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;
private static IoOutputStream getMockedIoOutputStream() throws IOException {
final IoOutputStream mock = mock(IoOutputStream.class);
final IoWriteFuture ioWriteFuture = mock(IoWriteFuture.class);
- doReturn(true).when(ioWriteFuture).isWritten();
+ doReturn(null).when(ioWriteFuture).getException();
Futures.addCallback(stubAddListener(ioWriteFuture), new SuccessFutureListener<IoWriteFuture>() {
@Override
}
}, MoreExecutors.directExecutor());
- doReturn(ioWriteFuture).when(mock).writePacket(any(Buffer.class));
+ doReturn(ioWriteFuture).when(mock).writeBuffer(any(Buffer.class));
doReturn(false).when(mock).isClosed();
doReturn(false).when(mock).isClosing();
return mock;
private static AuthFuture getFailedAuthFuture() {
final AuthFuture authFuture = mock(AuthFuture.class);
- doReturn(false).when(authFuture).isSuccess();
doReturn(new IllegalStateException()).when(authFuture).getException();
return authFuture;
}
private static OpenFuture getFailedOpenFuture() {
- final OpenFuture authFuture = mock(OpenFuture.class);
- doReturn(false).when(authFuture).isOpened();
- doReturn(new IllegalStateException()).when(authFuture).getException();
- return authFuture;
+ final OpenFuture openFuture = mock(OpenFuture.class);
+ doReturn(new IllegalStateException()).when(openFuture).getException();
+ return openFuture;
}
@Test
private static ConnectFuture getFailedConnectFuture() {
final ConnectFuture connectFuture = mock(ConnectFuture.class);
- doReturn(false).when(connectFuture).isConnected();
doReturn(new IllegalStateException()).when(connectFuture).getException();
return connectFuture;
}