Search in sources :

Example 6 with DetectFuture

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

the class ImapDetectorTest method testServerSuccess.

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

        @Override
        public void onInit() {
            setBanner("* OK THIS IS A BANNER FOR IMAP");
            addResponseHandler(contains("LOGOUT"), shutdownServer("* BYE\r\nONMSCAPSD OK"));
        }
    };
    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);
        // assertTrue(m_detector.isServiceDetected(m_server.getInetAddress()));
        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) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 7 with DetectFuture

use of org.opennms.netmgt.provision.DetectFuture 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 8 with DetectFuture

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

the class TcpDetectorTest method testServerCloses.

/**
 * I think that this test is redundant with {@link #testFailureClosedPort()} since neither
 * server is actually started. The detector just times out on both connections.
 */
@Test(timeout = 20000)
public void testServerCloses() throws Exception {
    initializeDefaultDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            shutdownServer("Closing");
        }
    };
    m_server.init();
    // m_server.startServer();
    m_detector.setPort(m_server.getLocalPort());
    // assertFalse("Test should fail because the server closes before detection takes place", m_detector.isServiceDetected(m_server.getInetAddress()));
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertFalse(future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 9 with DetectFuture

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

the class DetectFutureNettyImpl method addListener.

@Override
public DetectFuture addListener(final DetectFutureListener<DetectFuture> listener) {
    final DetectFuture thisFuture = this;
    m_future.addListener(new ChannelFutureListener() {

        @Override
        public void operationComplete(ChannelFuture future) {
            listener.operationComplete(thisFuture);
        }
    });
    return this;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) DetectFuture(org.opennms.netmgt.provision.DetectFuture) ChannelFutureListener(org.jboss.netty.channel.ChannelFutureListener)

Example 10 with DetectFuture

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

the class AsyncDetectorFileDescriptorLeakTest method testDetectorBannerTimeout.

/**
 * TODO: This test will fail if there are more than a few milliseconds of delay
 * between the characters of the banner. We need to fix this behavior.
 */
@Test
public void testDetectorBannerTimeout() throws Throwable {
    // Add 50 milliseconds of delay in between sending bytes of the banner
    setUpServer("Banner", 50);
    final int port = m_server.getLocalPort();
    final InetAddress address = m_server.getInetAddress();
    AsyncAbstractDetector detector = getNewDetector(port, "Banner");
    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();
    }
    assertTrue("False negative 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)

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