Search in sources :

Example 1 with UsingWhenSubscriber

use of reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber in project reactor-core by reactor.

the class FluxUsingWhenTest method scanRollbackInner.

@Test
public void scanRollbackInner() {
    CoreSubscriber<? super Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    UsingWhenSubscriber<Integer, String> up = new UsingWhenSubscriber<>(actual, "RESOURCE", Mono::just, (s, err) -> Mono.just(s), Mono::just, null);
    final Subscription parent = Operators.emptySubscription();
    up.onSubscribe(parent);
    FluxUsingWhen.RollbackInner op = new FluxUsingWhen.RollbackInner(up, new IllegalStateException("rollback cause"));
    assertThat(op.scan(Attr.PARENT)).as("PARENT").isSameAs(up);
    assertThat(op.scan(Attr.ACTUAL)).as("ACTUAL").isSameAs(up.actual);
    assertThat(op.scan(Attr.RUN_STYLE)).isSameAs(Attr.RunStyle.SYNC);
    assertThat(op.scan(Attr.TERMINATED)).as("TERMINATED before").isFalse();
    op.onComplete();
    assertThat(op.scan(Attr.TERMINATED)).as("TERMINATED by complete").isSameAs(up.scan(Attr.TERMINATED)).isTrue();
    assertThat(up.scan(Attr.ERROR)).as("parent ERROR").hasMessage("rollback cause");
    assertThat(op.scanUnsafe(Attr.PREFETCH)).as("PREFETCH not supported").isNull();
}
Also used : UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 2 with UsingWhenSubscriber

use of reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber in project reactor-core by reactor.

the class FluxUsingWhenTest method scanCommitInner.

@Test
public void scanCommitInner() {
    CoreSubscriber<? super Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    UsingWhenSubscriber<Integer, String> up = new UsingWhenSubscriber<>(actual, "RESOURCE", Mono::just, (s, err) -> Mono.just(s), Mono::just, null);
    final Subscription parent = Operators.emptySubscription();
    up.onSubscribe(parent);
    FluxUsingWhen.CommitInner op = new FluxUsingWhen.CommitInner(up);
    assertThat(op.scan(Attr.PARENT)).as("PARENT").isSameAs(up);
    assertThat(op.scan(Attr.ACTUAL)).as("ACTUAL").isSameAs(up.actual);
    assertThat(op.scan(Attr.RUN_STYLE)).isSameAs(Attr.RunStyle.SYNC);
    assertThat(op.scan(Attr.TERMINATED)).as("TERMINATED before").isFalse();
    op.onError(new IllegalStateException("boom"));
    assertThat(op.scan(Attr.TERMINATED)).as("TERMINATED by error").isSameAs(up.scan(Attr.TERMINATED)).isTrue();
    assertThat(up.scan(Attr.ERROR)).as("parent ERROR").hasMessage("Async resource cleanup failed after onComplete").hasCause(new IllegalStateException("boom"));
    assertThat(op.scanUnsafe(Attr.PREFETCH)).as("PREFETCH not supported").isNull();
}
Also used : UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 3 with UsingWhenSubscriber

use of reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber in project reactor-core by reactor.

the class FluxUsingWhenTest method scanUsingWhenSubscriber.

@Test
public void scanUsingWhenSubscriber() {
    CoreSubscriber<? super Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    UsingWhenSubscriber<Integer, String> op = new UsingWhenSubscriber<>(actual, "RESOURCE", Mono::just, (s, err) -> Mono.just(s), Mono::just, null);
    final Subscription parent = Operators.emptySubscription();
    op.onSubscribe(parent);
    assertThat(op.scan(Attr.PARENT)).as("PARENT").isSameAs(parent);
    assertThat(op.scan(Attr.ACTUAL)).as("ACTUAL").isSameAs(actual).isSameAs(op.actual());
    assertThat(op.scan(Attr.RUN_STYLE)).isSameAs(Attr.RunStyle.SYNC);
    assertThat(op.scan(Attr.TERMINATED)).as("pre TERMINATED").isFalse();
    assertThat(op.scan(Attr.CANCELLED)).as("pre CANCELLED").isFalse();
    op.deferredError(new IllegalStateException("boom"));
    assertThat(op.scan(Attr.TERMINATED)).as("TERMINATED with error").isTrue();
    assertThat(op.scan(Attr.ERROR)).as("ERROR").hasMessage("boom");
    op.cancel();
    assertThat(op.scan(Attr.CANCELLED)).as("CANCELLED").isTrue();
}
Also used : UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Example 4 with UsingWhenSubscriber

use of reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber in project reactor-core by reactor.

the class FluxUsingWhenTest method scanCancelInner.

@Test
public void scanCancelInner() {
    CoreSubscriber<? super Integer> actual = new LambdaSubscriber<>(null, e -> {
    }, null, null);
    UsingWhenSubscriber<Integer, String> up = new UsingWhenSubscriber<>(actual, "RESOURCE", Mono::just, (s, err) -> Mono.just(s), Mono::just, null);
    final Subscription parent = Operators.emptySubscription();
    up.onSubscribe(parent);
    FluxUsingWhen.CancelInner op = new FluxUsingWhen.CancelInner(up);
    assertThat(op.scan(Attr.PARENT)).as("PARENT").isSameAs(up);
    assertThat(op.scan(Attr.ACTUAL)).as("ACTUAL").isSameAs(up.actual);
    assertThat(op.scanUnsafe(Attr.PREFETCH)).as("PREFETCH not supported").isNull();
    assertThat(op.scan(Attr.RUN_STYLE)).isSameAs(Attr.RunStyle.SYNC);
}
Also used : UsingWhenSubscriber(reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber) Subscription(org.reactivestreams.Subscription) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 Subscription (org.reactivestreams.Subscription)4 UsingWhenSubscriber (reactor.core.publisher.FluxUsingWhen.UsingWhenSubscriber)4