use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class StrictSubscriberTest method requestDelayed.
@Test
public void requestDelayed() {
AtomicBoolean state = new AtomicBoolean();
AtomicReference<Throwable> e = new AtomicReference<>();
Flux.just(1).subscribe(new Subscriber<Integer>() {
boolean open;
@Override
public void onSubscribe(Subscription s) {
s.request(1);
open = true;
}
@Override
public void onNext(Integer t) {
state.set(open);
}
@Override
public void onError(Throwable t) {
e.set(t);
}
@Override
public void onComplete() {
}
});
Assert.assertNull("Error: " + e.get(), e.get());
Assert.assertTrue("Not open!", state.get());
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class StrictSubscriberTest method requestNotDelayed.
@Test
public void requestNotDelayed() {
AtomicBoolean state = new AtomicBoolean();
AtomicReference<Throwable> e = new AtomicReference<>();
Flux.just(1).subscribe(new CoreSubscriber<Integer>() {
boolean open;
@Override
public void onSubscribe(Subscription s) {
s.request(1);
open = true;
}
@Override
public void onNext(Integer t) {
state.set(open);
}
@Override
public void onError(Throwable t) {
e.set(t);
}
@Override
public void onComplete() {
}
});
Assert.assertNull("Error: " + e.get(), e.get());
Assert.assertFalse("Request delayed!", state.get());
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class TopicProcessorTest method scanProcessor.
@Test
public void scanProcessor() {
TopicProcessor<String> test = TopicProcessor.create("name", 16);
Subscription subscription = Operators.emptySubscription();
test.onSubscribe(subscription);
assertThat(test.scan(Scannable.Attr.PARENT)).isEqualTo(subscription);
assertThat(test.scan(Scannable.Attr.CAPACITY)).isEqualTo(16);
assertThat(test.scan(Scannable.Attr.TERMINATED)).isFalse();
assertThat(test.scan(Scannable.Attr.ERROR)).isNull();
test.onError(new IllegalStateException("boom"));
assertThat(test.scan(Scannable.Attr.ERROR)).hasMessage("boom");
assertThat(test.scan(Scannable.Attr.TERMINATED)).isTrue();
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class OperatorsTest method drainSubscriber.
@Test
public void drainSubscriber() {
AtomicBoolean requested = new AtomicBoolean();
AtomicBoolean errored = new AtomicBoolean();
try {
Hooks.onErrorDropped(e -> {
assertThat(Exceptions.isErrorCallbackNotImplemented(e)).isTrue();
assertThat(e.getCause()).hasMessage("test");
errored.set(true);
});
Flux.from(s -> {
assertThat(s).isEqualTo(Operators.drainSubscriber());
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
assertThat(n).isEqualTo(Long.MAX_VALUE);
requested.set(true);
}
@Override
public void cancel() {
}
});
// dropped
s.onNext("ignored");
// dropped
s.onComplete();
s.onError(new Exception("test"));
}).subscribe(Operators.drainSubscriber());
assertThat(requested.get()).isTrue();
assertThat(errored.get()).isTrue();
} finally {
Hooks.resetOnErrorDropped();
}
}
use of org.reactivestreams.Subscription in project reactor-core by reactor.
the class OperatorsTest method scanMultiSubscriptionSubscriber.
@Test
public void scanMultiSubscriptionSubscriber() {
CoreSubscriber<Integer> actual = new LambdaSubscriber<>(null, null, null, null);
MultiSubscriptionSubscriber<Integer, Integer> test = new MultiSubscriptionSubscriber<Integer, Integer>(actual) {
@Override
public void onNext(Integer t) {
}
};
Subscription parent = Operators.emptySubscription();
test.onSubscribe(parent);
assertThat(test.scan(Scannable.Attr.ACTUAL)).isSameAs(actual);
assertThat(test.scan(Scannable.Attr.PARENT)).isSameAs(parent);
test.request(34);
assertThat(test.scan(Scannable.Attr.REQUESTED_FROM_DOWNSTREAM)).isEqualTo(34);
assertThat(test.scan(Scannable.Attr.CANCELLED)).isFalse();
test.cancel();
assertThat(test.scan(Scannable.Attr.CANCELLED)).isTrue();
}
Aggregations