use of org.opennms.netmgt.provision.server.exchange.RequestHandler in project opennms by OpenNMS.
the class MemcachedDetectorTest method testServerSuccess.
@Test(timeout = 20000)
public void testServerSuccess() 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", "VERSION 1.2.3").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();
assertTrue(future.isServiceDetected());
} finally {
m_server.stopServer();
}
}
use of org.opennms.netmgt.provision.server.exchange.RequestHandler 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.server.exchange.RequestHandler in project opennms by OpenNMS.
the class NsclientDetectorTest method setUp.
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
m_detector = m_detectorFactory.createDetector();
// Initialize Mock NSClient Server
m_server = new SimpleServer() {
@Override
public void onInit() {
addResponseHandler(startsWith("None&1"), new RequestHandler() {
@Override
public void doRequest(OutputStream out) throws IOException {
out.write(String.format("%s\r\n", "NSClient++ 0.3.8.75 2010-05-27").getBytes());
}
});
}
};
m_server.init();
m_server.startServer();
// make sure the server is really started
Thread.sleep(100);
// Initialize Detector
m_detector.setServiceName("NSclient++");
m_detector.setPort(m_server.getLocalPort());
m_detector.setTimeout(2000);
m_detector.setRetries(3);
}
use of org.opennms.netmgt.provision.server.exchange.RequestHandler in project opennms by OpenNMS.
the class AbstractNsclientTest method startServer.
public void startServer(final String command, final String response) throws Exception {
m_server = new SimpleServer() {
@Override
public void onInit() {
addResponseHandler(startsWith(command), new RequestHandler() {
@Override
public void doRequest(OutputStream out) throws IOException {
out.write(response.getBytes());
}
});
}
};
m_server.init();
m_server.startServer();
// make sure the server is really started
Thread.sleep(100);
}
Aggregations