### Question:
SshFenceByTcpPort extends Configured implements FenceMethod { @Override public boolean tryFence(HAServiceTarget target, String argsStr) throws BadFencingConfigurationException { Args args = new Args(argsStr); InetSocketAddress serviceAddr = target.getAddress(); String host = serviceAddr.getHostName(); Session session; try { session = createSession(serviceAddr.getHostName(), args); } catch (JSchException e) { LOG.warn("Unable to create SSH session", e); return false; } LOG.info("Connecting to " + host + "..."); try { session.connect(getSshConnectTimeout()); } catch (JSchException e) { LOG.warn("Unable to connect to " + host + " as user " + args.user, e); return false; } LOG.info("Connected to " + host); try { return doFence(session, serviceAddr); } catch (JSchException e) { LOG.warn("Unable to achieve fencing on remote host", e); return false; } finally { session.disconnect(); } }  @Override void checkArgs(String argStr); @Override boolean tryFence(HAServiceTarget target, String argsStr);  }### Answer:
@Test(timeout=20000) public void testFence() throws BadFencingConfigurationException { Assume.assumeTrue(isConfigured()); Configuration conf = new Configuration(); conf.set(SshFenceByTcpPort.CONF_IDENTITIES_KEY, TEST_KEYFILE); SshFenceByTcpPort fence = new SshFenceByTcpPort(); fence.setConf(conf); assertTrue(fence.tryFence( TEST_TARGET, null)); }
@Test(timeout=20000) public void testConnectTimeout() throws BadFencingConfigurationException { Configuration conf = new Configuration(); conf.setInt(SshFenceByTcpPort.CONF_CONNECT_TIMEOUT_KEY, 3000); SshFenceByTcpPort fence = new SshFenceByTcpPort(); fence.setConf(conf); assertFalse(fence.tryFence(UNFENCEABLE_TARGET, "")); }