use of io.cdap.cdap.internal.app.runtime.monitor.TrafficRelayServer in project cdap by caskdata.
the class TrafficRelayServerTest method testRelay.
@Test
public void testRelay() throws Exception {
NettyHttpService httpServer = NettyHttpService.builder("test").setHttpHandlers(new TestHandler()).build();
httpServer.start();
try {
TrafficRelayServer relayServer = new TrafficRelayServer(InetAddress.getLoopbackAddress(), httpServer::getBindAddress);
relayServer.startAndWait();
try {
InetSocketAddress relayAddr = relayServer.getBindAddress();
// GET
URL url = new URL(String.format("http://%s:%d/ping", relayAddr.getHostName(), relayAddr.getPort()));
HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
// POST
url = new URL(String.format("http://%s:%d/echo", relayAddr.getHostName(), relayAddr.getPort()));
response = HttpRequests.execute(HttpRequest.post(url).withBody("Testing").build(), new DefaultHttpRequestConfig(false));
Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
Assert.assertEquals("Testing", response.getResponseBodyAsString());
} finally {
relayServer.stopAndWait();
}
} finally {
httpServer.stop();
}
}
Aggregations