private void sendOperationWithClient(Operation op, RequestContext context) { String registryAddress = getRegistryHostAddress(context); if (serviceClientProxy == null || (registryAddress != null && serviceClientNoProxyList.contains(registryAddress))) { serviceClientNoProxy.send(op); } else { serviceClientProxy.send(op); } }
serviceClient.setRequestPayloadSizeLimit(requestPayloadSizeLimit); serviceClient.setSSLContext(sslContext); serviceClient.start();
public void stop() { if (this.serviceClient != null) { this.serviceClient.stop(); } INSTANCE = null; }
private ServiceClient createServiceClient(SSLContext sslContext, int requestPayloadSizeLimit) { try { // Use the class name and prefix of GIT commit ID as the user agent name and version String commitID = (String) getState().codeProperties .get(GIT_COMMIT_SOURCE_PROPERTY_COMMIT_ID); if (commitID == null) { throw new LocalizableValidationException("CommitID code property not found!", "host.commit.id.not.found"); } commitID = commitID.substring(0, 8); String userAgent = ServiceHost.class.getSimpleName() + "/" + commitID; ServiceClient serviceClient = NettyHttpServiceClient.create(userAgent, null, getScheduledExecutor(), this); if (requestPayloadSizeLimit > 0) { serviceClient.setRequestPayloadSizeLimit(requestPayloadSizeLimit); } serviceClient.setSSLContext(sslContext); return serviceClient; } catch (URISyntaxException e) { throw new RuntimeException("Failed to create ServiceClient", e); } }
client.setSSLContext(clientContext); client.start(); client.send(get); this.host.testWait(); Assert.assertNotNull("Peer principal", result.get()); Assert.assertEquals("Peer principal", "CN=agent-461b1767-ea89-4452-9408-283d0752fe40", result.get()); client.stop();
nonXenonLookingClient = NettyHttpServiceClient.create(UUID.randomUUID().toString(), Executors.newFixedThreadPool(1), Executors.newScheduledThreadPool(1)); nonXenonLookingClient.start(); s = System.nanoTime() / 1000; .forceRemote() .setCompletion(this.host.getExpectedFailureCompletion()); nonXenonLookingClient.send(put); this.host.testWait(); nonXenonLookingClient.stop();
@Test public void testConnectionLimit() throws Throwable { List<Service> services = this.host.doThroughputServiceStart(this.serviceCount, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); String tag = "http1.1ConnectionLimitTag"; int limit = 8; ServiceClient serviceClient = createNettyServiceClient(); serviceClient.setConnectionLimitPerTag(tag, limit); serviceClient.start(); for (int i = 0; i < this.iterationCount; i++) { doConnectionLimit(services, serviceClient, tag, limit); } serviceClient.stop(); }
private static ServiceClient createNettyServiceClient() throws Throwable { ServiceClient client = NettyHttpServiceClient.create( NettyHttpServiceClientTest.class.getSimpleName(), Executors.newFixedThreadPool(4), Executors.newScheduledThreadPool(1), HOST); if (NettyChannelContext.isALPNEnabled()) { SslContext http2ClientContext = SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE) .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE) .applicationProtocolConfig(new ApplicationProtocolConfig( ApplicationProtocolConfig.Protocol.ALPN, ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE, ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2)) .build(); ((NettyHttpServiceClient) client).setHttp2SslContext(http2ClientContext); } SSLContext clientContext = SSLContext.getInstance(ServiceClient.TLS_PROTOCOL_NAME); clientContext.init(null, InsecureTrustManagerFactory.INSTANCE.getTrustManagers(), null); client.setSSLContext(clientContext); return client; }
doNothing().when(mockClient).sendRequest(valueCapture.capture()); verify(mockClient, never()).send(any(Operation.class));
@Test public void pendingRequestLimit() throws Throwable { for (int i = 0; i < this.iterationCount; i++) { this.tearDown(); setUpHost(false); List<Service> services = this.host.doThroughputServiceStart(this.serviceCount, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); // we need a fresh connection pool, with no connections already created // HTTP 1.1 test (connectionSharing == false) String tag = ServiceClient.CONNECTION_TAG_DEFAULT; int http11Count = Math.max(services.size() * this.requestCount, services.size() * this.host.getClient().getConnectionLimitPerTag(tag) * 4); verifyPerHostPendingRequestLimit(this.host, services, tag, http11Count / services.size(), false); this.host.getClient().stop(); } }
.getConnectionLimitPerTag(ServiceClient.CONNECTION_TAG_HTTP2_DEFAULT); ConnectionPoolMetrics http2Metrics = this.host.getClient().getConnectionPoolMetrics(true); assertTrue(http2Metrics != null); assertTrue(http2Metrics.inUseConnectionCount > 0); ConnectionPoolMetrics tagInfo = this.host.getClient().getConnectionPoolMetricsPerTag(tag); assertTrue(tagInfo != null); assertTrue(tagInfo.inUseConnectionCount > 0); this.host.connectionTag = "http2test"; this.host.log("Using tag specific connection limit %d", limit); this.host.getClient().setConnectionLimitPerTag(this.host.connectionTag, limit); this.host.doPutPerService( this.requestCount, services); http2Metrics = this.host.getClient().getConnectionPoolMetrics(true); assertTrue(http2Metrics != null); assertTrue(http2Metrics.inUseConnectionCount > 0); tagInfo = this.host.getClient().getConnectionPoolMetricsPerTag(tag); assertTrue(tagInfo != null); assertTrue(tagInfo.inUseConnectionCount > 0);
this.host.getClient().setConnectionLimitPerTag(this.host.connectionTag, 1); assertTrue(completionTimes[0] > completionTimes[1]); ConnectionPoolMetrics http2Metrics = this.host.getClient().getConnectionPoolMetrics(true); assertTrue(http2Metrics != null); assertTrue(http2Metrics.inUseConnectionCount > 0); ConnectionPoolMetrics tagInfo = this.host.getClient().getConnectionPoolMetricsPerTag(tag); assertTrue(tagInfo != null); assertTrue(tagInfo.inUseConnectionCount > 0);
public void handleMaintenance(Operation post) { if (serviceClient != null) { serviceClient.handleMaintenance(post); } }
public static ServiceClient createServiceClient() { try { ServiceClient serviceClient = NettyHttpServiceClient.create( JaxRsServiceClient.class.getSimpleName(), Executors.newFixedThreadPool(DEFAULT_THREAD_COUNT), Executors.newScheduledThreadPool(DEFAULT_THREAD_COUNT)); serviceClient.start(); return serviceClient; } catch (Exception e) { throw new RuntimeException("Unable to create ServiceClient due to " + e.getMessage(), e); } }
serviceClient.sendRequest(op); } catch (Exception e) { logger.severe(() -> String.format("Error sending login request for %s to %s,"
.getConnectionPoolMetrics(false); if (http11TagInfo != null) { createTimeSeriesStat( .getConnectionPoolMetrics(true); if (http2TagInfo != null) { createTimeSeriesStat(
client.setSSLContext(clientContext); client.start(); client.send(get); this.host.testWait(); Assert.assertNotNull("Peer principal", result.get()); Assert.assertEquals("Peer principal", "CN=agent-461b1767-ea89-4452-9408-283d0752fe40", result.get()); client.stop();
nonXenonLookingClient = NettyHttpServiceClient.create(UUID.randomUUID().toString(), Executors.newFixedThreadPool(1), Executors.newScheduledThreadPool(1)); nonXenonLookingClient.start(); s = System.nanoTime() / 1000; .forceRemote() .setCompletion(this.host.getExpectedFailureCompletion()); nonXenonLookingClient.send(put); this.host.testWait(); nonXenonLookingClient.stop();
@Test public void testConnectionLimit() throws Throwable { List<Service> services = this.host.doThroughputServiceStart(this.serviceCount, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); String tag = "http1.1ConnectionLimitTag"; int limit = 8; ServiceClient serviceClient = createNettyServiceClient(); serviceClient.setConnectionLimitPerTag(tag, limit); serviceClient.start(); for (int i = 0; i < this.iterationCount; i++) { doConnectionLimit(services, serviceClient, tag, limit); } serviceClient.stop(); }