public BenchmarkHttpClient() { nettyHttpClient = NettyHttpClient.newHttp2ClientWithHttp11Upgrade(); http1Client = new HttpClient(); }
@Test public void testRestPlainTextUpgrade() throws Exception { //when NettyHttpClient client = NettyHttpClient.newHttp2ClientWithHttp11Upgrade(); client.start("localhost", 8080); FullHttpRequest putValueInCacheRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, "/rest/default/test", wrappedBuffer("test".getBytes(CharsetUtil.UTF_8))); client.sendRequest(putValueInCacheRequest); Queue<FullHttpResponse> responses = client.getResponses(); //then assertEquals(1, responses.size()); assertEquals(HttpResponseStatus.OK, responses.poll().status()); }
@Test public void shouldUpgradeUsingHTTP11Upgrade() throws Exception { //given restServer = RestServerHelper.defaultRestServer("http2testcache").start(TestResourceTracker.getCurrentTestShortName()); client = NettyHttpClient.newHttp2ClientWithHttp11Upgrade(); client.start(restServer.getHost(), restServer.getPort()); FullHttpRequest putValueInCacheRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, "/rest/http2testcache/test", wrappedBuffer("test".getBytes(CharsetUtil.UTF_8))); //when client.sendRequest(putValueInCacheRequest); Queue<FullHttpResponse> responses = client.getResponses(); //then Assertions.assertThat(responses).hasSize(1); Assertions.assertThat(responses.element().status().code()).isEqualTo(200); Assertions.assertThat(restServer.getCacheManager().getCache("http2testcache").size()).isEqualTo(1); } }
@Test public void shouldUpgradeThroughHTTP11UpgradeHeaders() throws Exception { //given RestServer restServer1 = RestTestingUtil.createDefaultRestServer("default"); RestServerRouteDestination restDestination = new RestServerRouteDestination("rest1", restServer1); SinglePortRouteSource singlePortSource = new SinglePortRouteSource(); Route<SinglePortRouteSource, RestServerRouteDestination> routeToRest = new Route<>(singlePortSource, restDestination); RouterConfigurationBuilder routerConfigurationBuilder = new RouterConfigurationBuilder(); routerConfigurationBuilder .singlePort() .port(0) .ip(InetAddress.getLoopbackAddress()) .routing() .add(routeToRest); router = new Router(routerConfigurationBuilder.build()); router.start(); int port = router.getRouter(EndpointRouter.Protocol.SINGLE_PORT).get().getPort(); //when NettyHttpClient client = NettyHttpClient.newHttp2ClientWithHttp11Upgrade(); client.start("localhost", port); FullHttpRequest putValueInCacheRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, "/rest/default/test", wrappedBuffer("test".getBytes(CharsetUtil.UTF_8))); client.sendRequest(putValueInCacheRequest); Queue<FullHttpResponse> responses = client.getResponses(); //then assertThat(responses).hasSize(1); assertThat(responses.poll().status()).isEqualTo(HttpResponseStatus.OK); }