// The error is "JSchException: channel is not opened".
// With the thread-pool size at 100, you get failures a lot more often.
@Test
public void testExecHostnameConcurrentlyWithSameSessions() throws Exception {
final SshClient client = setupClient();
ListeningExecutorService userExecutor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
List<ListenableFuture<ExecResponse>> futures = Lists.newArrayList();
try {
for (int i = 0; i < 100; i++) {
futures.add(userExecutor.submit(new Callable<ExecResponse>() {
@Override
public ExecResponse call() {
ExecResponse response = client.exec("hostname");
//System.out.println("completed (concurrently) "+count.incrementAndGet());
return response;
}
}));
}
List<ExecResponse> responses = Futures.allAsList(futures).get(3000, TimeUnit.SECONDS);
for (ExecResponse response : responses) {
assertEquals(response.getError(), "");
assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName()
: sshHost);
}
} finally {
userExecutor.shutdownNow();
client.disconnect();
}
}