password = gerritAuthKeyFilePassword;
}
if (SshUtil.checkPassPhrase(file, password)) {
if (file.exists() && file.isFile()) {
try {
final SshConnection sshConnection = SshConnectionFactory.getConnection(
gerritHostName,
gerritSshPort,
gerritProxy,
new Authentication(file, gerritUserName, password));
ExecutorService service = Executors.newFixedThreadPool(THREADS_FOR_TEST_CONNECTION);
Future<Integer> future = service.submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return sshConnection.executeCommandReader(GerritConnection.CMD_STREAM_EVENTS).read();
}
});
int readChar;
try {
readChar = future.get(TIMEOUT_FOR_TEST_CONNECTION, TimeUnit.SECONDS);
} catch (TimeoutException ex) {
readChar = 0;
} finally {
sshConnection.disconnect();
}
if (readChar < 0) {
return FormValidation.error(Messages.StreamEventsCapabilityException(gerritUserName));
} else {
return FormValidation.ok(Messages.Success());