Search in sources :

Example 1 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture in project opennms by OpenNMS.

the class MemcachedDetectorTest method testServerSuccess.

@Test(timeout = 20000)
public void testServerSuccess() throws Exception {
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            addResponseHandler(contains("version"), new RequestHandler() {

                @Override
                public void doRequest(OutputStream out) throws IOException {
                    out.write(String.format("%s\r\n", "VERSION 1.2.3").getBytes());
                }
            });
        }
    };
    m_server.init();
    m_server.startServer();
    // make sure the server is really started
    Thread.sleep(100);
    try {
        m_detector.setPort(m_server.getLocalPort());
        m_detector.setIdleTime(1000);
        DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
        assertNotNull(future);
        future.awaitForUninterruptibly();
        assertTrue(future.isServiceDetected());
    } finally {
        m_server.stopServer();
    }
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) RequestHandler(org.opennms.netmgt.provision.server.exchange.RequestHandler) DetectFuture(org.opennms.netmgt.provision.DetectFuture) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Example 2 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture in project opennms by OpenNMS.

the class TcpDetectorTest method testFailureConnectionTimesOutWhenExpectingABanner.

@Test(timeout = 20000)
public void testFailureConnectionTimesOutWhenExpectingABanner() throws Exception {
    initializeDefaultDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            setTimeout(500);
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertFalse("Test should fail because no banner was sent when expecting a banner to be sent", future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 3 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture in project opennms by OpenNMS.

the class TcpDetectorTest method testFailureNoBannerSentWhenExpectingABanner.

@Test(timeout = 20000)
public void testFailureNoBannerSentWhenExpectingABanner() throws Exception {
    initializeDefaultDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertFalse("Test should fail because no banner was sent when expecting a banner to be sent", future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 4 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture in project opennms by OpenNMS.

the class AsyncDetectorFileDescriptorLeakTest method testDetectorTimeoutWaitingForBanner.

@Test
public void testDetectorTimeoutWaitingForBanner() throws Throwable {
    // Start a socket that doesn't have a thread servicing it
    setUpSocket();
    final int port = m_socket.getLocalPort();
    final InetAddress address = m_socket.getInetAddress();
    AsyncAbstractDetector detector = getNewDetector(port, "Hello");
    assertNotNull(detector);
    final DetectFuture future = (DetectFuture) detector.isServiceDetected(address);
    assertNotNull(future);
    future.awaitFor();
    if (future.getException() != null) {
        LOG.debug("got future exception", future.getException());
        throw future.getException();
    }
    assertFalse("False positive during detection!!", future.isServiceDetected());
    assertNull(future.getException());
}
Also used : DetectFuture(org.opennms.netmgt.provision.DetectFuture) AsyncAbstractDetector(org.opennms.netmgt.provision.support.AsyncAbstractDetector) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 5 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture in project opennms by OpenNMS.

the class FtpDetectorTest method testFailureNoBannerSent.

@Test(timeout = 20000)
public void testFailureNoBannerSent() throws Exception {
    m_server = new SimpleServer();
    m_server.init();
    m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    m_detector.setIdleTime(10000);
    DetectFuture df = m_detector.isServiceDetected(m_server.getInetAddress());
    assertFalse("Test should fail because the banner doesn't even get sent", doCheck(df));
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Aggregations

DetectFuture (org.opennms.netmgt.provision.DetectFuture)24 Test (org.junit.Test)21 SimpleServer (org.opennms.netmgt.provision.server.SimpleServer)12 AsyncAbstractDetector (org.opennms.netmgt.provision.support.AsyncAbstractDetector)5 InetAddress (java.net.InetAddress)4 OutputStream (java.io.OutputStream)2 ChannelFuture (org.jboss.netty.channel.ChannelFuture)2 TcpDetector (org.opennms.netmgt.provision.detector.simple.TcpDetector)2 RequestHandler (org.opennms.netmgt.provision.server.exchange.RequestHandler)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 KeyManagementException (java.security.KeyManagementException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)1 ChannelFutureListener (org.jboss.netty.channel.ChannelFutureListener)1 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)1 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)1 SslHandler (org.jboss.netty.handler.ssl.SslHandler)1 Ignore (org.junit.Ignore)1