public void start(String address, int port, int threads, boolean http2) throws Exception { this.address = address; this.port = port; this.http2 = http2; if (http2) nettyHttpClient.start(address, port); else http1Client.start(); executor = Executors.newFixedThreadPool(threads); executorCompletionService = new ExecutorCompletionService(executor); }
@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 shouldUpgradeUsingALPN() throws Exception { SkipTestNG.skipSinceJDK(10); // TODO: OpenSSL ALPN doesn't seem to work. Restructure the test to use internal JDK ALPN if (!OpenSsl.isAlpnSupported()) { throw new IllegalStateException("OpenSSL is not present, can not test TLS/ALPN support. Version: " + OpenSsl.versionString() + " Cause: " + OpenSsl.unavailabilityCause()); } //given restServer = RestServerHelper.defaultRestServer("http2testcache") .withKeyStore(KEY_STORE_PATH, "secret", "pkcs12") .start(TestResourceTracker.getCurrentTestShortName()); client = NettyHttpClient.newHttp2ClientWithALPN(KEY_STORE_PATH, "secret"); 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); }
client.start("localhost", port);