use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoCreateTest method cancellation.
@Test
public void cancellation() {
AtomicInteger onDispose = new AtomicInteger();
AtomicInteger onCancel = new AtomicInteger();
StepVerifier.create(Mono.create(s -> {
s.onDispose(onDispose::getAndIncrement).onCancel(onCancel::getAndIncrement);
})).thenAwait().consumeSubscriptionWith(Subscription::cancel).thenCancel().verify();
assertThat(onDispose.get()).isEqualTo(1);
assertThat(onCancel.get()).isEqualTo(1);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoFilterWhenTest method take1Cancel.
@Test
public void take1Cancel() {
AtomicLong onNextCount = new AtomicLong();
AtomicReference<SignalType> endSignal = new AtomicReference<>();
BaseSubscriber<Object> bs = new BaseSubscriber<Object>() {
@Override
protected void hookOnSubscribe(Subscription subscription) {
requestUnbounded();
}
@Override
public void hookOnNext(Object t) {
onNextCount.incrementAndGet();
cancel();
onComplete();
}
@Override
protected void hookFinally(SignalType type) {
endSignal.set(type);
}
};
Mono.just(1).filterWhen(v -> Mono.just(true).hide()).subscribe(bs);
assertThat(onNextCount.get()).isEqualTo(1);
assertThat(endSignal.get()).isEqualTo(SignalType.CANCEL);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoFilterWhenTest method take1CancelBackpressured.
@Test
public void take1CancelBackpressured() {
AtomicLong onNextCount = new AtomicLong();
AtomicReference<SignalType> endSignal = new AtomicReference<>();
BaseSubscriber<Object> bs = new BaseSubscriber<Object>() {
@Override
protected void hookOnSubscribe(Subscription subscription) {
request(1);
}
@Override
public void hookOnNext(Object t) {
onNextCount.incrementAndGet();
cancel();
onComplete();
}
@Override
protected void hookFinally(SignalType type) {
endSignal.set(type);
}
};
Mono.just(1).filterWhen(v -> Mono.just(true).hide()).subscribe(bs);
assertThat(onNextCount.get()).isEqualTo(1);
assertThat(endSignal.get()).isEqualTo(SignalType.CANCEL);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoFilterWhenTest method scanFilterWhenInner.
@Test
public void scanFilterWhenInner() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoFilterWhen.MonoFilterWhenMain<String> main = new MonoFilterWhen.MonoFilterWhenMain<>(actual, s -> Mono.just(false));
MonoFilterWhen.FilterWhenInner test = new MonoFilterWhen.FilterWhenInner(main, true);
Subscription innerSubscription = Operators.emptySubscription();
test.onSubscribe(innerSubscription);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(1L);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(0L);
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 MonoFlatMapManyTest method scanInner.
@Test
public void scanInner() {
CoreSubscriber<Integer> mainActual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
CoreSubscriber<Integer> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoFlatMapMany.FlatMapManyMain<String, Integer> main = new MonoFlatMapMany.FlatMapManyMain<>(mainActual, s -> Flux.just(1, 2, 3));
MonoFlatMapMany.FlatMapManyInner<Integer> test = new MonoFlatMapMany.FlatMapManyInner<>(main, actual);
Subscription innerSubscription = Operators.emptySubscription();
test.onSubscribe(innerSubscription);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(innerSubscription);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
main.requested = 3L;
assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(3L);
}
Aggregations