@Override public Flowable<T> apply(final Publisher<T> onSubscribe) { return Flowable.fromPublisher(onSubscribe); } }
@Override public Publisher<R> apply(Flowable<T> t) throws Exception { Publisher<R> p = ObjectHelper.requireNonNull(selector.apply(t), "The selector returned a null Publisher"); return Flowable.fromPublisher(p).observeOn(scheduler); } }
@Override public Iterator<T> iterator() { LatestSubscriberIterator<T> lio = new LatestSubscriberIterator<T>(); Flowable.<T>fromPublisher(source).materialize().subscribe(lio); return lio; }
@Test(expected = NullPointerException.class) public void fromPublisherNull() { Flowable.fromPublisher(null); }
@Test(expected = TestException.class) public void firstOnError() { Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() { @Override public void subscribe(Subscriber<? super Integer> s) { s.onSubscribe(new BooleanSubscription()); s.onError(new TestException()); } }); source.blockingFirst(); }
@Test public void firstFgnoredCancelAndOnNext() { Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() { @Override public void subscribe(Subscriber<? super Integer> s) { s.onSubscribe(new BooleanSubscription()); s.onNext(1); s.onNext(2); } }); assertEquals(1, source.blockingFirst().intValue()); }
/** * Concatenates the Publisher sequence of Publishers into a single sequence by subscribing to each inner Publisher, * one after the other, one at a time and delays any errors till the all inner and the outer Publishers terminate. * <p> * <img width="640" height="360" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/Maybe.concatDelayError.p.png" alt=""> * <dl> * <dt><b>Backpressure:</b></dt> * <dd>{@code concatDelayError} fully supports backpressure.</dd> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <T> the common element base type * @param sources the Publisher sequence of Publishers * @return the new Publisher with the concatenating behavior */ @SuppressWarnings({ "unchecked", "rawtypes" }) @BackpressureSupport(BackpressureKind.FULL) @CheckReturnValue @SchedulerSupport(SchedulerSupport.NONE) public static <T> Flowable<T> concatDelayError(Publisher<? extends MaybeSource<? extends T>> sources) { return Flowable.fromPublisher(sources).concatMapDelayError((Function)MaybeToPublisher.instance()); }
/** * Concatenates the Publisher sequence of Publishers into a single sequence by subscribing to each inner Publisher, * one after the other, one at a time and delays any errors till the all inner and the outer Publishers terminate. * * <dl> * <dt><b>Backpressure:</b></dt> * <dd>{@code concatDelayError} fully supports backpressure.</dd> * <dt><b>Scheduler:</b></dt> * <dd>{@code concatDelayError} does not operate by default on a particular {@link Scheduler}.</dd> * </dl> * * @param <T> the common element base type * @param sources the Publisher sequence of Publishers * @param prefetch the number of elements to prefetch from the outer Publisher * @param tillTheEnd if true exceptions from the outer and all inner Publishers are delayed to the end * if false, exception from the outer Publisher is delayed till the current Publisher terminates * @return the new Publisher with the concatenating behavior */ @SuppressWarnings({ "unchecked", "rawtypes" }) @CheckReturnValue @BackpressureSupport(BackpressureKind.FULL) @SchedulerSupport(SchedulerSupport.NONE) public static <T> Flowable<T> concatDelayError(Publisher<? extends Publisher<? extends T>> sources, int prefetch, boolean tillTheEnd) { return fromPublisher(sources).concatMapDelayError((Function)Functions.identity(), prefetch, tillTheEnd); }
public final <R> CylonDetectorObservable<R> boop(Function<? super T, ? extends R> func) { return new CylonDetectorObservable<R>(new FlowableMap<T, R>(Flowable.fromPublisher(onSubscribe), func)); }
public final CylonDetectorObservable<T> beep(Predicate<? super T> predicate) { return new CylonDetectorObservable<T>(new FlowableFilter<T>(Flowable.fromPublisher(onSubscribe), predicate)); }
@Test public void wrap() { Flowable.fromPublisher(new Publisher<Integer>() { @Override public void subscribe(Subscriber<? super Integer> subscriber) { subscriber.onSubscribe(new BooleanSubscription()); subscriber.onNext(1); subscriber.onNext(2); subscriber.onNext(3); subscriber.onNext(4); subscriber.onNext(5); subscriber.onComplete(); } }) .test() .assertResult(1, 2, 3, 4, 5); }
@Test public void onCompleteCrash() { Flowable.fromPublisher(new Publisher<Object>() { @Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(new BooleanSubscription()); s.onComplete(); } }) .doOnComplete(new Action() { @Override public void run() throws Exception { throw new IOException(); } }) .test() .assertFailure(IOException.class); }
@Test(timeout = 2000) public void backpressureWithBufferDropOldest() throws InterruptedException { int bufferSize = 3; final AtomicInteger droppedCount = new AtomicInteger(0); Action incrementOnDrop = new Action() { @Override public void run() throws Exception { droppedCount.incrementAndGet(); } }; TestSubscriber<Long> ts = createTestSubscriber(); Flowable.fromPublisher(send500ValuesAndComplete.onBackpressureBuffer(bufferSize, incrementOnDrop, DROP_OLDEST)) .subscribe(ts); // we request 10 but only 3 should come from the buffer ts.request(10); ts.awaitTerminalEvent(); assertEquals(bufferSize, ts.values().size()); ts.assertNoErrors(); assertEquals(497, ts.values().get(0).intValue()); assertEquals(498, ts.values().get(1).intValue()); assertEquals(499, ts.values().get(2).intValue()); assertEquals(droppedCount.get(), 500 - bufferSize); }
@Test(timeout = 2000) public void backpressureWithBufferDropLatest() throws InterruptedException { int bufferSize = 3; final AtomicInteger droppedCount = new AtomicInteger(0); Action incrementOnDrop = new Action() { @Override public void run() throws Exception { droppedCount.incrementAndGet(); } }; TestSubscriber<Long> ts = createTestSubscriber(); Flowable.fromPublisher(send500ValuesAndComplete.onBackpressureBuffer(bufferSize, incrementOnDrop, DROP_LATEST)) .subscribe(ts); // we request 10 but only 3 should come from the buffer ts.request(10); ts.awaitTerminalEvent(); assertEquals(bufferSize, ts.values().size()); ts.assertNoErrors(); assertEquals(0, ts.values().get(0).intValue()); assertEquals(1, ts.values().get(1).intValue()); assertEquals(499, ts.values().get(2).intValue()); assertEquals(droppedCount.get(), 500 - bufferSize); }
@Test public void firstIgnoredCancelAndOnError() { List<Throwable> list = TestHelper.trackPluginErrors(); try { Flowable<Integer> source = Flowable.fromPublisher(new Publisher<Integer>() { @Override public void subscribe(Subscriber<? super Integer> s) { s.onSubscribe(new BooleanSubscription()); s.onNext(1); s.onError(new TestException()); } }); assertEquals(1, source.blockingFirst().intValue()); TestHelper.assertUndeliverable(list, 0, TestException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void onCompleteCrashConditional() { Flowable.fromPublisher(new Publisher<Object>() { @Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(new BooleanSubscription()); s.onComplete(); } }) .doOnComplete(new Action() { @Override public void run() throws Exception { throw new IOException(); } }) .filter(Functions.alwaysTrue()) .test() .assertFailure(IOException.class); }
@Test public void onErrorAfterCrash() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { Flowable.fromPublisher(new Publisher<Object>() { @Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(new BooleanSubscription()); s.onError(new TestException()); } }) .doAfterTerminate(new Action() { @Override public void run() throws Exception { throw new IOException(); } }) .test() .assertFailure(TestException.class); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void onCompleteAfterCrash() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { Flowable.fromPublisher(new Publisher<Object>() { @Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(new BooleanSubscription()); s.onComplete(); } }) .doAfterTerminate(new Action() { @Override public void run() throws Exception { throw new IOException(); } }) .test() .assertResult(); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void overflowReported() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { Completable.concat( Flowable.fromPublisher(new Publisher<Completable>() { @Override public void subscribe(Subscriber<? super Completable> s) { s.onSubscribe(new BooleanSubscription()); s.onNext(Completable.never()); s.onNext(Completable.never()); s.onNext(Completable.never()); s.onNext(Completable.never()); s.onComplete(); } }), 1 ) .test() .assertFailure(MissingBackpressureException.class); TestHelper.assertError(errors, 0, MissingBackpressureException.class); } finally { RxJavaPlugins.reset(); } }
@Test public void onCompleteAfterCrashConditional() { List<Throwable> errors = TestHelper.trackPluginErrors(); try { Flowable.fromPublisher(new Publisher<Object>() { @Override public void subscribe(Subscriber<? super Object> s) { s.onSubscribe(new BooleanSubscription()); s.onComplete(); } }) .doAfterTerminate(new Action() { @Override public void run() throws Exception { throw new IOException(); } }) .filter(Functions.alwaysTrue()) .test() .assertResult(); TestHelper.assertUndeliverable(errors, 0, IOException.class); } finally { RxJavaPlugins.reset(); } }