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();
}
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();
}
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();
}
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();
}
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);
}
Aggregations