private Consumer<SubscriptionNotification<ContainerState>> handler() { return (r) -> { results.clear(); results.add(r); this.activeContext.completeIteration(); }; }
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 runAfterAndComplete(long millis, Runnable action, TestContext ctx) { runAfter(millis, () -> { action.run(); ctx.completeIteration(); }); }
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 runAfterAndComplete(long millis, Runnable action, TestContext ctx) { runAfter(millis, () -> { action.run(); ctx.completeIteration(); }); }
public void completeIteration() { if (this.isSingleton) { throw new IllegalStateException("Use startTest on singleton, shared host instances"); } TestContext ctx = this.context; if (ctx == null) { String error = "testStart() and testWait() not paired properly" + " or testStart(N) was called with N being less than actual completions"; log(error); return; } ctx.completeIteration(); }
public void completeIteration() { if (this.isSingleton) { throw new IllegalStateException("Use startTest on singleton, shared host instances"); } TestContext ctx = this.context; if (ctx == null) { String error = "testStart() and testWait() not paired properly" + " or testStart(N) was called with N being less than actual completions"; log(error); return; } ctx.completeIteration(); }
private void schedule(Map map, int count, TestContext context) { if (map.size() != count) { host.schedule(() -> { schedule(map, count, context); return; }, 3000, TimeUnit.MILLISECONDS); } context.completeIteration(); }
public CompletionHandler getSafeHandler(TestContext ctx, CompletionHandler handler) { return (o, e) -> { try { handler.handle(o, e); ctx.completeIteration(); } catch (Throwable t) { ctx.failIteration(t); } }; }
public void await(DeferredResult<?> deferredResult) { await(() -> { if (deferredResult.isDone()) { this.completeIteration(); } }); }
public CompletionHandler getSafeHandler(TestContext ctx, CompletionHandler handler) { return (o, e) -> { try { handler.handle(o, e); ctx.completeIteration(); } catch (Throwable t) { ctx.failIteration(t); } }; }
private void verifyContainerNameHasBeenUpdated(String containerLink, TestContext context) { // Get container and verify that its name has been updated by subscriber. ContainerState containerState = sendOperation(host, UriUtils.buildUri(host, containerLink), null, ContainerState.class, Action.GET); // If subscriber doesn't update container's name within 30 seconds, context will expire. while (!containerState.name.equals(DummySubscriber.class.getSimpleName())) { containerState = sendOperation(host, UriUtils.buildUri(host, containerLink), null, ContainerState.class, Action.GET); } context.completeIteration(); }
@Override public void handleRequest(Operation op) { if (!op.isNotification()) { if (op.getAction() == Action.DELETE && op.getUri().equals(getUri())) { notifyDeleteContext.completeIteration(); } super.handleRequest(op); return; } if (op.getAction() == Action.PUT) { notifyContext.completeIteration(); } } };
private void waitFor(TestWaitForHandler handler, TestContext context) throws Throwable { if (!handler.test()) { cluster.schedule(() -> { try { waitFor(handler, context); } catch (Throwable throwable) { } }, 1, TimeUnit.SECONDS); } else { context.completeIteration(); } }
private void deleteNotificationTarget(AtomicInteger deletesRemainingCount, ServiceSubscriber sr) throws Throwable { deletesRemainingCount.set(1); TestContext ctx = testCreate(1); this.host.send(Operation.createDelete(sr.reference) .setCompletion((o, e) -> ctx.completeIteration())); testWait(ctx); }
private void deleteNotificationTarget(AtomicInteger deletesRemainingCount, ServiceSubscriber sr) throws Throwable { deletesRemainingCount.set(1); TestContext ctx = testCreate(1); this.host.send(Operation.createDelete(sr.reference) .setCompletion((o, e) -> ctx.completeIteration())); testWait(ctx); }
public void waitForReplicatedFactoryServiceNotAvailable(VerificationHost host, URI u, String nodeSelectorPath) { host.waitFor("replicated not available check time out for " + u, () -> { boolean[] isReady = new boolean[1]; TestContext ctx = testCreate(1); NodeGroupUtils.checkServiceAvailability((o, e) -> { isReady[0] = e != null; ctx.completeIteration(); }, this.host, u, nodeSelectorPath); ctx.await(); return isReady[0]; }); }
public void waitForReplicatedFactoryServiceNotAvailable(VerificationHost host, URI u, String nodeSelectorPath) { host.waitFor("replicated not available check time out for " + u, () -> { boolean[] isReady = new boolean[1]; TestContext ctx = testCreate(1); NodeGroupUtils.checkServiceAvailability((o, e) -> { isReady[0] = e != null; ctx.completeIteration(); }, this.host, u, nodeSelectorPath); ctx.await(); return isReady[0]; }); }
public void waitForReplicatedFactoryServiceNotAvailable(VerificationHost host, URI u, String nodeSelectorPath) { host.waitFor("replicated not available check time out for " + u, () -> { boolean[] isReady = new boolean[1]; TestContext ctx = testCreate(1); NodeGroupUtils.checkServiceAvailability((o, e) -> { isReady[0] = e != null; ctx.completeIteration(); }, this.host, u, nodeSelectorPath); ctx.await(); return isReady[0]; }); }
private void queryTemplateImages() { TestContext ctx = BaseTestCase.testCreate(1); host.sendRequest(Operation.createGet(UriUtils.buildUri(host, templateQuery)) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { ctx.failIteration(ex); } else { ctx.completeIteration(); } })); ctx.await(); }