public CompletionHandler getCompletion() { return (o, e) -> { if (e != null) { 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(); }
private void wrapCompletionHandlerWithCompleteIteration(Operation operation) { CompletionHandler ch = operation.getCompletion(); operation.setCompletion((op, e) -> { ch.handle(op, e); this.host.completeIteration(); }); }
@Test public void allocateExecutor() throws Throwable { setUp(false); Service s = this.host.startServiceAndWait(MinimalTestService.class, UUID.randomUUID() .toString()); ExecutorService exec = this.host.allocateExecutor(s); this.host.testStart(1); exec.execute(() -> { this.host.completeIteration(); }); this.host.testWait(); }
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 wrapCompletionHandlerWithCompleteIteration(Operation operation) { CompletionHandler ch = operation.getCompletion(); operation.setCompletion((op, e) -> { ch.handle(op, e); this.host.completeIteration(); }); }
public CompletionHandler getCompletion() { return (o, e) -> { if (e != null) { failIteration(e); return; } completeIteration(); }; }
@Test public void allocateExecutor() throws Throwable { setUp(false); Service s = this.host.startServiceAndWait(MinimalTestService.class, UUID.randomUUID() .toString()); ExecutorService exec = this.host.allocateExecutor(s); this.host.testStart(1); exec.execute(() -> { this.host.completeIteration(); }); this.host.testWait(); }
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(); }
public <T> BiConsumer<T, ? super Throwable> getCompletionDeferred() { return (ignore, e) -> { if (e != null) { if (e instanceof CompletionException) { e = e.getCause(); } failIteration(e); return; } completeIteration(); }; }
@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(); }; }
@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(); }
protected Consumer<Collection<String>> verify(Consumer<Collection<String>> consumer) { return (registryLinks) -> { try { consumer.accept(registryLinks); host.completeIteration(); } catch (Throwable x) { host.failIteration(x); } }; }
private void commit(String transactionId) throws Throwable { this.defaultHost.testStart(1); Operation patch = SimpleTransactionService.TxUtils.buildCommitRequest(this.defaultHost, transactionId); patch.setCompletion((o, e) -> { if (operationFailed(o, e)) { this.defaultHost.failIteration(e); return; } this.defaultHost.completeIteration(); }); this.defaultHost.send(patch); this.defaultHost.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(); } }; } }
private void abort(String transactionId) throws Throwable { this.defaultHost.testStart(1); Operation patch = SimpleTransactionService.TxUtils.buildAbortRequest(this.defaultHost, transactionId); patch.setCompletion((o, e) -> { if (operationFailed(o, e)) { this.defaultHost.failIteration(e); return; } this.defaultHost.completeIteration(); }); this.defaultHost.send(patch); this.defaultHost.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(); } }; } }
private void sendGetContainerStateRequest() throws Throwable { Operation getContainerState = Operation.createGet(containerStateReference) .setCompletion((o, ex) -> { if (ex != null) { host.failIteration(ex); } else { containerState = o.getBody(ContainerState.class); host.completeIteration(); } }); host.testStart(1); host.send(getContainerState); host.testWait(); }
@Before public void setup() { placementHostSelectionTaskState = new PlacementHostSelectionTaskState(); placementHostSelectionTaskState.contextId = UUID.randomUUID().toString(); host = Mockito.mock(VerificationHost.class); Mockito.when(host.getUri()).thenReturn(URI.create("http://mocked.verification.host:1234")); Answer<Void> realMethodAnswer = invocation -> { invocation.callRealMethod(); return null; }; Mockito.doAnswer(realMethodAnswer).when(host).completeIteration(); Mockito.doAnswer(realMethodAnswer).when(host).failIteration(Mockito.any(Throwable.class)); }