use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method syncWorkerCancelRace.
@Test
public void syncWorkerCancelRace() {
for (int i = 0; i < TestHelper.RACE_LONG_LOOPS; i++) {
final CompositeDisposable set = new CompositeDisposable();
final AtomicBoolean interrupted = new AtomicBoolean();
final AtomicInteger sync = new AtomicInteger(2);
final AtomicInteger syncb = new AtomicInteger(2);
Runnable r0 = new Runnable() {
@Override
public void run() {
set.dispose();
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
if (syncb.decrementAndGet() != 0) {
while (syncb.get() != 0) {
}
}
for (int j = 0; j < 1000; j++) {
if (Thread.currentThread().isInterrupted()) {
interrupted.set(true);
break;
}
}
}
};
final ScheduledRunnable run = new ScheduledRunnable(r0, set);
set.add(run);
final FutureTask<Void> ft = new FutureTask<>(run, null);
Runnable r2 = new Runnable() {
@Override
public void run() {
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
run.setFuture(ft);
if (syncb.decrementAndGet() != 0) {
while (syncb.get() != 0) {
}
}
}
};
TestHelper.race(ft, r2);
assertFalse("The task was interrupted", interrupted.get());
}
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method runDispose.
@Test
public void runDispose() {
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);
Runnable r1 = new Runnable() {
@Override
public void run() {
run.call();
}
};
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 setFutureRunRace.
@Test
public void setFutureRunRace() {
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.run();
}
};
TestHelper.race(r1, r2);
assertEquals(0, set.size());
}
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method pluginCrash.
@Test
public void pluginCrash() {
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
throw new TestException("Second");
}
});
CompositeDisposable set = new CompositeDisposable();
final ScheduledRunnable run = new ScheduledRunnable(new Runnable() {
@Override
public void run() {
throw new TestException("First");
}
}, set);
set.add(run);
try {
run.run();
fail("Should have thrown!");
} catch (TestException ex) {
assertEquals("Second", ex.getMessage());
} finally {
Thread.currentThread().setUncaughtExceptionHandler(null);
}
assertTrue(run.isDisposed());
assertEquals(0, set.size());
}
use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.
the class ScheduledRunnableTest method crashReported.
@Test
public void crashReported() {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
CompositeDisposable set = new CompositeDisposable();
final ScheduledRunnable run = new ScheduledRunnable(new Runnable() {
@Override
public void run() {
throw new TestException("First");
}
}, set);
set.add(run);
try {
run.run();
fail("Should have thrown!");
} catch (TestException expected) {
// expected
}
assertTrue(run.isDisposed());
assertEquals(0, set.size());
TestHelper.assertUndeliverable(errors, 0, TestException.class, "First");
} finally {
RxJavaPlugins.reset();
}
}
Aggregations