use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method runnableDisposedAsyncCrash.
@Test
public void runnableDisposedAsyncCrash() throws Exception {
final Scheduler s = Schedulers.from(new Executor() {
@Override
public void execute(Runnable r) {
new Thread(r).start();
}
});
Disposable d = s.scheduleDirect(new Runnable() {
@Override
public void run() {
throw new IllegalStateException();
}
});
while (!d.isDisposed()) {
Thread.sleep(1);
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method interruptibleRunnableRunDispose.
@Test
public void interruptibleRunnableRunDispose() {
try {
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
AtomicReference<Runnable> runRef = new AtomicReference<>();
Scheduler s = Schedulers.from(r -> {
runRef.set(r);
}, true);
Disposable d = s.scheduleDirect(() -> {
});
TestHelper.race(() -> runRef.get().run(), () -> d.dispose());
}
} finally {
Thread.interrupted();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method disposeRace.
@Test
public void disposeRace() {
ExecutorService exec = Executors.newSingleThreadExecutor();
final Scheduler s = Schedulers.from(exec);
try {
for (int i = 0; i < 500; i++) {
final Worker w = s.createWorker();
final AtomicInteger c = new AtomicInteger(2);
w.schedule(new Runnable() {
@Override
public void run() {
c.decrementAndGet();
while (c.get() != 0) {
}
}
});
c.decrementAndGet();
while (c.get() != 0) {
}
w.dispose();
}
} finally {
exec.shutdownNow();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerTest method interruptibleRunnableRunDisposeRace.
@Test
public void interruptibleRunnableRunDisposeRace() {
ExecutorService exec = Executors.newSingleThreadExecutor();
try {
Scheduler s = Schedulers.from(r -> exec.execute(r), true);
for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
SequentialDisposable sd = new SequentialDisposable();
TestHelper.race(() -> sd.update(s.scheduleDirect(() -> {
})), () -> sd.dispose());
}
} finally {
exec.shutdown();
}
}
use of io.reactivex.rxjava3.core.Scheduler in project RxJava by ReactiveX.
the class ExecutorSchedulerInterruptibleTest method nonInterruptibleDirectTaskScheduledExecutorTimed.
@Test
public void nonInterruptibleDirectTaskScheduledExecutorTimed() throws Exception {
ScheduledExecutorService exec = Executors.newScheduledThreadPool(1);
try {
Scheduler scheduler = Schedulers.from(exec, false);
final AtomicInteger sync = new AtomicInteger(2);
final AtomicBoolean isInterrupted = new AtomicBoolean();
Disposable d = scheduler.scheduleDirect(new Runnable() {
@Override
public void run() {
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
isInterrupted.set(true);
}
}
}, 1, TimeUnit.MILLISECONDS);
if (sync.decrementAndGet() != 0) {
while (sync.get() != 0) {
}
}
Thread.sleep(500);
d.dispose();
int i = 20;
while (i-- > 0 && !isInterrupted.get()) {
Thread.sleep(50);
}
assertFalse("Interruption happened", isInterrupted.get());
} finally {
exec.shutdown();
}
}
Aggregations