use of org.opennms.netmgt.provision.detector.simple.TcpDetector in project opennms by OpenNMS.
the class AsyncDetectorFileDescriptorLeakTest method getNewDetector.
private static AsyncAbstractDetector getNewDetector(int port, String bannerRegex) {
TcpDetector detector = new TcpDetector();
detector.setServiceName("TCP");
detector.setPort(port);
// Three seconds
detector.setTimeout(3000);
// Three seconds
detector.setIdleTime(3000);
detector.setBanner(bannerRegex);
detector.setRetries(3);
detector.init();
return detector;
}
use of org.opennms.netmgt.provision.detector.simple.TcpDetector in project opennms by OpenNMS.
the class TcpDetectorTest method testNoServerPresent.
@Test(timeout = 20000)
public void testNoServerPresent() throws Exception {
initializeDefaultDetector();
m_detector.setPort(1999);
// assertFalse("Test should fail because the server closes before detection takes place", m_detector.isServiceDetected(m_server.getInetAddress()));
DetectFuture future = m_detector.isServiceDetected(InetAddress.getLocalHost());
future.addListener(new DetectFutureListener<DetectFuture>() {
@Override
public void operationComplete(DetectFuture future) {
TcpDetector detector = m_detector;
m_detector = null;
detector.dispose();
}
});
assertNotNull(future);
future.awaitForUninterruptibly();
assertFalse(future.isServiceDetected());
}
use of org.opennms.netmgt.provision.detector.simple.TcpDetector in project opennms by OpenNMS.
the class TcpDetectorTest method testSuccessServer.
@Test(timeout = 20000)
public void testSuccessServer() throws Exception {
initializeDefaultDetector();
m_server = new SimpleServer() {
@Override
public void onInit() {
setBanner("Hello");
}
};
m_server.init();
m_server.startServer();
m_detector.setPort(m_server.getLocalPort());
DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
future.addListener(new DetectFutureListener<DetectFuture>() {
@Override
public void operationComplete(DetectFuture future) {
TcpDetector detector = m_detector;
m_detector = null;
detector.dispose();
}
});
assertNotNull(future);
future.awaitForUninterruptibly();
assertTrue(future.isServiceDetected());
}
Aggregations