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