use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class BlockingFlowableMostRecentTest method singleSourceManyIterators.
@Test
public void singleSourceManyIterators() {
TestScheduler scheduler = new TestScheduler();
Flowable<Long> source = Flowable.interval(1, TimeUnit.SECONDS, scheduler).take(10);
Iterable<Long> iter = source.blockingMostRecent(-1L);
for (int j = 0; j < 3; j++) {
Iterator<Long> it = iter.iterator();
Assert.assertEquals(Long.valueOf(-1), it.next());
for (int i = 0; i < 9; i++) {
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertTrue(it.hasNext());
Assert.assertEquals(Long.valueOf(i), it.next());
}
scheduler.advanceTimeBy(1, TimeUnit.SECONDS);
Assert.assertFalse(it.hasNext());
}
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class BoundedSubscriberTest method badSourceEmitAfterDone.
@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
s.onNext(1);
s.onComplete();
s.onNext(2);
s.onError(new TestException());
s.onComplete();
}
});
final List<Object> received = new ArrayList<>();
BoundedSubscriber<Object> subscriber = new BoundedSubscriber<>(new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
received.add(v);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
received.add(e);
}
}, new Action() {
@Override
public void run() throws Exception {
received.add(100);
}
}, new Consumer<Subscription>() {
@Override
public void accept(Subscription s) throws Exception {
s.request(128);
}
}, 128);
source.subscribe(subscriber);
assertEquals(Arrays.asList(1, 100), received);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class LambdaSubscriberTest method badSourceEmitAfterDone.
@Test
@SuppressUndeliverable
public void badSourceEmitAfterDone() {
Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() {
@Override
public void subscribe(Subscriber<? super Integer> s) {
BooleanSubscription s1 = new BooleanSubscription();
s.onSubscribe(s1);
s.onNext(1);
s.onComplete();
s.onNext(2);
s.onError(new TestException());
s.onComplete();
}
});
final List<Object> received = new ArrayList<>();
LambdaSubscriber<Object> subscriber = new LambdaSubscriber<>(new Consumer<Object>() {
@Override
public void accept(Object v) throws Exception {
received.add(v);
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable e) throws Exception {
received.add(e);
}
}, new Action() {
@Override
public void run() throws Exception {
received.add(100);
}
}, new Consumer<Subscription>() {
@Override
public void accept(Subscription s) throws Exception {
s.request(Long.MAX_VALUE);
}
});
source.subscribe(subscriber);
assertEquals(Arrays.asList(1, 100), received);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class StrictSubscriberTest method normalOnError.
@Test
public void normalOnError() {
TestSubscriberEx<Integer> ts = new TestSubscriberEx<>();
SubscriberWrapper<Integer> wrapper = new SubscriberWrapper<>(ts);
Flowable.range(1, 5).concatWith(Flowable.<Integer>error(new TestException())).subscribe(wrapper);
ts.assertFailure(TestException.class, 1, 2, 3, 4, 5);
}
use of io.reactivex.rxjava3.core.Flowable in project RxJava by ReactiveX.
the class StrictSubscriberTest method cancelAfterOnComplete.
@Test
public void cancelAfterOnComplete() {
final List<Object> list = new ArrayList<>();
Subscriber<Object> sub = new Subscriber<Object>() {
Subscription upstream;
@Override
public void onSubscribe(Subscription s) {
this.upstream = s;
}
@Override
public void onNext(Object t) {
list.add(t);
}
@Override
public void onError(Throwable t) {
upstream.cancel();
list.add(t);
}
@Override
public void onComplete() {
upstream.cancel();
list.add("Done");
}
};
new Flowable<Object>() {
@Override
protected void subscribeActual(Subscriber<? super Object> s) {
BooleanSubscription b = new BooleanSubscription();
s.onSubscribe(b);
s.onComplete();
list.add(b.isCancelled());
}
}.subscribe(sub);
assertEquals(Arrays.<Object>asList("Done", false), list);
}
Aggregations