ArrayCompositeSubscription extends AtomicReferenceArray<Subscription> implements Disposable { @Override public void dispose() { if (get(0) != SubscriptionHelper.CANCELLED) { int s = length(); for (int i = 0; i < s; i++) { Subscription o = get(i); if (o != SubscriptionHelper.CANCELLED) { o = getAndSet(i, SubscriptionHelper.CANCELLED); if (o != SubscriptionHelper.CANCELLED && o != null) { o.cancel(); } } } } } ArrayCompositeSubscription(int capacity); boolean setResource(int index, Subscription resource); Subscription replaceResource(int index, Subscription resource); @Override void dispose(); @Override boolean isDisposed();  }
@Test public void disposeRace() { for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) { final ArrayCompositeSubscription ac = new ArrayCompositeSubscription(1000); Runnable r = new Runnable() { @Override public void run() { ac.dispose(); } }; TestHelper.race(r, r); } }