Refine search
@Test public void testFirstOrElseWithPredicateOfSomeFlowable() { Flowable<String> src = Flowable.just("a", "b", "c", "d", "e", "f"); src.filter(IS_D).first("default").toFlowable().subscribe(w); verify(w, times(1)).onNext(anyString()); verify(w, times(1)).onNext("d"); verify(w, never()).onError(any(Throwable.class)); verify(w, times(1)).onComplete(); }
@Test public void testBackpressure2() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(); Flowable.range(1, 100000).takeLast(Flowable.bufferSize() * 4) .observeOn(Schedulers.newThread()).map(newSlowProcessor()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals(Flowable.bufferSize() * 4, ts.valueCount()); }
@Test(timeout = 2000) public void testRepeatTake() { Flowable<Integer> xs = Flowable.just(1, 2); Object[] ys = xs.repeat().subscribeOn(Schedulers.newThread()).take(4).toList().blockingGet().toArray(); assertArrayEquals(new Object[] { 1, 2, 1, 2 }, ys); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Publisher<List<Long>> createPublisher(long elements) { return Flowable.fromIterable(iterate(elements)) .window(Flowable.just(1).concatWith(Flowable.<Integer>never())) .onBackpressureBuffer() .flatMap((Function)Functions.identity()) ; } }
@Override public Publisher<Long> createPublisher(long elements) { return Flowable.switchOnNext(Flowable.just( Flowable.fromIterable(iterate(elements))) ) ; } }
@Test public void normalError() { Flowable.create(source, BackpressureStrategy.ERROR).subscribe(ts); source.onNext(1); source.onNext(2); source.onComplete(); ts.assertNoValues(); ts.assertError(MissingBackpressureException.class); ts.assertNotComplete(); Assert.assertEquals("create: could not emit value due to lack of requests", ts.errors().get(0).getMessage()); }
@Test public void workerNotDisposedPrematurelyNormalInAsyncOutConditional() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); TestSubscriber<Integer> ts = new TestSubscriberFusedCanceling(); Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()).subscribe(ts); assertEquals(1, s.disposedCount.get()); } }
@Test public void innerEscapeCompleted() { Flowable<Integer> source = Flowable.just(0); Flowable<Integer> m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber<Object> ts = new TestSubscriber<Object>(); m.subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); System.out.println(ts.values()); }
@Test public void workerNotDisposedPrematurelyNormalInNormalOutConditional() { DisposeTrackingScheduler s = new DisposeTrackingScheduler(); Flowable.concat( Flowable.just(1).hide().observeOn(s).filter(Functions.alwaysTrue()), Flowable.just(2) ) .test() .assertResult(1, 2); assertEquals(1, s.disposedCount.get()); }
@Test public void testListFlowable() { Flowable<String> w = Flowable.fromIterable(Arrays.asList("one", "two", "three")); Flowable<List<String>> flowable = w.toList().toFlowable(); Subscriber<List<String>> subscriber = TestHelper.mockSubscriber(); flowable.subscribe(subscriber); verify(subscriber, times(1)).onNext(Arrays.asList("one", "two", "three")); verify(subscriber, Mockito.never()).onError(any(Throwable.class)); verify(subscriber, times(1)).onComplete(); }
@Test public void testTake2() { Flowable<Integer> f = Flowable.just(1, 2, 3, 4, 5); Iterable<String> it = Arrays.asList("a", "b", "c", "d", "e"); SquareStr squareStr = new SquareStr(); f.map(squareStr).zipWith(it, concat2Strings).take(2).subscribe(printer); assertEquals(2, squareStr.counter.get()); }
@Test public void testErrorDelayedAsync() { Flowable<Integer> source = Flowable.just(1, 2, 3) .concatWith(Flowable.<Integer>error(new TestException())); TestSubscriber<Integer> ts = TestSubscriber.create(); source.observeOn(Schedulers.computation(), true).subscribe(ts); ts.awaitTerminalEvent(2, TimeUnit.SECONDS); ts.assertValues(1, 2, 3); ts.assertError(TestException.class); ts.assertNotComplete(); }
@Test public void testError2() { Flowable<Integer> source = Flowable.concat(Flowable.just(0), Flowable.<Integer> error(new TestException("Forced failure"))); Flowable<Integer> m = source.groupBy(identity, dbl).flatMap(FLATTEN_INTEGER); TestSubscriber<Object> ts = new TestSubscriber<Object>(); m.subscribe(ts); ts.awaitTerminalEvent(); assertEquals(1, ts.errorCount()); ts.assertValueCount(1); }
@Test public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() { Flowable<String> src = Flowable.just("a", "b", "c"); src.filter(IS_D).first("default").subscribe(wo); verify(wo, times(1)).onSuccess(anyString()); verify(wo, times(1)).onSuccess("default"); verify(wo, never()).onError(any(Throwable.class)); }
@Test public void testFlatMapTransformsMergeException() { Flowable<Integer> onNext = Flowable.error(new TestException()); Flowable<Integer> onComplete = Flowable.fromIterable(Arrays.asList(4)); Flowable<Integer> onError = Flowable.fromIterable(Arrays.asList(5)); Flowable<Integer> source = Flowable.fromIterable(Arrays.asList(10, 20, 30)); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); source.flatMap(just(onNext), just(onError), funcThrow0(onComplete)).subscribe(subscriber); verify(subscriber).onError(any(TestException.class)); verify(subscriber, never()).onNext(any()); verify(subscriber, never()).onComplete(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void flatMapMaxConcurrentJustJust() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.just(Flowable.just(1)).flatMap((Function)Functions.identity(), 5).subscribe(ts); ts.assertValue(1); ts.assertNoErrors(); ts.assertComplete(); }
@Test public void backFusedErrorConditional() { TestSubscriber<Integer> ts = SubscriberFusion.newTest(QueueFuseable.ANY); Flowable.<Integer>error(new TestException()) .observeOn(ImmediateThinScheduler.INSTANCE) .filter(Functions.alwaysTrue()) .subscribe(ts); SubscriberFusion.assertFusion(ts, QueueFuseable.ASYNC) .assertFailure(TestException.class); }
@Test public void repeatScheduled() { TestSubscriber<Integer> ts = TestSubscriber.create(); Flowable.just(1).subscribeOn(Schedulers.computation()).repeat(5).subscribe(ts); ts.awaitTerminalEvent(5, TimeUnit.SECONDS); ts.assertValues(1, 1, 1, 1, 1); ts.assertNoErrors(); ts.assertComplete(); }