private void runAfter(TestContext ctx, long additionalDelay, Runnable action) { Thread t = new Thread(() -> { ctx.await(); if (additionalDelay > 0) { sleep(additionalDelay); } action.run(); }); t.setDaemon(true); t.start(); }
private void runAfter(TestContext ctx, long additionalDelay, Runnable action) { Thread t = new Thread(() -> { ctx.await(); if (additionalDelay > 0) { sleep(additionalDelay); } action.run(); }); t.setDaemon(true); t.start(); }
private void waitFor(Map map, int count) { TestContext context = new TestContext(1, Duration.ofMinutes(1)); schedule(map, count, context); context.await(); }
public void await(DeferredResult<?> deferredResult) { await(() -> { if (deferredResult.isDone()) { this.completeIteration(); } }); }
protected void waitForServiceAvailability(ServiceHost h, String... serviceLinks) throws Throwable { if (serviceLinks == null || serviceLinks.length == 0) { throw new IllegalArgumentException("null or empty serviceLinks"); } TestContext ctx = testCreate(serviceLinks.length); h.registerForServiceAvailability(ctx.getCompletion(), serviceLinks); ctx.await(); }
@Test public void testCreateionOfChangeComputeNameTopic() { // On start service creates new topic. No need for explicit post for creation. TestContext context = new TestContext(1, Duration.ofSeconds(120)); verifyThatTopicExists(CHANGE_COMPUTE_NAME_SELF_LINK, context); context.await(); }
@Test public void testCreateionOfChangeContainerNameTopic() { // On start service creates new topic. No need for explicit post for creation. TestContext context = new TestContext(1, Duration.ofSeconds(120)); verifyThatTopicExists(CHANGE_CONTAINER_NAME_SELF_LINK, context); context.await(); }
public void waitForServiceAvailable(String... links) { for (String link : links) { TestContext ctx = testCreate(1); this.registerForServiceAvailability(ctx.getCompletion(), link); ctx.await(); } }
public void waitForServiceAvailable(String... links) { for (String link : links) { TestContext ctx = testCreate(1); this.registerForServiceAvailability(ctx.getCompletion(), link); ctx.await(); } }
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]; }); }
@Test public void testNoHarborProperty() throws Exception { TestContext t = new TestContext(1, Duration.ofSeconds(15)); harborInitRegistryService.handleStart(Operation .createGet(null) .setCompletion(t.getCompletion())); t.await(); RegistryState harborRegistry = getHarborRegistry(false); assertNull(harborRegistry); }
@Test public void testThenApply() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); DeferredResult<Integer> result = original .thenApply(i -> i + 1); result.whenComplete(ctx.getCompletionDeferred()); runAfter(10, () -> original.complete(1)); ctx.await(); Assert.assertEquals(2, result.getNow(0).intValue()); }
@Test public void testThenApply() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); DeferredResult<Integer> result = original .thenApply(i -> i + 1); result.whenComplete(ctx.getCompletionDeferred()); runAfter(10, () -> original.complete(1)); ctx.await(); Assert.assertEquals(2, result.getNow(0).intValue()); }
@Test public void testThenAcceptCanThrowException() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); original .thenAccept(i -> { throw new TestException(); }) .whenComplete(getExpectedExceptionCompletion(ctx)); runAfter(10, () -> original.complete(1)); ctx.await(); }
public static void stopContinuousQuerySubscription(TestRequestSender s, ServiceHost host, URI notificationTarget, QueryTask qt) { TestContext ctx = new TestContext(1, s.getTimeout()); Operation delete = Operation .createDelete(UriUtils.buildUri(notificationTarget, qt.documentSelfLink)) .setReferer(host.getUri()) .setCompletion(ctx.getCompletion()); host.stopSubscriptionService(delete, notificationTarget); ctx.await(); }
@Test public void testThenAcceptCanThrowException() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); original .thenAccept(i -> { throw new TestException(); }) .whenComplete(getExpectedExceptionCompletion(ctx)); runAfter(10, () -> original.complete(1)); ctx.await(); }
@Test public void testThenComposeNestedStageException() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult.completed(12345) .thenCompose(ignore -> { DeferredResult<String> nested = new DeferredResult<>(); runAfter(10, () -> nested.fail(new TestException())); return nested; }) .whenComplete(getExpectedExceptionCompletion(ctx)); ctx.await(); }
@Test public void testThenComposeNestedStageException() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult.completed(12345) .thenCompose(ignore -> { DeferredResult<String> nested = new DeferredResult<>(); runAfter(10, () -> nested.fail(new TestException())); return nested; }) .whenComplete(getExpectedExceptionCompletion(ctx)); ctx.await(); }