Search in sources :

Example 1 with DeferredSubscription

use of reactor.core.publisher.Operators.DeferredSubscription in project reactor-core by reactor.

the class OperatorsTest method onNextErrorModeLocalStrategy.

@Test
public void onNextErrorModeLocalStrategy() {
    List<Object> nextDropped = new ArrayList<>();
    List<Object> errorDropped = new ArrayList<>();
    Hooks.onNextDropped(nextDropped::add);
    Hooks.onErrorDropped(errorDropped::add);
    Hooks.onNextError(OnNextFailureStrategy.STOP);
    Context c = Context.of(OnNextFailureStrategy.KEY_ON_NEXT_ERROR_STRATEGY, OnNextFailureStrategy.RESUME_DROP);
    Exception error = new IllegalStateException("boom");
    DeferredSubscription s = new Operators.DeferredSubscription();
    try {
        assertThat(s.isCancelled()).as("s initially cancelled").isFalse();
        Throwable e = Operators.onNextError("foo", error, c, s);
        assertThat(e).isNull();
        assertThat(nextDropped).containsExactly("foo");
        assertThat(errorDropped).containsExactly(error);
        assertThat(s.isCancelled()).as("s cancelled").isFalse();
    } finally {
        Hooks.resetOnNextDropped();
        Hooks.resetOnErrorDropped();
        Hooks.resetOnNextError();
    }
}
Also used : Context(reactor.util.context.Context) ArrayList(java.util.ArrayList) DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.Test)

Example 2 with DeferredSubscription

use of reactor.core.publisher.Operators.DeferredSubscription in project reactor-core by reactor.

the class OperatorsTest method scanDeferredSubscription.

@Test
public void scanDeferredSubscription() {
    DeferredSubscription test = new DeferredSubscription();
    test.s = Operators.emptySubscription();
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(test.s);
    test.requested = 123;
    assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(123);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : DeferredSubscription(reactor.core.publisher.Operators.DeferredSubscription) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DeferredSubscription (reactor.core.publisher.Operators.DeferredSubscription)2 ArrayList (java.util.ArrayList)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1 Context (reactor.util.context.Context)1