Search in sources :

Example 1 with RxThreadFactory

use of io.reactivex.rxjava3.internal.schedulers.RxThreadFactory in project RxJava by ReactiveX.

the class ExecutorSchedulerFairTest method runnableDisposedAsyncTimed2.

@Test
public void runnableDisposedAsyncTimed2() throws Exception {
    ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
    try {
        final Scheduler s = Schedulers.from(executorScheduler, false, true);
        Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
        while (!d.isDisposed()) {
            Thread.sleep(1);
        }
    } finally {
        executorScheduler.shutdownNow();
    }
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) RxThreadFactory(io.reactivex.rxjava3.internal.schedulers.RxThreadFactory) Test(org.junit.Test)

Example 2 with RxThreadFactory

use of io.reactivex.rxjava3.internal.schedulers.RxThreadFactory in project RxJava by ReactiveX.

the class ExecutorSchedulerInterruptibleTest method runnableDisposedAsyncTimed2.

@Test
public void runnableDisposedAsyncTimed2() throws Exception {
    ExecutorService executorScheduler = Executors.newScheduledThreadPool(1, new RxThreadFactory("TestCustomPoolTimed"));
    try {
        final Scheduler s = Schedulers.from(executorScheduler, true);
        Disposable d = s.scheduleDirect(Functions.EMPTY_RUNNABLE, 1, TimeUnit.MILLISECONDS);
        while (!d.isDisposed()) {
            Thread.sleep(1);
        }
    } finally {
        executorScheduler.shutdownNow();
    }
}
Also used : EmptyDisposable(io.reactivex.rxjava3.internal.disposables.EmptyDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) Scheduler(io.reactivex.rxjava3.core.Scheduler) RxThreadFactory(io.reactivex.rxjava3.internal.schedulers.RxThreadFactory) Test(org.junit.Test)

Example 3 with RxThreadFactory

use of io.reactivex.rxjava3.internal.schedulers.RxThreadFactory in project RxJava by ReactiveX.

the class IoSchedulerInternalTest method expireReuseRace.

@Test
public void expireReuseRace() {
    ConcurrentLinkedQueue<ThreadWorker> expire = new ConcurrentLinkedQueue<>();
    CompositeDisposable cd = new CompositeDisposable();
    ThreadWorker tw = new ThreadWorker(new RxThreadFactory("IoExpiryTest"));
    tw.dispose();
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        expire.add(tw);
        cd.add(tw);
        TestHelper.race(() -> CachedWorkerPool.evictExpiredWorkers(expire, cd), () -> expire.remove(tw));
    }
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 4 with RxThreadFactory

use of io.reactivex.rxjava3.internal.schedulers.RxThreadFactory in project RxJava by ReactiveX.

the class IoSchedulerInternalTest method noExpiredWorker.

@Test
public void noExpiredWorker() {
    ConcurrentLinkedQueue<ThreadWorker> expire = new ConcurrentLinkedQueue<>();
    CompositeDisposable cd = new CompositeDisposable();
    ThreadWorker tw = new ThreadWorker(new RxThreadFactory("IoExpiryTest"));
    tw.setExpirationTime(System.nanoTime() + 10_000_000_000L);
    try {
        expire.add(tw);
        cd.add(tw);
        CachedWorkerPool.evictExpiredWorkers(expire, cd);
        assertFalse(tw.isDisposed());
        assertFalse(expire.isEmpty());
    } finally {
        tw.dispose();
    }
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 5 with RxThreadFactory

use of io.reactivex.rxjava3.internal.schedulers.RxThreadFactory in project RxJava by ReactiveX.

the class IoSchedulerInternalTest method expiredWorkerRemoved.

@Test
public void expiredWorkerRemoved() {
    ConcurrentLinkedQueue<ThreadWorker> expire = new ConcurrentLinkedQueue<>();
    CompositeDisposable cd = new CompositeDisposable();
    ThreadWorker tw = new ThreadWorker(new RxThreadFactory("IoExpiryTest"));
    try {
        expire.add(tw);
        cd.add(tw);
        CachedWorkerPool.evictExpiredWorkers(expire, cd);
        assertTrue(tw.isDisposed());
        assertTrue(expire.isEmpty());
    } finally {
        tw.dispose();
    }
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)3 Scheduler (io.reactivex.rxjava3.core.Scheduler)3 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)3 Disposable (io.reactivex.rxjava3.disposables.Disposable)3 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)3 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)2 RxThreadFactory (io.reactivex.rxjava3.internal.schedulers.RxThreadFactory)2