use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method runFuture.
@Test
public void runFuture() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
CompositeDisposable set = new CompositeDisposable();
final ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
set.add(run);
final FutureTask<Void> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, null);
Runnable r1 = new Runnable() {
@Override
public void run() {
run.call();
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
run.setFuture(ft);
}
};
TestHelper.race(r1, r2);
}
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method setFutureCancelRace.
@Test
public void setFutureCancelRace() {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
CompositeDisposable set = new CompositeDisposable();
final ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
set.add(run);
final FutureTask<Object> ft = new FutureTask<>(Functions.EMPTY_RUNNABLE, 0);
Runnable r1 = new Runnable() {
@Override
public void run() {
run.setFuture(ft);
}
};
Runnable r2 = new Runnable() {
@Override
public void run() {
run.dispose();
}
};
TestHelper.race(r1, r2);
assertEquals(0, set.size());
}
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method toStringStates.
@Test
public void toStringStates() {
CompositeDisposable set = new CompositeDisposable();
ScheduledRunnable task = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
assertEquals("ScheduledRunnable[Waiting]", task.toString());
task.set(ScheduledRunnable.THREAD_INDEX, Thread.currentThread());
assertEquals("ScheduledRunnable[Running on " + Thread.currentThread() + "]", task.toString());
task.dispose();
assertEquals("ScheduledRunnable[Disposed(Sync)]", task.toString());
task.set(ScheduledRunnable.FUTURE_INDEX, ScheduledRunnable.DONE);
assertEquals("ScheduledRunnable[Finished]", task.toString());
task = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
task.dispose();
assertEquals("ScheduledRunnable[Disposed(Async)]", task.toString());
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method withParentDisposed.
@Test
public void withParentDisposed() {
ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, new CompositeDisposable());
run.dispose();
run.call();
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class CompositeDisposableTest method unsubscribeIdempotenceConcurrently.
@Test
public void unsubscribeIdempotenceConcurrently() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
final CompositeDisposable cd = new CompositeDisposable();
final int count = 10;
final CountDownLatch start = new CountDownLatch(1);
cd.add(Disposable.fromRunnable(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
}
}));
final List<Thread> threads = new ArrayList<>();
for (int i = 0; i < count; i++) {
final Thread t = new Thread() {
@Override
public void run() {
try {
start.await();
cd.dispose();
} catch (final InterruptedException e) {
fail(e.getMessage());
}
}
};
t.start();
threads.add(t);
}
start.countDown();
for (final Thread t : threads) {
t.join();
}
// we should have only disposed once
assertEquals(1, counter.get());
}
Aggregations