TorqueJPPFNodeDeployer implements TorqueNodeDeployment, PublicIpNotifier { @VisibleForTesting void doPublicIpRequest() throws SSHClientException { if (!sshClient.isConnected()) { connectToSSH(); } String publicIpString = sshClient.executeWithResult("echo $SSH_CLIENT"); String publicIpPart = publicIpString.split(" ")[0]; if (InetAddresses.isInetAddress(publicIpPart)) { this.publicIp = publicIpPart; logger.info("Public IP request successful. ({})", publicIp); } else { this.publicIp = PublicIp.getInstance().getPublicIp(); logger.warn("Error parsing public IP from \"{}\", used fallback {} instead ({})", new String[]{publicIpString, PublicIp.class.getName(), publicIp}); } notifyPublicIp(publicIp); } TorqueJPPFNodeDeployer(TorqueConfiguration configuration, SSHClient sshClient); synchronized void prepareAndDeployInfrastructure(Collection<File> artifactsToPreload); void deployNewNode(TorqueNodeConfiguration nodeConfiguration); @Override String getDriverAddress(); @Override String getSessionId(); @Override SSHClient sshClient(); void disconnectSshConnection(); @Override void notifyPublicIp(String publicIp); @Override void addListener(Observer listener); @Override void remoteListener(Observer listener);  }
@Test public void doPublicIpRequest() throws Exception { when(sshClient.executeWithResult(eq("echo $SSH_CLIENT"))).thenReturn("1.2.3.5 123 456"); torqueJPPFNodeDeployer.addListener(new Observer() { @Override public void update(Observable o, Object arg) { notifiedIp = (String)arg; } }); verify(sshClient).executeWithResult(eq("echo $SSH_CLIENT")); assertThat(notifiedIp, is("1.2.3.5")); }