Search in sources :

Example 21 with Disposable

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

the class CompletableTest method subscribeDispose.

@Test(timeout = 1000)
public void subscribeDispose() throws InterruptedException {
    final AtomicBoolean complete = new AtomicBoolean();
    Completable c = normal.completable.delay(200, TimeUnit.MILLISECONDS).doOnComplete(new Action() {

        @Override
        public void run() {
            complete.set(true);
        }
    });
    Disposable d = c.subscribe();
    Thread.sleep(100);
    d.dispose();
    Thread.sleep(150);
    Assert.assertFalse("Completed", complete.get());
}
Also used : Disposable(io.reactivex.disposables.Disposable)

Example 22 with Disposable

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

the class CompletableTest method subscribeAction2ReportsUnsubscribedOnError.

@Test
public void subscribeAction2ReportsUnsubscribedOnError() {
    PublishSubject<String> stringSubject = PublishSubject.create();
    Completable completable = stringSubject.ignoreElements();
    Disposable completableSubscription = completable.subscribe(new Action() {

        @Override
        public void run() {
        }
    }, new Consumer<Throwable>() {

        @Override
        public void accept(Throwable e) {
        }
    });
    stringSubject.onError(new TestException());
    assertTrue("Not unsubscribed?", completableSubscription.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable)

Example 23 with Disposable

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

the class CompletableTest method subscribeReportsUnsubscribed.

@Test
public void subscribeReportsUnsubscribed() {
    PublishSubject<String> stringSubject = PublishSubject.create();
    Completable completable = stringSubject.ignoreElements();
    Disposable completableSubscription = completable.subscribe();
    stringSubject.onComplete();
    assertTrue("Not unsubscribed?", completableSubscription.isDisposed());
}
Also used : Disposable(io.reactivex.disposables.Disposable)

Example 24 with Disposable

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

the class FlowablePublishTest method subscribeDisconnectRace.

@Test
public void subscribeDisconnectRace() {
    for (int i = 0; i < 500; i++) {
        final PublishProcessor<Integer> ps = PublishProcessor.create();
        final ConnectableFlowable<Integer> co = ps.publish();
        final Disposable d = co.connect();
        final TestSubscriber<Integer> to = new TestSubscriber<Integer>();
        Runnable r1 = new Runnable() {

            @Override
            public void run() {
                d.dispose();
            }
        };
        Runnable r2 = new Runnable() {

            @Override
            public void run() {
                co.subscribe(to);
            }
        };
        TestHelper.race(r1, r2);
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) TestSubscriber(io.reactivex.subscribers.TestSubscriber) Test(org.junit.Test)

Example 25 with Disposable

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

the class FlowablePublishTest method testPublish.

@Test
public void testPublish() throws InterruptedException {
    final AtomicInteger counter = new AtomicInteger();
    ConnectableFlowable<String> o = Flowable.unsafeCreate(new Publisher<String>() {

        @Override
        public void subscribe(final Subscriber<? super String> observer) {
            observer.onSubscribe(new BooleanSubscription());
            new Thread(new Runnable() {

                @Override
                public void run() {
                    counter.incrementAndGet();
                    observer.onNext("one");
                    observer.onComplete();
                }
            }).start();
        }
    }).publish();
    final CountDownLatch latch = new CountDownLatch(2);
    // subscribe once
    o.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    // subscribe again
    o.subscribe(new Consumer<String>() {

        @Override
        public void accept(String v) {
            assertEquals("one", v);
            latch.countDown();
        }
    });
    Disposable s = o.connect();
    try {
        if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
            fail("subscriptions did not receive values");
        }
        assertEquals(1, counter.get());
    } finally {
        s.dispose();
    }
}
Also used : Disposable(io.reactivex.disposables.Disposable) BooleanSubscription(io.reactivex.internal.subscriptions.BooleanSubscription) TestSubscriber(io.reactivex.subscribers.TestSubscriber) HasUpstreamPublisher(io.reactivex.internal.fuseable.HasUpstreamPublisher) Test(org.junit.Test)

Aggregations

Disposable (io.reactivex.disposables.Disposable)199 Test (org.junit.Test)95 Logger (chat.rocket.android.helper.Logger)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)18 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)17 Worker (io.reactivex.Scheduler.Worker)15 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)13 CountingRunnable (io.reactivex.android.testutil.CountingRunnable)10 EmptyDisposable (io.reactivex.internal.disposables.EmptyDisposable)10 TestSubscriber (io.reactivex.subscribers.TestSubscriber)10 Optional (com.fernandocejas.arrow.optional.Optional)9 Single (io.reactivex.Single)9 Nullable (android.support.annotation.Nullable)8 Function (io.reactivex.functions.Function)8 Bundle (android.os.Bundle)7 Pair (android.support.v4.util.Pair)7 ANError (com.androidnetworking.error.ANError)7 AnalyticsListener (com.androidnetworking.interfaces.AnalyticsListener)7 List (java.util.List)7 NonNull (android.support.annotation.NonNull)6