org.apache.sshd.common.io.IoInputStream Java Examples

The following examples show how to use org.apache.sshd.common.io.IoInputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TtyCommand.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
}
 
Example #2
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
    // ignored
}
 
Example #3
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
    // ignored
}
 
Example #4
Source File: WindowTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Test
public void testWindowConsumptionWithAsyncStreams() throws Exception {
    sshd.setShellFactory(new AsyncEchoShellFactory());
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024);
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024);

    client.start();

    try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
        session.addPasswordIdentity(getCurrentTestName());
        session.auth().verify(5L, TimeUnit.SECONDS);

        try (ChannelShell channel = session.createShellChannel()) {
            channel.setStreaming(ClientChannel.Streaming.Async);
            channel.open().verify(5L, TimeUnit.SECONDS);

            try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) {
                Window clientLocal = channel.getLocalWindow();
                Window clientRemote = channel.getRemoteWindow();
                Window serverLocal = serverChannel.getLocalWindow();
                Window serverRemote = serverChannel.getRemoteWindow();

                final String message = "0123456789\n";
                final byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
                final int nbMessages = 500;
                IoOutputStream output = channel.getAsyncIn();
                IoInputStream input = channel.getAsyncOut();
                for (int i = 0; i < nbMessages; i++) {
                    Buffer buffer = new ByteArrayBuffer(bytes);
                    output.write(buffer).verify(5L, TimeUnit.SECONDS);

                    waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));

                    Buffer buf = new ByteArrayBuffer(16);
                    IoReadFuture future = input.read(buf);
                    future.verify(5L, TimeUnit.SECONDS);
                    assertEquals("Mismatched available data at line #" + i, message.length(), buf.available());
                    assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available()));

                    waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));
                    waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L));
                }
            }
        }
    } finally {
        client.stop();
    }
}
 
Example #5
Source File: TtyCommand.java    From aesh-readline with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
}
 
Example #6
Source File: TtyCommand.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
}
 
Example #7
Source File: WindowAdjustTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
    // ignored
}
 
Example #8
Source File: AsyncEchoShellFactory.java    From termd with Apache License 2.0 4 votes vote down vote up
@Override
public void setIoInputStream(IoInputStream in) {
    // ignored
}
 
Example #9
Source File: WindowTest.java    From termd with Apache License 2.0 4 votes vote down vote up
@Test
public void testWindowConsumptionWithAsyncStreams() throws Exception {
    sshd.setShellFactory(new AsyncEchoShellFactory());
    PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 1024);
    PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024);

    client.start();

    try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) {
        session.addPasswordIdentity(getCurrentTestName());
        session.auth().verify(5L, TimeUnit.SECONDS);

        try (ChannelShell channel = session.createShellChannel()) {
            channel.setStreaming(ClientChannel.Streaming.Async);
            channel.open().verify(5L, TimeUnit.SECONDS);

            try (Channel serverChannel = sshd.getActiveSessions().iterator().next().getService(ServerConnectionService.class).getChannels().iterator().next()) {
                Window clientLocal = channel.getLocalWindow();
                Window clientRemote = channel.getRemoteWindow();
                Window serverLocal = serverChannel.getLocalWindow();
                Window serverRemote = serverChannel.getRemoteWindow();

                final String message = "0123456789\n";
                final byte[] bytes = message.getBytes(StandardCharsets.UTF_8);
                final int nbMessages = 500;
                IoOutputStream output = channel.getAsyncIn();
                IoInputStream input = channel.getAsyncOut();
                for (int i = 0; i < nbMessages; i++) {
                    Buffer buffer = new ByteArrayBuffer(bytes);
                    output.write(buffer).verify(5L, TimeUnit.SECONDS);

                    waitForWindowNotEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));

                    Buffer buf = new ByteArrayBuffer(16);
                    IoReadFuture future = input.read(buf);
                    future.verify(5L, TimeUnit.SECONDS);
                    assertEquals("Mismatched available data at line #" + i, message.length(), buf.available());
                    assertEquals("Mismatched data at line #" + i, message, new String(buf.array(), buf.rpos(), buf.available()));

                    waitForWindowEquals(clientLocal, serverRemote, "client local", "server remote", TimeUnit.SECONDS.toMillis(3L));
                    waitForWindowEquals(clientRemote, serverLocal, "client remote", "server local", TimeUnit.SECONDS.toMillis(3L));
                }
            }
        }
    } finally {
        client.stop();
    }
}