use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableSubscriberTest method requestToFlowable.
@Test
public void requestToFlowable() {
TestSubscriber<Integer> ts = new TestSubscriber<>(3L);
final AtomicLong requested = new AtomicLong();
Flowable.<Integer>unsafeCreate(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
s.onSubscribe(new Subscription() {
@Override
public void request(long n) {
requested.set(n);
}
@Override
public void cancel() {
}
});
}
}).subscribe(ts);
assertEquals(3, requested.get());
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class XFlatMapTest method flowableFlowable.
@Test
public void flowableFlowable() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Flowable.just(1).subscribeOn(Schedulers.io()).flatMap(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
sleep();
return Flowable.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(ts);
ts.cancel();
Thread.sleep(SLEEP_AFTER_CANCEL);
ts.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class XFlatMapTest method singlePublisher.
@Test
public void singlePublisher() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Single.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
sleep();
return Flowable.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(ts);
ts.cancel();
Thread.sleep(SLEEP_AFTER_CANCEL);
ts.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class XFlatMapTest method maybePublisher.
@Test
public void maybePublisher() throws Exception {
List<Throwable> errors = TestHelper.trackPluginErrors();
try {
TestSubscriber<Integer> ts = Maybe.just(1).subscribeOn(Schedulers.io()).flatMapPublisher(new Function<Integer, Publisher<Integer>>() {
@Override
public Publisher<Integer> apply(Integer v) throws Exception {
sleep();
return Flowable.<Integer>error(new TestException());
}
}).test();
cb.await();
beforeCancelSleep(ts);
ts.cancel();
Thread.sleep(SLEEP_AFTER_CANCEL);
ts.assertEmpty();
assertTrue(errors.toString(), errors.isEmpty());
} finally {
RxJavaPlugins.reset();
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class FlowableTests method cacheWithCapacity.
@Test
public void cacheWithCapacity() throws InterruptedException {
final AtomicInteger counter = new AtomicInteger();
Flowable<String> f = Flowable.<String>unsafeCreate(new Publisher<String>() {
@Override
public void subscribe(final Subscriber<? super String> subscriber) {
subscriber.onSubscribe(new BooleanSubscription());
new Thread(new Runnable() {
@Override
public void run() {
counter.incrementAndGet();
subscriber.onNext("one");
subscriber.onComplete();
}
}).start();
}
}).cacheWithInitialCapacity(1);
// we then expect the following 2 subscriptions to get that same value
final CountDownLatch latch = new CountDownLatch(2);
// subscribe once
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
// subscribe again
f.subscribe(new Consumer<String>() {
@Override
public void accept(String v) {
assertEquals("one", v);
latch.countDown();
}
});
if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
fail("subscriptions did not receive values");
}
assertEquals(1, counter.get());
}
Aggregations