@Test public void testCancelledSubscriber() { Subscriptions.CancelledSubscriber<Integer> subscriber = new Subscriptions.CancelledSubscriber<>(); Subscription subscription = mock(Subscription.class); subscriber.onSubscribe(subscription); verify(subscription).cancel(); verify(subscription, never()).request(anyLong()); subscriber.onNext(1); subscriber.onComplete(); subscriber.onError(new Exception("boom")); assertThatThrownBy(() -> subscriber.onSubscribe(null)) .isInstanceOf(NullPointerException.class); }
public static void cancel(AtomicReference<Subscription> reference) { Subscription actual = reference.getAndSet(CANCELLED); if (actual != null && actual != CANCELLED) { actual.cancel(); } }
Subscriptions { public static void cancel(AtomicReference<Subscription> reference) { Subscription actual = reference.getAndSet(CANCELLED); if (actual != null && actual != CANCELLED) { actual.cancel(); } } }
Subscriptions { public static void cancel(AtomicReference<Subscription> reference) { Subscription actual = reference.getAndSet(CANCELLED); if (actual != null && actual != CANCELLED) { actual.cancel(); } } private  Subscriptions(); }
Subscriptions { public static void cancel(AtomicReference<Subscription> reference) { Subscription actual = reference.getAndSet(CANCELLED); if (actual != null && actual != CANCELLED) { actual.cancel(); } } private  Subscriptions(); static IllegalArgumentException getInvalidRequestException(); static Subscription empty(); static void complete(Subscriber<?> subscriber); static void fail(Subscriber<?> subscriber, Throwable failure); static void fail(Subscriber<?> subscriber, Throwable failure, Publisher<?> upstream); static long add(long a, long b); static long add(AtomicLong requested, long requests); static long subtract(AtomicLong requested, long emitted); static int unboundedOrLimit(int prefetch); static long unboundedOrRequests(int concurrency); static boolean addFailure(AtomicReference<Throwable> failures, Throwable failure); static void cancel(AtomicReference<Subscription> reference); static Throwable markFailureAsTerminated(AtomicReference<Throwable> failures); static void terminateAndPropagate(AtomicReference<Throwable> failures, Subscriber<?> subscriber); static long multiply(long n, long times); static void requestIfNotNullOrAccumulate(AtomicReference<Subscription> field, AtomicLong requested, long requests); static boolean setIfEmptyAndRequest(AtomicReference<Subscription> container, AtomicLong requested,
            Subscription subscription); static boolean setIfEmpty(AtomicReference<Subscription> container, Subscription subscription); static Throwable terminate(AtomicReference<Throwable> failure); static long produced(AtomicLong requested, long amount); static long subOrZero(long a, long b); static SingleItemSubscription<T> single(Subscriber<T> downstream, T item); static long producedAndHandleAlreadyCancelled(AtomicLong requested, long n); static long addAndHandledAlreadyCancelled(AtomicLong requested, long n); }
Subscriptions { public static void cancel(AtomicReference<Subscription> reference) { Subscription actual = reference.getAndSet(CANCELLED); if (actual != null && actual != CANCELLED) { actual.cancel(); } } private  Subscriptions(); static IllegalArgumentException getInvalidRequestException(); static Subscription empty(); static void complete(Subscriber<?> subscriber); static void fail(Subscriber<?> subscriber, Throwable failure); static void fail(Subscriber<?> subscriber, Throwable failure, Publisher<?> upstream); static long add(long a, long b); static long add(AtomicLong requested, long requests); static long subtract(AtomicLong requested, long emitted); static int unboundedOrLimit(int prefetch); static long unboundedOrRequests(int concurrency); static boolean addFailure(AtomicReference<Throwable> failures, Throwable failure); static void cancel(AtomicReference<Subscription> reference); static Throwable markFailureAsTerminated(AtomicReference<Throwable> failures); static void terminateAndPropagate(AtomicReference<Throwable> failures, Subscriber<?> subscriber); static long multiply(long n, long times); static void requestIfNotNullOrAccumulate(AtomicReference<Subscription> field, AtomicLong requested, long requests); static boolean setIfEmptyAndRequest(AtomicReference<Subscription> container, AtomicLong requested,
            Subscription subscription); static boolean setIfEmpty(AtomicReference<Subscription> container, Subscription subscription); static Throwable terminate(AtomicReference<Throwable> failure); static long produced(AtomicLong requested, long amount); static long subOrZero(long a, long b); static SingleItemSubscription<T> single(Subscriber<T> downstream, T item); static long producedAndHandleAlreadyCancelled(AtomicLong requested, long n); static long addAndHandledAlreadyCancelled(AtomicLong requested, long n); static final Throwable TERMINATED; static final EmptySubscription CANCELLED; }