Search in sources :

Example 1 with Exceptions

use of reactor.core.Exceptions in project reactor-core by reactor.

the class MonoDoOnEachTest method consumerBubbleError.

@Test
public void consumerBubbleError() {
    LongAdder state = new LongAdder();
    Throwable err = new Exception("test");
    assertThatThrownBy(() -> StepVerifier.create(Mono.just(1).doOnEach(s -> {
        if (s.isOnNext()) {
            state.increment();
            throw Exceptions.bubble(err);
        }
    })).expectErrorMessage("test").verify()).isInstanceOf(RuntimeException.class).matches(Exceptions::isBubbling, "bubbling").hasCause(// equivalent to unwrap for this case
    err);
    assertThat(state.intValue()).isEqualTo(1);
}
Also used : LongAdder(java.util.concurrent.atomic.LongAdder) StepVerifier(reactor.test.StepVerifier) Context(reactor.util.context.Context) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Tuples(reactor.util.function.Tuples) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Tuple2(reactor.util.function.Tuple2) Test(org.junit.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Mockito(org.mockito.Mockito) List(java.util.List) CoreSubscriber(reactor.core.CoreSubscriber) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AssertSubscriber(reactor.test.subscriber.AssertSubscriber) Assertions(org.assertj.core.api.Assertions) Exceptions(reactor.core.Exceptions) LongAdder(java.util.concurrent.atomic.LongAdder) Test(org.junit.Test)

Example 2 with Exceptions

use of reactor.core.Exceptions in project reactor-core by reactor.

the class FluxOnBackpressureBufferTest method onBackpressureBufferMaxCallbackOverflow.

@Test
public void onBackpressureBufferMaxCallbackOverflow() {
    AtomicInteger last = new AtomicInteger();
    StepVerifier.create(Flux.range(1, 100).hide().onBackpressureBuffer(8, last::set, BufferOverflowStrategy.ERROR), 0).thenRequest(7).expectNext(1, 2, 3, 4, 5, 6, 7).then(() -> assertThat(last.get()).isEqualTo(16)).thenRequest(9).expectNextCount(8).verifyErrorMatches(Exceptions::isOverflow);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Exceptions(reactor.core.Exceptions) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Example 3 with Exceptions

use of reactor.core.Exceptions in project reactor-core by reactor.

the class FluxOnBackpressureBufferTest method onBackpressureBufferMaxCallback.

@Test
public void onBackpressureBufferMaxCallback() {
    AtomicInteger last = new AtomicInteger();
    StepVerifier.create(Flux.range(1, 100).hide().onBackpressureBuffer(8, last::set), 0).thenRequest(7).expectNext(1, 2, 3, 4, 5, 6, 7).then(() -> assertThat(last.get()).isEqualTo(16)).thenRequest(9).expectNextCount(8).verifyErrorMatches(Exceptions::isOverflow);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Exceptions(reactor.core.Exceptions) Test(org.junit.Test) FluxOperatorTest(reactor.test.publisher.FluxOperatorTest)

Aggregations

AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.Test)3 Exceptions (reactor.core.Exceptions)3 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 LongAdder (java.util.concurrent.atomic.LongAdder)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)1 ArgumentCaptor (org.mockito.ArgumentCaptor)1 Mockito (org.mockito.Mockito)1 CoreSubscriber (reactor.core.CoreSubscriber)1 StepVerifier (reactor.test.StepVerifier)1 AssertSubscriber (reactor.test.subscriber.AssertSubscriber)1 Context (reactor.util.context.Context)1 Tuple2 (reactor.util.function.Tuple2)1 Tuples (reactor.util.function.Tuples)1