Search in sources :

Example 21 with CompositeDisposable

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

the class ScheduledRunnableTest method disposeRun.

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

Example 22 with CompositeDisposable

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

the class ScheduledRunnableTest method disposeRace.

@Test
public void disposeRace() {
    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.dispose();
            }
        };
        TestHelper.race(r1, r1);
        assertEquals(0, set.size());
    }
}
Also used : CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) RxJavaTest(io.reactivex.rxjava3.core.RxJavaTest) Test(org.junit.Test)

Example 23 with CompositeDisposable

use of io.reactivex.rxjava3.disposables.CompositeDisposable in project Signal-Android by signalapp.

the class SignalWebSocket method getUnidentifiedWebSocket.

private synchronized WebSocketConnection getUnidentifiedWebSocket() throws WebSocketUnavailableException {
    if (!canConnect) {
        throw new WebSocketUnavailableException();
    }
    if (unidentifiedWebSocket == null || unidentifiedWebSocket.isDead()) {
        unidentifiedWebSocketStateDisposable.dispose();
        unidentifiedWebSocket = webSocketFactory.createUnidentifiedWebSocket();
        unidentifiedWebSocketStateDisposable = new CompositeDisposable();
        Disposable state = unidentifiedWebSocket.connect().subscribeOn(Schedulers.computation()).observeOn(Schedulers.computation()).subscribe(unidentifiedWebSocketState::onNext);
        unidentifiedWebSocketStateDisposable.add(state);
    }
    return unidentifiedWebSocket;
}
Also used : CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) WebSocketUnavailableException(org.whispersystems.signalservice.api.websocket.WebSocketUnavailableException) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable)

Example 24 with CompositeDisposable

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

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