@Test
public void testConnectStreamLoggerToCommand() throws IOException, InterruptedException {
SSHClient client = Ssh.newClient(localhost, adminAccess, 1000);
try {
Session session = client.startSession();
try {
final Session.Command command = session.exec("echo 'line1' && echo && echo 'line2'");
final List<String> lines = Lists.newCopyOnWriteArrayList();
StreamLogger logger = new StreamLogger(command.getInputStream(), LOG, MarkerFactory.getMarker("live")) {
@Override
protected void log(Logger logger, Marker marker, String line) {
logger.info(marker, line); /* just for visual inspection */
lines.add(line);
}
};
logger.start();
command.join();
logger.join();
assertThat(lines).hasSize(2).contains("line1", "line2");
} finally {
session.close();
}
} finally {
client.close();
}
}