private void verifyAcceptEither(long wait, boolean originalFirst) throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); DeferredResult<Integer> other = new DeferredResult<>(); AtomicInteger invocations = new AtomicInteger(); int originalValue = 10; int otherValue = 20; int expected = (originalFirst ? originalValue : otherValue); original .acceptEither(other, (x) -> { Assert.assertEquals(expected, x.intValue()); invocations.incrementAndGet(); }) .thenRun(() -> { Assert.assertFalse(originalFirst ? other.isDone() : original.isDone()); }) .whenComplete(ctx.getCompletionDeferred()); TestContext synchCtx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); if (originalFirst) { runAfterAndComplete(wait, () -> original.complete(originalValue), synchCtx); runAfter(synchCtx, wait, () -> other.complete(otherValue)); } else { runAfter(synchCtx, wait, () -> original.complete(originalValue)); runAfterAndComplete(wait, () -> other.complete(otherValue), synchCtx); } ctx.await(); Assert.assertEquals(1, invocations.get()); }
private void verifyAcceptEither(long wait, boolean originalFirst) throws Throwable { TestContext ctx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); DeferredResult<Integer> original = new DeferredResult<>(); DeferredResult<Integer> other = new DeferredResult<>(); AtomicInteger invocations = new AtomicInteger(); int originalValue = 10; int otherValue = 20; int expected = (originalFirst ? originalValue : otherValue); original .acceptEither(other, (x) -> { Assert.assertEquals(expected, x.intValue()); invocations.incrementAndGet(); }) .thenRun(() -> { Assert.assertFalse(originalFirst ? other.isDone() : original.isDone()); }) .whenComplete(ctx.getCompletionDeferred()); TestContext synchCtx = new TestContext(1, TestContext.DEFAULT_WAIT_DURATION); if (originalFirst) { runAfterAndComplete(wait, () -> original.complete(originalValue), synchCtx); runAfter(synchCtx, wait, () -> other.complete(otherValue)); } else { runAfter(synchCtx, wait, () -> original.complete(originalValue)); runAfterAndComplete(wait, () -> other.complete(otherValue), synchCtx); } ctx.await(); Assert.assertEquals(1, invocations.get()); }