public CompletionHandler getCompletion() { return (o, e) -> { if (e != null) { failIteration(e); return; } completeIteration(); }; }
private <T> T testExecuteTask(RetriableTaskBuilder<T> task) { ArrayList<T> result = new ArrayList<>(1); host.testStart(1); task.execute().whenComplete((taskResult, ex) -> { if (ex != null) { host.failIteration(ex); } else { result.add(taskResult); host.completeIteration(); } }); host.testWait(); return result.iterator().next(); }
private void verifyRegistryLinksByRegistryFilter(String registryFilter, Collection<String> tenantLinks, Collection<RegistryState> expectedRegistries) { assertNotNull(expectedRegistries); host.testStart(1); RegistryUtil.findRegistries(host, tenantLinks, registryFilter, (registries, errors) -> { if (errors != null && !errors.isEmpty()) { host.failIteration(errors.iterator().next()); } verifyFoundRegistries(expectedRegistries, registries); }); host.testWait(); }
@Test public void testSetOperationsFailureWithoutOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); host.testStart(1); try { operationJoin.sendWith(host); host.failIteration(new IllegalStateException("Expected exception")); } catch (IllegalStateException e) { host.completeIteration(); } host.testWait(); }
public CompletionHandler getCompletion() { return (o, e) -> { if (e != null) { failIteration(e); return; } completeIteration(); }; }
private void verifyRegistryLinksByHostname(String hostname, Collection<String> tenantLinks, Collection<RegistryState> expectedRegistries) { assertNotNull(expectedRegistries); host.testStart(1); RegistryUtil.findRegistriesByHostname(host, hostname, tenantLinks, (registries, errors) -> { if (errors != null && !errors.isEmpty()) { host.failIteration(errors.iterator().next()); } verifyFoundRegistries(expectedRegistries, registries); }); host.testWait(); }
@Test public void testSetOperationsFailureWithoutOperations() throws Throwable { OperationJoin operationJoin = OperationJoin.create(); host.testStart(1); try { operationJoin.sendWith(host); host.failIteration(new IllegalStateException("Expected exception")); } catch (IllegalStateException e) { host.completeIteration(); } host.testWait(); }
public <T> BiConsumer<T, ? super Throwable> getCompletionDeferred() { return (ignore, e) -> { if (e != null) { if (e instanceof CompletionException) { e = e.getCause(); } failIteration(e); return; } completeIteration(); }; }
private void sendGetNetworkStateRequest() throws Throwable { Operation getNetworkState = Operation.createGet(networkStateReference) .setCompletion((o, ex) -> { if (ex != null) { host.failIteration(ex); } else { host.completeIteration(); } }); host.testStart(1); host.send(getNetworkState); host.testWait(); }
public <T> BiConsumer<T, ? super Throwable> getCompletionDeferred() { return (ignore, e) -> { if (e != null) { if (e instanceof CompletionException) { e = e.getCause(); } failIteration(e); return; } completeIteration(); }; }
public void testJoinWithBatch(Consumer<JoinWithBatchParams> createJoinOperation) throws Throwable { for (int numberOfOperations = 1; numberOfOperations < 5; numberOfOperations++) { for (int batchSize = 1; batchSize < numberOfOperations; batchSize++) { Collection<Operation> ops = getOperations( numberOfOperations, this.services.get(0), (o, e) -> { try { host.completeIteration(); } catch (Throwable ex) { host.failIteration(ex); } }); host.testStart(numberOfOperations); createJoinOperation.accept(new JoinWithBatchParams(ops, batchSize)); host.testWait(); } } }
protected Consumer<Collection<String>> verify(Consumer<Collection<String>> consumer) { return (registryLinks) -> { try { consumer.accept(registryLinks); host.completeIteration(); } catch (Throwable x) { host.failIteration(x); } }; }
public void testJoinWithBatch(Consumer<JoinWithBatchParams> createJoinOperation) throws Throwable { for (int numberOfOperations = 1; numberOfOperations < 5; numberOfOperations++) { for (int batchSize = 1; batchSize < numberOfOperations; batchSize++) { Collection<Operation> ops = getOperations( numberOfOperations, this.services.get(0), (o, e) -> { try { host.completeIteration(); } catch (Throwable ex) { host.failIteration(ex); } }); host.testStart(numberOfOperations); createJoinOperation.accept(new JoinWithBatchParams(ops, batchSize)); host.testWait(); } } }
private void validateBroadcastQueryPostFailure(VerificationHost targetHost, Operation o, Throwable e) { if (e != null) { ServiceErrorResponse rsp = o.getErrorResponseBody(); if (rsp.message == null || !rsp.message.contains(QueryOption.BROADCAST.toString())) { targetHost.failIteration(new IllegalStateException("Expected failure")); return; } targetHost.completeIteration(); } else { targetHost.failIteration(new IllegalStateException("expected failure")); } }
private void sendGetVolumeStateRequest() throws Throwable { Operation getVolumeState = Operation.createGet(volumeStateReference) .setCompletion((o, ex) -> { if (ex != null) { host.failIteration(ex); } else { host.completeIteration(); } }); host.testStart(1); host.send(getVolumeState); host.testWait(); }
private void validateBroadcastQueryPostFailure(VerificationHost targetHost, Operation o, Throwable e) { if (e != null) { ServiceErrorResponse rsp = o.getErrorResponseBody(); if (rsp.message == null || !rsp.message.contains(QueryOption.BROADCAST.toString())) { targetHost.failIteration(new IllegalStateException("Expected failure")); return; } targetHost.completeIteration(); } else { targetHost.failIteration(new IllegalStateException("expected failure")); } }
private void deleteResourceOrClonedCompositeDescription(String descriptionLink, Class<? extends ServiceDocument> descriptionClass, BiFunction<ServiceHost, String, DeferredResult<Void>> deleteFunction) throws Throwable { // verify description exists verifyDocumentExists(descriptionLink, descriptionClass); // delete it host.testStart(1); deleteFunction.apply(host, descriptionLink) .whenComplete((ignore, ex) -> { if (ex != null) { host.failIteration(ex instanceof CompletionException ? ex.getCause() : ex); } else { host.completeIteration(); } }); host.testWait(); // verify it is not there anymore verifyDocumentDoesNotExist(descriptionLink, descriptionClass); // remove it from the cleanup list descriptionLinks.remove(descriptionLink); }
private ResultHandler<MinimalTestServiceState> handler() { this.minimalTestStates.clear(); return (r, e) -> { if (e != null) { this.host.failIteration(e); } else if (r.hasResult()) { this.minimalTestStates.add(r.getResult()); } else { this.host.completeIteration(); } }; } }
@Test public void completeOkWithCompletionHandler() throws Throwable { CompletableFuture<Operation> f = this.host.sendWithFuture(Operation .createGet(UriUtils.buildUri(this.host, "/"))); host.testStart(1); f.handle((o, e) -> { if (e != null) { host.failIteration(e); } else { host.completeIteration(); } return null; }); host.testWait(); }
private ResultHandler<MinimalTestServiceState> handler() { this.minimalTestStates.clear(); return (r, e) -> { if (e != null) { this.host.failIteration(e); } else if (r.hasResult()) { this.minimalTestStates.add(r.getResult()); } else { this.host.completeIteration(); } }; } }