Search in sources :

Example 1 with TcpDetector

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;
}
Also used : TcpDetector(org.opennms.netmgt.provision.detector.simple.TcpDetector)

Example 2 with TcpDetector

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());
}
Also used : TcpDetector(org.opennms.netmgt.provision.detector.simple.TcpDetector) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 3 with TcpDetector

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());
}
Also used : TcpDetector(org.opennms.netmgt.provision.detector.simple.TcpDetector) SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Aggregations

TcpDetector (org.opennms.netmgt.provision.detector.simple.TcpDetector)3 Test (org.junit.Test)2 DetectFuture (org.opennms.netmgt.provision.DetectFuture)2 SimpleServer (org.opennms.netmgt.provision.server.SimpleServer)1