public class RxMetricEventsTest {
@Test
public void testMetricEventsSanityCheck() throws Exception {
final CountDownLatch bothClientAndServerDone = new CountDownLatch(2);
final ChannelCloseListener serverCloseListener = new ChannelCloseListener();
HttpServer<ByteBuf, ByteBuf> server =
RxNetty.newHttpServerBuilder(7999, new RequestHandler<ByteBuf, ByteBuf>() {
@Override
public Observable<Void> handle(HttpServerRequest<ByteBuf> request,
HttpServerResponse<ByteBuf> response) {
request.getContent().subscribe();
response.writeString("Hellooo!!!");
return response.close().finallyDo(new Action0() {
@Override
public void call() {
bothClientAndServerDone.countDown();
}
});
}
}).appendPipelineConfigurator(new PipelineConfigurator<HttpServerRequest<ByteBuf>, HttpServerResponse<ByteBuf>>() {
@Override
public void configureNewPipeline(ChannelPipeline pipeline) {
pipeline.addLast(serverCloseListener);
}
}).enableWireLogging(LogLevel.ERROR).build().start();
TestableServerMetricsEventListener listener = new TestableServerMetricsEventListener();
server.subscribe(listener);
TestableClientMetricsEventListener clientListener = new TestableClientMetricsEventListener();
final ChannelCloseListener clientCloseListener = new ChannelCloseListener();
HttpClient<ByteBuf, ByteBuf> client =
RxNetty.<ByteBuf, ByteBuf>newHttpClientBuilder("localhost", server.getServerPort())
.enableWireLogging(LogLevel.DEBUG)
.appendPipelineConfigurator(new PipelineConfigurator<HttpClientResponse<ByteBuf>, HttpClientRequest<ByteBuf>>() {
@Override
public void configureNewPipeline(ChannelPipeline pipeline) {
pipeline.addLast(clientCloseListener);
}
})
.withNoConnectionPooling().build();
client.subscribe(clientListener);
client.submit(HttpClientRequest.createGet("/"))
.finallyDo(new Action0() {
@Override
public void call() {
bothClientAndServerDone.countDown();
}
}).toBlocking().last();
bothClientAndServerDone.await(1, TimeUnit.MINUTES);
clientCloseListener.waitForClose(1, TimeUnit.MINUTES);
serverCloseListener.waitForClose(1, TimeUnit.MINUTES);
Assert.assertTrue("Invalid TCP Server metric callbacks: " + listener.getEventTypeVsInvalidInvocations(),
listener.getEventTypeVsInvalidInvocations().isEmpty());
Assert.assertTrue("Invalid HTTP Server metric callbacks: " + listener.getHttpEventTypeVsInvalidInvocations(),