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();
}
}
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());
}
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());
}
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;
}
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());
}
Aggregations