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());
}
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());
}
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());
}
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);
}
}
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();
}
}
Aggregations