Search in sources :

Example 11 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.

the class IoSchedulerInternalTest method expiredQueueEmpty.

@Test
public void expiredQueueEmpty() {
    ConcurrentLinkedQueue<ThreadWorker> expire = new ConcurrentLinkedQueue<>();
    CompositeDisposable cd = new CompositeDisposable();
    CachedWorkerPool.evictExpiredWorkers(expire, cd);
}
Also used : ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 12 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable 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 13 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.

the class SchedulerMultiWorkerSupportTest method distinctThreads.

@Test
public void distinctThreads() throws Exception {
    for (int i = 0; i < TestHelper.RACE_DEFAULT_LOOPS; i++) {
        final CompositeDisposable composite = new CompositeDisposable();
        try {
            final CountDownLatch cdl = new CountDownLatch(max * 2);
            final Set<String> threads1 = Collections.synchronizedSet(new HashSet<>());
            final Set<String> threads2 = Collections.synchronizedSet(new HashSet<>());
            Runnable parallel1 = new Runnable() {

                @Override
                public void run() {
                    final List<Worker> list1 = new ArrayList<>();
                    SchedulerMultiWorkerSupport mws = (SchedulerMultiWorkerSupport) Schedulers.computation();
                    mws.createWorkers(max, new WorkerCallback() {

                        @Override
                        public void onWorker(int i, Worker w) {
                            list1.add(w);
                            composite.add(w);
                        }
                    });
                    Runnable run = new Runnable() {

                        @Override
                        public void run() {
                            threads1.add(Thread.currentThread().getName());
                            cdl.countDown();
                        }
                    };
                    for (Worker w : list1) {
                        w.schedule(run);
                    }
                }
            };
            Runnable parallel2 = new Runnable() {

                @Override
                public void run() {
                    final List<Worker> list2 = new ArrayList<>();
                    SchedulerMultiWorkerSupport mws = (SchedulerMultiWorkerSupport) Schedulers.computation();
                    mws.createWorkers(max, new WorkerCallback() {

                        @Override
                        public void onWorker(int i, Worker w) {
                            list2.add(w);
                            composite.add(w);
                        }
                    });
                    Runnable run = new Runnable() {

                        @Override
                        public void run() {
                            threads2.add(Thread.currentThread().getName());
                            cdl.countDown();
                        }
                    };
                    for (Worker w : list2) {
                        w.schedule(run);
                    }
                }
            };
            TestHelper.race(parallel1, parallel2);
            assertTrue(cdl.await(5, TimeUnit.SECONDS));
            assertEquals(threads1.toString(), max, threads1.size());
            assertEquals(threads2.toString(), max, threads2.size());
        } finally {
            composite.dispose();
        }
    }
}
Also used : WorkerCallback(io.reactivex.rxjava3.internal.schedulers.SchedulerMultiWorkerSupport.WorkerCallback) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 14 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.

the class ScheduledRunnableTest method dispose.

@Test
public void dispose() {
    CompositeDisposable set = new CompositeDisposable();
    ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
    set.add(run);
    assertFalse(run.isDisposed());
    set.dispose();
    assertTrue(run.isDisposed());
}
Also used : CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 15 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable in project RxJava by ReactiveX.

the class ScheduledRunnableTest method withParentIsDisposed.

@Test
public void withParentIsDisposed() {
    CompositeDisposable set = new CompositeDisposable();
    ScheduledRunnable run = new ScheduledRunnable(Functions.EMPTY_RUNNABLE, set);
    set.add(run);
    assertFalse(run.isDisposed());
    run.run();
    assertTrue(run.isDisposed());
    assertFalse(set.remove(run));
}
Also used : CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)28 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)24 CompositeDisposable (io.reactivex.rxjava3.disposables.CompositeDisposable)24 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)4 Disposable (io.reactivex.rxjava3.disposables.Disposable)4 TestException (io.reactivex.rxjava3.exceptions.TestException)4 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)4 FutureTask (java.util.concurrent.FutureTask)4 WebSocketUnavailableException (org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException)4 AtomicThrowable (io.reactivex.rxjava3.internal.util.AtomicThrowable)2 TestObserver (io.reactivex.rxjava3.observers.TestObserver)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Scheduler (io.reactivex.rxjava3.core.Scheduler)1 CompositeException (io.reactivex.rxjava3.exceptions.CompositeException)1 Amb (io.reactivex.rxjava3.internal.operators.completable.CompletableAmb.Amb)1 TimeOutObserver (io.reactivex.rxjava3.internal.operators.completable.CompletableTimeout.TimeOutObserver)1 NewThreadWorker (io.reactivex.rxjava3.internal.schedulers.NewThreadWorker)1 WorkerCallback (io.reactivex.rxjava3.internal.schedulers.SchedulerMultiWorkerSupport.WorkerCallback)1