use of org.reactivestreams.tck.SubscriberWhiteboxVerification.WhiteboxSubscriberProbe in project reactive-streams-jvm by reactive-streams.
the class SubscriberWhiteboxVerificationTest method required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCalledSubscriptionCancel_shouldFail.
@Test
public void required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCalledSubscriptionCancel_shouldFail() throws Throwable {
requireTestFailure(new ThrowingRunnable() {
@Override
public void run() throws Throwable {
customSubscriberVerification(new Function<WhiteboxSubscriberProbe<Integer>, Subscriber<Integer>>() {
@Override
public Subscriber<Integer> apply(WhiteboxSubscriberProbe<Integer> probe) throws Throwable {
final AtomicBoolean subscriptionCancelled = new AtomicBoolean(false);
return new SimpleSubscriberWithProbe(probe) {
@Override
public void onSubscribe(final Subscription s) {
this.subscription = s;
probe.registerOnSubscribe(new SubscriberPuppet() {
@Override
public void triggerRequest(long elements) {
s.request(elements);
}
@Override
public void signalCancel() {
subscriptionCancelled.set(true);
s.cancel();
}
});
}
@Override
public void onNext(Integer element) {
if (subscriptionCancelled.get()) {
// but this test aims to simulate a Subscriber where someone got it's internals wrong and "blows up".
throw new RuntimeException("But I thought it's cancelled!");
} else {
probe.registerOnNext(element);
}
}
};
}
}).required_spec208_mustBePreparedToReceiveOnNextSignalsAfterHavingCalledSubscriptionCancel();
}
}, "But I thought it's cancelled!");
}
Aggregations