@Test public void timedNoOutdatedData() { TestScheduler scheduler = new TestScheduler(); Flowable<Integer> source = Flowable.just(1) .replay(2, TimeUnit.SECONDS, scheduler) .autoConnect(); source.test().assertResult(1); source.test().assertResult(1); scheduler.advanceTimeBy(3, TimeUnit.SECONDS); source.test().assertResult(); }
@Test public void scalarMapToEmpty() { FlowableScalarXMap.scalarXMap(1, new Function<Integer, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Integer v) throws Exception { return Flowable.empty(); } }) .test() .assertResult(); }
@Test public void multicastSelectorCallableConnectableCrash() { FlowableReplay.multicastSelector(new Callable<ConnectableFlowable<Object>>() { @Override public ConnectableFlowable<Object> call() throws Exception { throw new TestException(); } }, Functions.<Flowable<Object>>identity()) .test() .assertFailure(TestException.class); }
@Test public void emitLastTimed() { Flowable.just(1) .sample(1, TimeUnit.DAYS, true) .test() .assertResult(1); }
@Test public void scanEmptyBackpressured() { Flowable.<Integer>empty() .scan(0, SUM) .test(1) .assertResult(0); }
@Test public void replaySelectorSizeScheduler() { Flowable.just(1).replay(Functions.<Flowable<Integer>>identity(), 1, Schedulers.io()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void replaySelectorReturnsNull() { Flowable.just(1) .replay(new Function<Flowable<Integer>, Publisher<Object>>() { @Override public Publisher<Object> apply(Flowable<Integer> v) throws Exception { return null; } }, Schedulers.trampoline()) .test() .assertFailureAndMessage(NullPointerException.class, "The selector returned a null Publisher"); }
@Test public void emitLastOther() { Flowable.just(1) .sample(Flowable.timer(1, TimeUnit.DAYS), true) .test() .assertResult(1); }
@Test public void singleOrError() { Flowable.empty() .singleOrError() .toFlowable() .test() .assertFailure(NoSuchElementException.class); } }
@Test public void replaySizeAndTime() { Flowable.just(1).replay(1, 1, TimeUnit.MILLISECONDS) .autoConnect() .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void boundaryDirectSecondMissingBackpressure() { BehaviorProcessor.createDefault(1) .window(Flowable.just(1)) .test(1) .assertError(MissingBackpressureException.class) .assertNotComplete(); }
@Test public void dontRetry() { Flowable.error(new TestException("Outer")) .retry(Functions.alwaysFalse()) .test() .assertFailureAndMessage(TestException.class, "Outer"); }
@Test public void sourceSupplierReturnsNull() { Flowable.using(Functions.justCallable(1), Functions.justFunction((Publisher<Object>)null), Functions.emptyConsumer()) .test() .assertFailureAndMessage(NullPointerException.class, "The sourceSupplier returned a null Publisher") ; }
@Test public void prefetchFlowable() { Flowable.sequenceEqual(Flowable.range(1, 20), Flowable.range(1, 20), 2) .toFlowable() .test() .assertResult(true); }
@Test public void mainError() { Flowable.error(new TestException()) .window(Functions.justCallable(Flowable.never())) .test() .assertError(TestException.class); }
@Test public void boundaryOnError() { TestSubscriber<Object> ts = Flowable.error(new TestException()) .window(Flowable.never()) .flatMap(Functions.<Flowable<Object>>identity(), true) .test() .assertFailure(CompositeException.class); List<Throwable> errors = TestHelper.compositeList(ts.errors().get(0)); TestHelper.assertError(errors, 0, TestException.class); }
@Test public void skipLastTimedDefaultScheduler() { Flowable.just(1).concatWith(Flowable.just(2).delay(500, TimeUnit.MILLISECONDS)) .skipLast(300, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void boundaryError() { BehaviorProcessor.createDefault(1) .window(Functions.justCallable(Flowable.error(new TestException()))) .test() .assertValueCount(1) .assertNotComplete() .assertError(TestException.class); }
@Test public void takeHalf() { int elements = 1024; Flowable.range(0, elements * 2).unsubscribeOn(Schedulers.single()) .take(elements) .test() .awaitDone(5, TimeUnit.SECONDS) .assertValueCount(elements) .assertComplete() .assertNoErrors() .assertSubscribed(); }
@Test public void cancelAsFlowable() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = pp.singleOrError().toFlowable().test(); assertTrue(pp.hasSubscribers()); ts.assertEmpty(); ts.cancel(); assertFalse(pp.hasSubscribers()); }