use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class FluxCreateTest method gh613.
@Test
public void gh613() {
AtomicBoolean cancelled = new AtomicBoolean();
AtomicBoolean completed = new AtomicBoolean();
AtomicBoolean errored = new AtomicBoolean();
AtomicInteger i = new AtomicInteger();
Flux<Integer> source = Flux.create(e -> {
e.next(1);
cancelled.set(e.isCancelled());
e.next(2);
e.next(3);
e.complete();
});
source.subscribe(new Subscriber<Integer>() {
@Override
public void onSubscribe(Subscription s) {
s.request(Long.MAX_VALUE);
}
@Override
public void onNext(Integer integer) {
i.incrementAndGet();
throw new RuntimeException();
}
@Override
public void onError(Throwable t) {
errored.set(true);
}
@Override
public void onComplete() {
completed.set(true);
}
});
assertThat(cancelled.get()).isTrue();
assertThat(completed.get()).isFalse();
assertThat(errored.get()).isFalse();
assertThat(i.get()).isEqualTo(1);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class FluxDefaultIfEmptyTest method scanSubscriberCancelled.
@Test
public void scanSubscriberCancelled() {
CoreSubscriber<String> actual = new LambdaSubscriber<>(null, e -> {
}, null, null);
FluxDefaultIfEmpty.DefaultIfEmptySubscriber<String> test = new FluxDefaultIfEmpty.DefaultIfEmptySubscriber<>(actual, "bar");
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
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 BlockingIterableTest method scanSubscriber.
@Test
public void scanSubscriber() {
BlockingIterable.SubscriberIterator<String> subscriberIterator = new BlockingIterable.SubscriberIterator<>(Queues.<String>one().get(), 123);
Subscription s = Operators.emptySubscription();
subscriberIterator.onSubscribe(s);
assertThat(subscriberIterator.scan(Scannable.Attr.PARENT)).describedAs("PARENT").isSameAs(s);
assertThat(subscriberIterator.scan(Scannable.Attr.TERMINATED)).describedAs("TERMINATED").isFalse();
assertThat(subscriberIterator.scan(Scannable.Attr.CANCELLED)).describedAs("CANCELLED").isFalse();
assertThat(subscriberIterator.scan(Scannable.Attr.ERROR)).describedAs("ERROR").isNull();
// FIXME
assertThat(subscriberIterator.scan(Attr.PREFETCH)).describedAs("PREFETCH").isEqualTo(123);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class BlockingSingleSubscriberTest method scanMain.
@Test
public void scanMain() {
Subscription s = Operators.emptySubscription();
test.onSubscribe(s);
assertThat(test.scan(Scannable.Attr.PARENT)).describedAs("PARENT").isSameAs(s);
assertThat(test.scan(Scannable.Attr.TERMINATED)).describedAs("TERMINATED").isFalse();
assertThat(test.scan(Scannable.Attr.CANCELLED)).describedAs("CANCELLED").isFalse();
assertThat(test.scan(Scannable.Attr.ERROR)).describedAs("ERROR").isNull();
assertThat(test.scan(Scannable.Attr.PREFETCH)).describedAs("PREFETCH").isEqualTo(Integer.MAX_VALUE);
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class EmitterProcessorTest method scanMain.
@Test
public void scanMain() {
EmitterProcessor<Integer> test = EmitterProcessor.create(123);
assertThat(test.scan(BUFFERED)).isEqualTo(0);
assertThat(test.scan(CANCELLED)).isFalse();
assertThat(test.scan(PREFETCH)).isEqualTo(123);
assertThat(test.scan(CAPACITY)).isEqualTo(123);
Disposable d1 = test.subscribe();
FluxSink<Integer> sink = test.sink();
sink.next(2);
sink.next(3);
sink.next(4);
assertThat(test.scan(BUFFERED)).isEqualTo(0);
AtomicReference<Subscription> d2 = new AtomicReference<>();
test.subscribe(new CoreSubscriber<Integer>() {
@Override
public void onSubscribe(Subscription s) {
d2.set(s);
}
@Override
public void onNext(Integer integer) {
}
@Override
public void onError(Throwable t) {
}
@Override
public void onComplete() {
}
});
sink.next(5);
sink.next(6);
sink.next(7);
assertThat(test.scan(BUFFERED)).isEqualTo(3);
assertThat(test.scan(TERMINATED)).isFalse();
sink.complete();
assertThat(test.scan(TERMINATED)).isFalse();
d1.dispose();
d2.get().cancel();
assertThat(test.scan(TERMINATED)).isTrue();
// other values
assertThat(test.scan(Scannable.Attr.PARENT)).isNotNull();
assertThat(test.scan(Attr.ERROR)).isNull();
}
Aggregations