Search in sources :

Example 1 with WhiteboxSubscriberProbe

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!");
}
Also used : SubscriberPuppet(org.reactivestreams.tck.SubscriberWhiteboxVerification.SubscriberPuppet) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) WhiteboxSubscriberProbe(org.reactivestreams.tck.SubscriberWhiteboxVerification.WhiteboxSubscriberProbe) Subscriber(org.reactivestreams.Subscriber) Subscription(org.reactivestreams.Subscription) Test(org.testng.annotations.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Subscriber (org.reactivestreams.Subscriber)1 Subscription (org.reactivestreams.Subscription)1 SubscriberPuppet (org.reactivestreams.tck.SubscriberWhiteboxVerification.SubscriberPuppet)1 WhiteboxSubscriberProbe (org.reactivestreams.tck.SubscriberWhiteboxVerification.WhiteboxSubscriberProbe)1 Test (org.testng.annotations.Test)1