Search in sources :

Example 6 with Disposable

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

the class HandlerSchedulerTest method workerScheduleOnceWithDelayDisposedDoesNotRun.

@Test
public void workerScheduleOnceWithDelayDisposedDoesNotRun() {
    Worker worker = scheduler.createWorker();
    CountingRunnable counter = new CountingRunnable();
    Disposable disposable = worker.schedule(counter, 1, MINUTES);
    idleMainLooper(30, SECONDS);
    disposable.dispose();
    idleMainLooper(30, SECONDS);
    runUiThreadTasks();
    assertEquals(0, counter.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) Test(org.junit.Test)

Example 7 with Disposable

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

the class HandlerSchedulerTest method workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule.

@Test
@Ignore("Implementation delegated to default RxJava implementation")
public void workerSchedulePeriodicallyDisposedDuringRunDoesNotReschedule() {
    Worker worker = scheduler.createWorker();
    final AtomicReference<Disposable> disposableRef = new AtomicReference<>();
    CountingRunnable counter = new CountingRunnable() {

        @Override
        public void run() {
            super.run();
            if (get() == 2) {
                disposableRef.get().dispose();
            }
        }
    };
    Disposable disposable = worker.schedulePeriodically(counter, 1, 1, MINUTES);
    disposableRef.set(disposable);
    runUiThreadTasks();
    assertEquals(0, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(1, counter.get());
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
    // Dispose will have happened here during the last run() execution.
    idleMainLooper(1, MINUTES);
    runUiThreadTasks();
    assertEquals(2, counter.get());
}
Also used : Disposable(io.reactivex.rxjava3.disposables.Disposable) CountingRunnable(io.reactivex.rxjava3.android.testutil.CountingRunnable) Worker(io.reactivex.rxjava3.core.Scheduler.Worker) AtomicReference(java.util.concurrent.atomic.AtomicReference) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.

the class EnterPhoneNumberFragment method requestVerificationCode.

private void requestVerificationCode(@NonNull Mode mode) {
    NavController navController = NavHostFragment.findNavController(this);
    Disposable request = viewModel.requestVerificationCode(mode).doOnSubscribe(unused -> SignalStore.account().setRegistered(false)).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
        if (processor.hasResult()) {
            SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
        } else if (processor.localRateLimit()) {
            Log.i(TAG, "Unable to request sms code due to local rate limit");
            SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionEnterVerificationCode());
        } else if (processor.captchaRequired()) {
            Log.i(TAG, "Unable to request sms code due to captcha required");
            SafeNavigation.safeNavigate(navController, EnterPhoneNumberFragmentDirections.actionRequestCaptcha());
        } else if (processor.rateLimit()) {
            Log.i(TAG, "Unable to request sms code due to rate limit");
            Toast.makeText(register.getContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
        } else if (processor.isImpossibleNumber()) {
            Log.w(TAG, "Impossible number", processor.getError());
            Dialogs.showAlertDialog(requireContext(), getString(R.string.RegistrationActivity_invalid_number), String.format(getString(R.string.RegistrationActivity_the_number_you_specified_s_is_invalid), viewModel.getNumber().getFullFormattedNumber()));
        } else if (processor.isNonNormalizedNumber()) {
            handleNonNormalizedNumberError(processor.getOriginalNumber(), processor.getNormalizedNumber(), mode);
        } else {
            Log.i(TAG, "Unknown error during verification code request", processor.getError());
            Toast.makeText(register.getContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();
        }
        cancelSpinning(register);
        enableAllEntries();
    });
    disposables.add(request);
}
Also used : LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable) NavController(androidx.navigation.NavController)

Example 9 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.

the class BaseEnterSmsCodeFragment method handlePhoneCallRequestAfterConfirm.

private void handlePhoneCallRequestAfterConfirm() {
    Disposable request = viewModel.requestVerificationCode(VerifyAccountRepository.Mode.PHONE_CALL).observeOn(AndroidSchedulers.mainThread()).subscribe(processor -> {
        if (processor.hasResult()) {
            Toast.makeText(requireContext(), R.string.RegistrationActivity_call_requested, Toast.LENGTH_LONG).show();
        } else if (processor.captchaRequired()) {
            navigateToCaptcha();
        } else if (processor.rateLimit()) {
            Toast.makeText(requireContext(), R.string.RegistrationActivity_rate_limited_to_service, Toast.LENGTH_LONG).show();
        } else {
            Log.w(TAG, "Unable to request phone code", processor.getError());
            Toast.makeText(requireContext(), R.string.RegistrationActivity_unable_to_connect_to_service, Toast.LENGTH_LONG).show();
        }
    });
    disposables.add(request);
}
Also used : LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) Disposable(io.reactivex.rxjava3.disposables.Disposable)

Example 10 with Disposable

use of io.reactivex.rxjava3.disposables.Disposable in project Signal-Android by WhisperSystems.

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)

Aggregations

Test (org.junit.Test)251 Disposable (io.reactivex.rxjava3.disposables.Disposable)236 TestException (io.reactivex.rxjava3.exceptions.TestException)74 RxJavaTest (io.reactivex.rxjava3.core.RxJavaTest)56 IOException (java.io.IOException)38 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 LifecycleDisposable (org.thoughtcrime.securesms.util.LifecycleDisposable)8 Observable (io.reactivex.rxjava3.core.Observable)6 Observer (io.reactivex.rxjava3.core.Observer)6 ScalarDisposable (io.reactivex.rxjava3.internal.operators.observable.ObservableScalarXMap.ScalarDisposable)6