Search in sources :

Example 16 with DetectFuture

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

the class TcpDetectorTest method testFailureClosedPort.

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

        @Override
        public void onInit() {
            setBanner("BLIP");
        }
    };
    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 17 with DetectFuture

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

the class AsyncBasicDetectorNettyImpl method isServiceDetected.

/**
 * {@inheritDoc}
 */
@Override
public final DetectFuture isServiceDetected(final InetAddress address) {
    DetectFuture detectFuture = new DetectFutureFailedImpl(this, new IllegalStateException());
    try {
        ClientBootstrap bootstrap = new ClientBootstrap(m_factory);
        bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline retval = Channels.pipeline();
                // Upstream handlers
                // retval.addLast("retryHandler", new RetryChannelHandler());
                appendToPipeline(retval);
                // Downstream handlers
                retval.addLast("detectorHandler", getDetectorHandler(getConversation()));
                if (isUseSSLFilter()) {
                    // Use a relaxed SSL context
                    retval.addLast("sslHandler", new SslHandler(createClientSSLContext().createSSLEngine()));
                }
                return retval;
            }
        });
        bootstrap.setOption("tcpNoDelay", true);
        bootstrap.setOption("keepAlive", true);
        SocketAddress remoteAddress = new InetSocketAddress(address, getPort());
        ChannelFuture future = bootstrap.connect(remoteAddress);
        future.addListener(new RetryChannelFutureListener(remoteAddress, this.getRetries()));
        detectFuture = new DetectFutureNettyImpl(this, future);
    } catch (Throwable e) {
        detectFuture = new DetectFutureFailedImpl(this, e);
    }
    return detectFuture;
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) InetSocketAddress(java.net.InetSocketAddress) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) ServiceDetectionFailedException(org.opennms.netmgt.provision.support.DetectFutureNettyImpl.ServiceDetectionFailedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) SslHandler(org.jboss.netty.handler.ssl.SslHandler) DetectFuture(org.opennms.netmgt.provision.DetectFuture) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 18 with DetectFuture

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

the class TcpDetectorTest method testSuccessNotExpectingBannerNoBannerSent.

@Test(timeout = 20000)
@Ignore
public void testSuccessNotExpectingBannerNoBannerSent() throws Exception {
    intializeNullBannerDetector();
    m_server = new SimpleServer() {

        @Override
        public void onInit() {
            setTimeout(500);
        }
    };
    m_server.init();
    m_server.startServer();
    m_detector.setBanner(null);
    m_detector.setPort(m_server.getLocalPort());
    DetectFuture future = m_detector.isServiceDetected(m_server.getInetAddress());
    assertNotNull(future);
    future.awaitForUninterruptibly();
    assertTrue("Test should pass if we don't set a banner property and nothing responds", future.isServiceDetected());
}
Also used : SimpleServer(org.opennms.netmgt.provision.server.SimpleServer) DetectFuture(org.opennms.netmgt.provision.DetectFuture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 19 with DetectFuture

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

the class MemcachedDetectorTest method testServerFail.

@Test(timeout = 20000)
public void testServerFail() 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", "I don't know what version means...").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();
        assertFalse(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 20 with DetectFuture

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

the class AsyncDetectorFileDescriptorLeakTest method testSuccessServer.

@Test
public void testSuccessServer() throws Throwable {
    setUpServer("Winner");
    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, ".*");
        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)

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