use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoCollectListTest method scanBufferAllSubscriber.
@Test
public void scanBufferAllSubscriber() {
CoreSubscriber<List<String>> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoCollectList.MonoBufferAllSubscriber<String, List<String>> test = new MonoCollectList.MonoBufferAllSubscriber<String, List<String>>(actual, new ArrayList<>());
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 MonoDelayUntilTest method scanTrigger.
@Test
public void scanTrigger() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
@SuppressWarnings("unchecked") Function<? super String, ? extends Publisher<?>>[] otherGenerators = new Function[3];
MonoDelayUntil.DelayUntilCoordinator<String> main = new MonoDelayUntil.DelayUntilCoordinator<>(actual, otherGenerators);
MonoDelayUntil.DelayUntilTrigger<String> test = new MonoDelayUntil.DelayUntilTrigger<>(main);
Subscription subscription = Operators.emptySubscription();
test.onSubscribe(subscription);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(subscription);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(main);
assertThat(test.scan(Scannable.Attr.PREFETCH)).isEqualTo(Integer.MAX_VALUE);
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
test.error = new IllegalStateException("boom");
assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class MonoElementAtTest method scanSubscriber.
@Test
public void scanSubscriber() {
CoreSubscriber<String> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoElementAt.ElementAtSubscriber<String> test = new MonoElementAt.ElementAtSubscriber<>(actual, 1, "foo");
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 MonoCountTest method scanCountSubscriber.
@Test
public void scanCountSubscriber() {
CoreSubscriber<Long> actual = new LambdaMonoSubscriber<>(null, e -> {
}, null, null);
MonoCount.CountSubscriber<String> test = new MonoCount.CountSubscriber<>(actual);
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);
// only TERMINATED state evaluated is one from Operators: hasValue
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
test.onComplete();
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 MonoCreateTest method monoCreateCancelOnNext.
@Test
public void monoCreateCancelOnNext() {
AtomicInteger onCancel = new AtomicInteger();
AtomicInteger onDispose = new AtomicInteger();
AtomicReference<Subscription> subscription = new AtomicReference<>();
Mono<String> created = Mono.create(s -> {
s.onDispose(onDispose::getAndIncrement).onCancel(onCancel::getAndIncrement).success("done");
});
created = created.doOnSubscribe(s -> subscription.set(s)).doOnNext(n -> subscription.get().cancel());
StepVerifier.create(created).expectNext("done").verifyComplete();
assertThat(onDispose.get()).isEqualTo(1);
assertThat(onCancel.get()).isEqualTo(0);
}
Aggregations