Search in sources :

Example 96 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class MonoFlatMapTest method scanMain.

@Test
public void scanMain() {
    CoreSubscriber<Integer> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoFlatMap.FlatMapMain<String, Integer> test = new MonoFlatMap.FlatMapMain<>(actual, s -> Mono.just(s.length()));
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 97 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class MonoFlatMapTest method scanInner.

@Test
public void scanInner() {
    CoreSubscriber<Integer> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoFlatMap.FlatMapMain<String, Integer> main = new MonoFlatMap.FlatMapMain<>(actual, s -> Mono.just(s.length()));
    MonoFlatMap.FlatMapInner<Integer> test = new MonoFlatMap.FlatMapInner<>(main);
    Subscription innerSubscription = Operators.emptySubscription();
    test.onSubscribe(innerSubscription);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    test.onError(new IllegalStateException("boom"));
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.cancel();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 98 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class MonoHasElementsTest method scanHasElements.

@Test
public void scanHasElements() {
    CoreSubscriber<? super Boolean> actual = new LambdaMonoSubscriber<>(null, e -> {
    }, null, null);
    MonoHasElements.HasElementsSubscriber<String> test = new MonoHasElements.HasElementsSubscriber<>(actual);
    Subscription parent = Operators.emptySubscription();
    test.onSubscribe(parent);
    assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
    assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
    assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
    test.onComplete();
    assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
    assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
}
Also used : Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 99 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class MonoHasElementsTest method hasElementCancel.

@Test
public void hasElementCancel() throws InterruptedException {
    AtomicBoolean cancelled = new AtomicBoolean();
    Mono.just("foo").hide().doOnCancel(() -> cancelled.set(true)).log().hasElement().subscribe(v -> {
    }, e -> {
    }, () -> {
    }, Subscription::cancel);
    assertThat(cancelled.get()).isTrue();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Example 100 with Subscription

use of org.reactivestreams.Subscription in project reactor-core by reactor.

the class MonoSequenceEqualTest method doubleCancelCancelsOnce.

@Test
public void doubleCancelCancelsOnce() {
    AtomicReference<Subscription> sub1 = new AtomicReference<>();
    AtomicReference<Subscription> sub2 = new AtomicReference<>();
    AtomicLong cancel1 = new AtomicLong();
    AtomicLong cancel2 = new AtomicLong();
    Flux<Integer> source1 = Flux.range(1, 5).doOnSubscribe(sub1::set).doOnCancel(cancel1::incrementAndGet).hide();
    Flux<Integer> source2 = Flux.just(1, 2, 3, 7, 8).doOnSubscribe(sub2::set).doOnCancel(cancel2::incrementAndGet).hide();
    Mono.sequenceEqual(source1, source2).subscribe(System.out::println, Throwable::printStackTrace, null, s -> {
        s.cancel();
        s.cancel();
    });
    Assert.assertNotNull("left not subscribed", sub1.get());
    assertThat(cancel1.get()).isEqualTo(1);
    Assert.assertNotNull("right not subscribed", sub2.get());
    assertThat(cancel2.get()).isEqualTo(1);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicReference(java.util.concurrent.atomic.AtomicReference) Subscription(org.reactivestreams.Subscription) Test(org.junit.Test)

Aggregations

Subscription (org.reactivestreams.Subscription)627 Test (org.junit.Test)506 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)158 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)131 ArrayList (java.util.ArrayList)117 AtomicReference (java.util.concurrent.atomic.AtomicReference)105 List (java.util.List)80 FluxOperatorTest (reactor.test.publisher.FluxOperatorTest)74 Subscriber (org.reactivestreams.Subscriber)68 AtomicLong (java.util.concurrent.atomic.AtomicLong)56 Assert (org.junit.Assert)56 Arrays (java.util.Arrays)43 BaseSequentialTest (com.oath.cyclops.streams.BaseSequentialTest)42 Vector (cyclops.data.Vector)39 ReactiveSeq (cyclops.reactive.ReactiveSeq)39 Executor (java.util.concurrent.Executor)38 Spouts (cyclops.reactive.Spouts)36 Arrays.asList (java.util.Arrays.asList)36 Executors (java.util.concurrent.Executors)35 StepVerifier (reactor.test.StepVerifier)34