/** * Consider using {@link #TestContext(int, Duration)} * This method exists for backward compatibility, and may be deprecated/deleted in future. */ public static TestContext create(int count, long expIntervalMicros) { return new TestContext(count, Duration.of(expIntervalMicros, ChronoUnit.MICROS)); }
/** * Consider using {@link #TestContext(int, Duration)} * This method exists for backward compatibility, and may be deprecated/deleted in future. */ public static TestContext create(int count, long expIntervalMicros) { return new TestContext(count, Duration.of(expIntervalMicros, ChronoUnit.MICROS)); }
private void waitFor(String errorMessage, TestWaitForHandler handler) throws Throwable { TestContext context = new TestContext(1, Duration.ofMinutes(1)); waitFor(handler, context); try { context.await(); } catch (Exception e) { throw new Exception(errorMessage, e); } }
private void waitFor(Map map, int count) { TestContext context = new TestContext(1, Duration.ofMinutes(1)); schedule(map, count, 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(); }
@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(); }
private static void waitForDefaultRegistryCreated(ManagementHost host) { TestContext ctx = new TestContext(1, Duration.ofSeconds(120)); host.log(Level.INFO, "Waiting for default registry to start."); host.registerForServiceAvailability(ctx.getCompletion(), RegistryService.DEFAULT_INSTANCE_LINK); ctx.await(); host.log(Level.INFO, "Default registry started."); }
@Test public void testThenRun() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); AtomicInteger invocations = new AtomicInteger(); DeferredResult<Integer> original = new DeferredResult<>(); original .thenRun(() -> { invocations.incrementAndGet(); }) .whenComplete(ctx.getCompletionDeferred()); runAfter(10, () -> original.complete(1)); ctx.await(); Assert.assertEquals(1, invocations.get()); }
@Test public void testGetNowWithValue() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); TestContext synchCtx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); int defaultValue = 0; int value = 10; DeferredResult<Integer> deferredResult = new DeferredResult<>(); deferredResult.whenComplete(ctx.getCompletionDeferred()); runAfter(synchCtx, () -> deferredResult.complete(value)); Assert.assertEquals(defaultValue, deferredResult.getNow(defaultValue).intValue()); synchCtx.complete(); ctx.await(); Assert.assertEquals(value, deferredResult.getNow(defaultValue).intValue()); }
@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()); }
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 testThenCombine() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); DeferredResult<Integer> other = new DeferredResult<>(); DeferredResult<Integer> result = original .thenCombine(other, (x, y) -> x + y); result.whenComplete(ctx.getCompletionDeferred()); runAfter(10, () -> original.complete(1)); runAfter(20, () -> other.complete(2)); ctx.await(); Assert.assertEquals(3, 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 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(); }
@Test public void testThenCompose() throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<String> result = DeferredResult.completed(12345) .thenCompose(ignore -> { DeferredResult<String> nested = new DeferredResult<>(); runAfter(10, () -> nested.complete("foo")); return nested; }); result.whenComplete(ctx.getCompletionDeferred()); ctx.await(); Assert.assertEquals("foo", result.getNow("bar")); }