Search in sources :

Example 1 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project redisson by redisson.

the class RedissonRemoteServiceTest method testCancelReactive.

@Test
public void testCancelReactive() throws InterruptedException {
    RedissonReactiveClient r1 = Redisson.create(createConfig()).reactive();
    AtomicInteger iterations = new AtomicInteger();
    ExecutorService executor = Executors.newSingleThreadExecutor();
    r1.getKeys().flushall();
    r1.getRemoteService().register(RemoteInterface.class, new RemoteImpl(iterations), 1, executor);
    RedissonReactiveClient r2 = Redisson.create(createConfig()).reactive();
    RemoteInterfaceReactive ri = r2.getRemoteService().get(RemoteInterfaceReactive.class);
    Mono<Void> f = ri.cancelMethod();
    Disposable t = f.doOnSubscribe(s -> s.request(1)).subscribe();
    Thread.sleep(500);
    t.dispose();
    executor.shutdown();
    r1.shutdown();
    r2.shutdown();
    assertThat(iterations.get()).isLessThan(Integer.MAX_VALUE / 2);
    assertThat(executor.awaitTermination(2, TimeUnit.SECONDS)).isTrue();
}
Also used : Disposable(reactor.core.Disposable) RemoteServiceTimeoutException(org.redisson.remote.RemoteServiceTimeoutException) Single(io.reactivex.rxjava3.core.Single) Disposable(reactor.core.Disposable) RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) RRemoteService(org.redisson.api.RRemoteService) RRemoteAsync(org.redisson.api.annotation.RRemoteAsync) ArrayList(java.util.ArrayList) RFuture(org.redisson.api.RFuture) RedissonRxClient(org.redisson.api.RedissonRxClient) Future(java.util.concurrent.Future) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) RRemoteRx(org.redisson.api.annotation.RRemoteRx) RedissonClient(org.redisson.api.RedissonClient) RRemoteReactive(org.redisson.api.annotation.RRemoteReactive) ExecutorService(java.util.concurrent.ExecutorService) SerializationCodec(org.redisson.codec.SerializationCodec) IOException(java.io.IOException) Completable(io.reactivex.rxjava3.core.Completable) Mono(reactor.core.publisher.Mono) NotSerializableException(java.io.NotSerializableException) Executors(java.util.concurrent.Executors) RemoteInvocationOptions(org.redisson.api.RemoteInvocationOptions) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) RemoteServiceAckTimeoutException(org.redisson.remote.RemoteServiceAckTimeoutException) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) RedissonReactiveClient(org.redisson.api.RedissonReactiveClient) Test(org.junit.jupiter.api.Test)

Example 2 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project Tusky by Vavassor.

the class NotificationsFragment method sendFetchNotificationsRequest.

private void sendFetchNotificationsRequest(String fromId, String uptoId, final FetchEnd fetchEnd, final int pos) {
    /* If there is a fetch already ongoing, record however many fetches are requested and
         * fulfill them after it's complete. */
    if (fetchEnd == FetchEnd.TOP && topLoading) {
        return;
    }
    if (fetchEnd == FetchEnd.BOTTOM && bottomLoading) {
        return;
    }
    if (fetchEnd == FetchEnd.TOP) {
        topLoading = true;
    }
    if (fetchEnd == FetchEnd.BOTTOM) {
        bottomLoading = true;
    }
    Disposable notificationCall = mastodonApi.notifications(fromId, uptoId, LOAD_AT_ONCE, showNotificationsFilter ? notificationFilter : null).observeOn(AndroidSchedulers.mainThread()).to(autoDisposable(from(this, Lifecycle.Event.ON_DESTROY))).subscribe(response -> {
        if (response.isSuccessful()) {
            String linkHeader = response.headers().get("Link");
            onFetchNotificationsSuccess(response.body(), linkHeader, fetchEnd, pos);
        } else {
            onFetchNotificationsFailure(new Exception(response.message()), fetchEnd, pos);
        }
    }, throwable -> onFetchNotificationsFailure(throwable, fetchEnd, pos));
    disposables.add(notificationCall);
}
Also used : AutoDispose.autoDisposable(autodispose2.AutoDispose.autoDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) CompositeDisposable(io.reactivex.rxjava3.disposables.CompositeDisposable) IOException(java.io.IOException)

Example 3 with Disposable

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

the class FlowableInterval method subscribeActual.

@Override
public void subscribeActual(Subscriber<? super Long> s) {
    IntervalSubscriber is = new IntervalSubscriber(s);
    s.onSubscribe(is);
    Scheduler sch = scheduler;
    if (sch instanceof TrampolineScheduler) {
        Worker worker = sch.createWorker();
        is.setResource(worker);
        worker.schedulePeriodically(is, initialDelay, period, unit);
    } else {
        Disposable d = sch.schedulePeriodicallyDirect(is, initialDelay, period, unit);
        is.setResource(d);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)

Example 4 with Disposable

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

the class ObservableIntervalRange method subscribeActual.

@Override
public void subscribeActual(Observer<? super Long> observer) {
    IntervalRangeObserver is = new IntervalRangeObserver(observer, start, end);
    observer.onSubscribe(is);
    Scheduler sch = scheduler;
    if (sch instanceof TrampolineScheduler) {
        Worker worker = sch.createWorker();
        is.setResource(worker);
        worker.schedulePeriodically(is, initialDelay, period, unit);
    } else {
        Disposable d = sch.schedulePeriodicallyDirect(is, initialDelay, period, unit);
        is.setResource(d);
    }
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) TrampolineScheduler(io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)

Example 5 with Disposable

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

the class FlowableTimer method subscribeActual.

@Override
public void subscribeActual(Subscriber<? super Long> s) {
    TimerSubscriber ios = new TimerSubscriber(s);
    s.onSubscribe(ios);
    Disposable d = scheduler.scheduleDirect(ios, delay, unit);
    ios.setResource(d);
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable)

Aggregations

Test (org.junit.Test)250 Disposable (io.reactivex.rxjava3.disposables.Disposable)219 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)37 Scheduler (io.reactivex.rxjava3.core.Scheduler)36 EmptyDisposable (io.reactivex.rxjava3.internal.disposables.EmptyDisposable)35 Worker (io.reactivex.rxjava3.core.Scheduler.Worker)34 BooleanSubscription (io.reactivex.rxjava3.internal.subscriptions.BooleanSubscription)32 TestSubscriber (io.reactivex.rxjava3.subscribers.TestSubscriber)22 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)22 TestObserver (io.reactivex.rxjava3.observers.TestObserver)18 SequentialDisposable (io.reactivex.rxjava3.internal.disposables.SequentialDisposable)15 QueueDisposable (io.reactivex.rxjava3.operators.QueueDisposable)13 CountingRunnable (io.reactivex.rxjava3.android.testutil.CountingRunnable)10 TrampolineScheduler (io.reactivex.rxjava3.internal.schedulers.TrampolineScheduler)9 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6 TestScheduler (io.reactivex.rxjava3.schedulers.TestScheduler)6