NettyHttpServiceClient implements ServiceClient { @Override public void send(Operation op) { sendRequest(op); }  static ServiceClient create(String userAgent,
            ExecutorService executor,
            ScheduledExecutorService scheduledExecutor); static ServiceClient create(String userAgent,
            ExecutorService executor,
            ScheduledExecutorService scheduledExecutor,
            ServiceHost host); @Override void start(); @Override void stop(); ServiceClient setHttpProxy(URI proxy); @Override void send(Operation op); @Override void sendRequest(Operation op); @Override void handleMaintenance(Operation op); @Override ServiceClient setPendingRequestQueueLimit(int limit); @Override int getPendingRequestQueueLimit(); @Override ServiceClient setConnectionLimitPerTag(String tag, int limit); @Override int getConnectionLimitPerTag(String tag); ServiceClient setHttp2SslContext(SslContext context); SslContext getHttp2SslContext(); @Override ServiceClient setSSLContext(SSLContext context); @Override SSLContext getSSLContext(); NettyChannelPool getChannelPool(); NettyChannelPool getHttp2ChannelPool(); NettyChannelPool getSslChannelPool(); NettyChannelContext getInUseHttp2SslContext(String tag, String host, int port); NettyChannelContext getInUseHttp2Context(String tag, String host, int port); @Override ConnectionPoolMetrics getConnectionPoolMetrics(boolean http2); @Override ConnectionPoolMetrics getConnectionPoolMetricsPerTag(String tag); int getInUseContextCount(String tag, String host, int port); void clearCookieJar(); @Override int getRequestPayloadSizeLimit(); @Override ServiceClient setRequestPayloadSizeLimit(int limit); static final int DEFAULT_CONNECTIONS_PER_HOST; static final Logger LOGGER; }
@Test public void httpsGetAndPut() throws Throwable { List<Service> services = this.host.doThroughputServiceStart(10, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); List<URI> uris = new ArrayList<>(); for (Service s : services) { URI u = UriUtils.extendUri(this.host.getSecureUri(), s.getSelfLink()); uris.add(u); } this.host.getServiceState(null, MinimalTestServiceState.class, uris); this.host.testStart(uris.size()); for (URI u : uris) { MinimalTestServiceState body = (MinimalTestServiceState) this.host .buildMinimalTestState(); Operation put = Operation.createPut(u) .setBody(body) .forceRemote() .setCompletion(this.host.getCompletion()); this.host.send(put); } this.host.testWait(); String tag = ServiceClient.CONNECTION_TAG_DEFAULT; validateTagInfo(this.host, tag); }
@Test public void httpsFailure() throws Throwable { List<Service> services = this.host.doThroughputServiceStart(10, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); List<URI> uris = new ArrayList<>(); for (Service s : services) { URI u = UriUtils.extendUri(this.host.getSecureUri(), s.getSelfLink()); uris.add(u); } this.host.getServiceState(null, MinimalTestServiceState.class, uris); this.host.testStart(uris.size()); for (URI u : uris) { MinimalTestServiceState body = (MinimalTestServiceState) this.host .buildMinimalTestState(); body.id = MinimalTestService.STRING_MARKER_HAS_CONTEXT_ID; Operation put = Operation.createPatch(u).setBody(body) .setCompletion((o, e) -> { this.host.completeIteration(); }); this.host.send(put); } this.host.testWait(); }
@Test public void getSingleNoQueueingNotFound() throws Throwable { this.host.testStart(1); Operation get = Operation .createGet(UriUtils.buildUri(this.host, UUID.randomUUID().toString())) .setCompletion( (op, ex) -> { if (op.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) { this.host.completeIteration(); return; } this.host.failIteration(new Throwable( "Expected Operation.STATUS_CODE_NOT_FOUND")); }); this.host.send(get); this.host.testWait(); }
@Test public void getQueueServiceAvailability() throws Throwable { String targetPath = UUID.randomUUID().toString(); Operation startOp = Operation.createPost(UriUtils.buildUri(this.host, targetPath)) .setCompletion(this.host.getCompletion()); StatelessService testStatelessService = new StatelessService() { @Override public void handleRequest(Operation update) { update.complete(); } }; this.host.testStart(2); Operation get = Operation .createGet(UriUtils.buildUri(this.host, targetPath)) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion( (op, ex) -> { int statusCode = op.getStatusCode(); if (statusCode == Operation.STATUS_CODE_OK) { this.host.completeIteration(); return; } this.host.failIteration(new Throwable( "Expected Operation.STATUS_CODE_OK but was " + statusCode)); }); this.host.send(get); this.host.startService(startOp, testStatelessService); this.host.testWait(); }
@Test public void updatesWithForcedFailure() throws Throwable { long serviceCount = 1; List<Service> services = this.host.doThroughputServiceStart(serviceCount, MinimalTestService.class, this.host.buildMinimalTestState(), null, null); verifyErrorResponseBodyHandling(services); verifyRequestRetryPolicy(services); this.host.doPutPerService( EnumSet.of(TestProperty.FORCE_FAILURE, TestProperty.SINGLE_ITERATION), services); this.host.doPutPerService( EnumSet.of(TestProperty.FORCE_REMOTE, TestProperty.FORCE_FAILURE, TestProperty.SINGLE_ITERATION), services); this.host.testStart(1); this.host.send(Operation.createPut(services.get(0).getUri()) .setBody("this is not JSON") .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); this.host.testStart(1); this.host.send(Operation.createPut(services.get(0).getUri()) .setBody("this is not JSON") .forceRemote() .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); MinimalTestServiceState body = new MinimalTestServiceState(); this.host.testStart(1); body.id = MinimalTestService.STRING_MARKER_FAIL_REQUEST_WITH_CORRUPTED_JSON_RSP; this.host.send(Operation.createPatch(services.get(0).getUri()) .setBody(body) .forceRemote() .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); this.host.testStart(1); this.host.send(Operation.createPatch(services.get(0).getUri()) .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); this.host.testStart(1); this.host.send(Operation.createPatch(services.get(0).getUri()) .forceRemote() .setCompletion(this.host.getExpectedFailureCompletion())); this.host.testWait(); }
@Test public void validateOperationChecks() throws Throwable { URI noUri = null; URI noHostUri = new URI("/foo/bar/baz"); Operation noUriOp = Operation.createGet(noUri).setReferer(noHostUri); Operation noHostOp = Operation.createGet(noHostUri).setReferer(noHostUri); this.host.testStart(2); noUriOp.setCompletion((op, ex) -> { if (ex == null) { this.host.failIteration(ex); return; } if (!ex.getMessage().contains("Uri is required")) { this.host.failIteration(new IllegalStateException("Unexpected exception")); return; } this.host.completeIteration(); }); noHostOp.setCompletion((op, ex) -> { if (ex == null) { this.host.failIteration(ex); return; } if (!ex.getMessage().contains("host")) { this.host.failIteration(new IllegalStateException("Unexpected exception")); return; } this.host.completeIteration(); }); this.host.toggleNegativeTestMode(true); ServiceClient cl = this.host.getClient(); cl.send(noUriOp); cl.send(noHostOp); this.host.testWait(); this.host.toggleNegativeTestMode(false); }