Search in sources :

Example 1 with AsyncAbstractDetector

use of org.opennms.netmgt.provision.support.AsyncAbstractDetector 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 2 with AsyncAbstractDetector

use of org.opennms.netmgt.provision.support.AsyncAbstractDetector 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)

Example 3 with AsyncAbstractDetector

use of org.opennms.netmgt.provision.support.AsyncAbstractDetector 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)

Example 4 with AsyncAbstractDetector

use of org.opennms.netmgt.provision.support.AsyncAbstractDetector 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 5 with AsyncAbstractDetector

use of org.opennms.netmgt.provision.support.AsyncAbstractDetector 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)

Aggregations

Test (org.junit.Test)5 DetectFuture (org.opennms.netmgt.provision.DetectFuture)5 AsyncAbstractDetector (org.opennms.netmgt.provision.support.AsyncAbstractDetector)5 InetAddress (java.net.InetAddress)4 Repeat (org.springframework.test.annotation.Repeat)1