Search in sources :

Example 1 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class CollectTest method collectIterableDelayErrorMaxConcurrency.

@Test
void collectIterableDelayErrorMaxConcurrency() throws Exception {
    AtomicBoolean secondSubscribed = new AtomicBoolean();
    Future<? extends Collection<Integer>> future = collectUnorderedDelayError(asList(failed(DELIBERATE_EXCEPTION), succeeded(2).beforeOnSubscribe(__ -> secondSubscribed.set(true))), 1).toFuture();
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertThat("Second source not subscribed.", secondSubscribed.get(), is(true));
        assertThat("Unexpected exception.", e.getCause(), is(DELIBERATE_EXCEPTION));
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) Collection(java.util.Collection) Single.collectUnorderedDelayError(io.servicetalk.concurrent.api.Single.collectUnorderedDelayError) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Single.collectUnordered(io.servicetalk.concurrent.api.Single.collectUnordered) Future(java.util.concurrent.Future) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Arrays.asList(java.util.Arrays.asList) Single.failed(io.servicetalk.concurrent.api.Single.failed) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 2 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class SingleToCompletionStageTest method completableFutureFromSingleToCompletionStageToCompletableFutureFailure.

@Test
void completableFutureFromSingleToCompletionStageToCompletableFutureFailure() {
    CompletableFuture<Long> input = new CompletableFuture<>();
    CompletableFuture<Long> output = Single.fromStage(input).toCompletionStage().toCompletableFuture().whenComplete((v, c) -> {
    }).thenApply(l -> l + 1).whenComplete((v, c) -> {
    });
    input.completeExceptionally(DELIBERATE_EXCEPTION);
    ExecutionException e = assertThrows(ExecutionException.class, () -> output.get());
    assertThat(e.getCause(), is(DELIBERATE_EXCEPTION));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) LegacyTestSingle(io.servicetalk.concurrent.api.LegacyTestSingle) BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BiFunction(java.util.function.BiFunction) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TimeoutException(java.util.concurrent.TimeoutException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Thread.currentThread(java.lang.Thread.currentThread) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AfterAll(org.junit.jupiter.api.AfterAll) Future(java.util.concurrent.Future) BeforeAll(org.junit.jupiter.api.BeforeAll) RegisterExtension(org.junit.jupiter.api.extension.RegisterExtension) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Executor(io.servicetalk.concurrent.api.Executor) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) ExecutorService(java.util.concurrent.ExecutorService) Nullable(javax.annotation.Nullable) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) ExecutorExtension(io.servicetalk.concurrent.api.ExecutorExtension) CancellationException(java.util.concurrent.CancellationException) Single(io.servicetalk.concurrent.api.Single) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) CountDownLatch(java.util.concurrent.CountDownLatch) CompletionStage(java.util.concurrent.CompletionStage) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Matchers.is(org.hamcrest.Matchers.is) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 3 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class BeforeErrorTest method testCallbackThrowsError.

@Override
@Test
void testCallbackThrowsError() {
    DeliberateException srcEx = new DeliberateException();
    this.<String>doError(Publisher.failed(srcEx), t1 -> {
        throw DELIBERATE_EXCEPTION;
    }).subscribe(subscriber);
    subscriber.awaitSubscription().request(1);
    assertThat(subscriber.awaitOnError(), sameInstance(srcEx));
    verifySuppressed(subscriber.awaitOnError(), DELIBERATE_EXCEPTION);
}
Also used : Test(org.junit.jupiter.api.Test) Consumer(java.util.function.Consumer) VerificationTestUtils.verifySuppressed(io.servicetalk.concurrent.api.VerificationTestUtils.verifySuppressed) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Publisher(io.servicetalk.concurrent.api.Publisher) PublisherSource(io.servicetalk.concurrent.PublisherSource) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) SourceAdapters.toSource(io.servicetalk.concurrent.api.SourceAdapters.toSource) DeliberateException(io.servicetalk.concurrent.internal.DeliberateException) Test(org.junit.jupiter.api.Test)

Example 4 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class CollectTest method collectIterableDelayError.

@Test
void collectIterableDelayError() throws Exception {
    AtomicBoolean secondSubscribed = new AtomicBoolean();
    Future<Void> future = mergeAllDelayError(asList(failed(DELIBERATE_EXCEPTION), completed().beforeOnSubscribe(__ -> secondSubscribed.set(true)))).toFuture();
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertThat("Second source not subscribed.", secondSubscribed.get(), is(true));
        assertThat("Unexpected exception.", e.getCause(), is(DELIBERATE_EXCEPTION));
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Completable.mergeAllDelayError(io.servicetalk.concurrent.api.Completable.mergeAllDelayError) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) Arrays.asList(java.util.Arrays.asList) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Completable.mergeAll(io.servicetalk.concurrent.api.Completable.mergeAll) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Completable.failed(io.servicetalk.concurrent.api.Completable.failed) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Example 5 with DELIBERATE_EXCEPTION

use of io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION in project servicetalk by apple.

the class CollectTest method collectIterableDelayErrorMaxConcurrency.

@Test
void collectIterableDelayErrorMaxConcurrency() throws Exception {
    AtomicBoolean secondSubscribed = new AtomicBoolean();
    Future<Void> future = mergeAllDelayError(asList(failed(DELIBERATE_EXCEPTION), completed().beforeOnSubscribe(__ -> secondSubscribed.set(true))), 1).toFuture();
    try {
        future.get();
        fail();
    } catch (ExecutionException e) {
        assertThat("Second source not subscribed.", secondSubscribed.get(), is(true));
        assertThat("Unexpected exception.", e.getCause(), is(DELIBERATE_EXCEPTION));
    }
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Completable.mergeAllDelayError(io.servicetalk.concurrent.api.Completable.mergeAllDelayError) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) Future(java.util.concurrent.Future) Arrays.asList(java.util.Arrays.asList) Completable.completed(io.servicetalk.concurrent.api.Completable.completed) Completable.mergeAll(io.servicetalk.concurrent.api.Completable.mergeAll) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Completable.failed(io.servicetalk.concurrent.api.Completable.failed) DELIBERATE_EXCEPTION(io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

DELIBERATE_EXCEPTION (io.servicetalk.concurrent.internal.DeliberateException.DELIBERATE_EXCEPTION)49 Test (org.junit.jupiter.api.Test)46 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)42 Matchers.is (org.hamcrest.Matchers.is)37 SourceAdapters.toSource (io.servicetalk.concurrent.api.SourceAdapters.toSource)32 Subscription (io.servicetalk.concurrent.PublisherSource.Subscription)28 Mockito.mock (org.mockito.Mockito.mock)27 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)24 Future (java.util.concurrent.Future)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)21 Mockito.verify (org.mockito.Mockito.verify)21 PublisherSource (io.servicetalk.concurrent.PublisherSource)19 Arrays.asList (java.util.Arrays.asList)19 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)19 Mockito.doAnswer (org.mockito.Mockito.doAnswer)19 Publisher.from (io.servicetalk.concurrent.api.Publisher.from)17 DeliberateException (io.servicetalk.concurrent.internal.DeliberateException)17 CountDownLatch (java.util.concurrent.CountDownLatch)17 ExecutionException (java.util.concurrent.ExecutionException)17 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)17