Search in sources :

Example 21 with DetectFuture

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

the class AsyncDetectorFileDescriptorLeakTest method testNoServerPresent.

@Test
@Repeat(10000)
public void testNoServerPresent() throws Exception {
    AsyncAbstractDetector detector = getNewDetector(1999, ".*");
    LOG.info("Starting testNoServerPresent with detector: {}\n", detector);
    final DetectFuture future = detector.isServiceDetected(InetAddressUtils.getLocalHostAddress());
    assertNotNull(future);
    future.awaitFor();
    assertFalse("False positive during detection!!", future.isServiceDetected());
    assertNull(future.getException());
    LOG.info("Finished testNoServerPresent with detector: {}\n", detector);
}
Also used : DetectFuture(org.opennms.netmgt.provision.DetectFuture) AsyncAbstractDetector(org.opennms.netmgt.provision.support.AsyncAbstractDetector) Test(org.junit.Test) Repeat(org.springframework.test.annotation.Repeat)

Example 22 with DetectFuture

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

the class FtpDetectorTest method testFailureClosedPort.

@Test(timeout = 20000)
public void testFailureClosedPort() throws Exception {
    m_server.setBanner("WRONG BANNER");
    m_detector.setPort(65535);
    m_detector.setIdleTime(10000);
    DetectFuture df = m_detector.isServiceDetected(m_server.getInetAddress());
    assertFalse("Test should fail because the server closes before detection takes place", doCheck(df));
}
Also used : DetectFuture(org.opennms.netmgt.provision.DetectFuture) Test(org.junit.Test)

Example 23 with DetectFuture

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

the class AsyncDetectorFileDescriptorLeakTest method testBannerlessServer.

@Test
public void testBannerlessServer() throws Throwable {
    // No banner
    setUpServer(null);
    final int port = m_server.getLocalPort();
    final InetAddress address = m_server.getInetAddress();
    int i = 0;
    while (i < 30000) {
        LOG.info("current loop: {}", i);
        AsyncAbstractDetector detector = getNewDetector(port, null);
        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());
        i++;
    }
}
Also used : DetectFuture(org.opennms.netmgt.provision.DetectFuture) AsyncAbstractDetector(org.opennms.netmgt.provision.support.AsyncAbstractDetector) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 24 with DetectFuture

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

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