public void performGets(int pertentageOfMisses, int numberOfGets, String existingKey, String nonExistingKey) throws Exception { Random r = ThreadLocalRandom.current(); for (int i = 0; i < numberOfGets; ++i) { String key = r.nextInt(100) < pertentageOfMisses ? nonExistingKey : existingKey; executorCompletionService.submit(() -> { if (http2) { FullHttpRequest getRequest = new DefaultFullHttpRequest(HTTP_1_1, GET, "/rest/default/" + key); nettyHttpClient.sendRequest(getRequest); } else { try { String scheme = usesTLS ? "https" : "http"; http1Client .GET(String.format("%s://localhost:%d/rest/%s/%s", scheme, port, "default", key)); } catch (Exception e) { throw new RuntimeException(e); } } return 1; }); } for (int i = 0; i < numberOfGets; ++i) { executorCompletionService.take().get(); } if (http2) { nettyHttpClient.getResponses(); } }
@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()); }
public void performPuts(int numberOfInserts) throws Exception { for (int i = 0; i < numberOfInserts; ++i) { String randomKey = UUID.randomUUID().toString(); executorCompletionService.submit(() -> { if (http2) { FullHttpRequest putValueInCacheRequest = new DefaultFullHttpRequest(HTTP_1_1, POST, "/rest/default/" + randomKey, wrappedBuffer("test".getBytes(CharsetUtil.UTF_8))); nettyHttpClient.sendRequest(putValueInCacheRequest); return 1; } else { try { String scheme = usesTLS ? "https" : "http"; http1Client .POST(String.format("%s://localhost:%d/rest/%s/%s", scheme, port, "default", "randomKey")) .content(new StringContentProvider("test")) .send(); return 1; } catch (Exception e) { throw new RuntimeException(e); } } }); } for (int i = 0; i < numberOfInserts; ++i) { executorCompletionService.take().get(); } if (http2) { nettyHttpClient.getResponses(); } }
@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); }
Queue<FullHttpResponse> responses = client.getResponses();