I am attempting to abruptly disconnect from an SFTP connection in Java without using the sftp.disconnect() method. Using this to build an integration test that checks that clean up happens everytime. See the test below:
public void checkDisruptedConnections() throws JSchException, InterruptedException {
ChannelSftp sftp = setupSftp(null);
sftp.connect();
try {
//disrupt connection OVER HERE
} catch (Exception e) {
assertEquals("1", jedis.get(SESSION_KEY));
}
waitForConnectionClose();
assertEquals("0", jedis.get(SESSION_KEY));
}
Ended up using a separate thread that connects and gets interupted.
Connect looks as follows: