@Override public Flowable<Flowable<Object>> apply(Flowable<Object> f) throws Exception { return f.window(1); } });
@Override public Flowable<Flowable<Object>> apply(Flowable<Object> f) throws Exception { return f.window(1, 2); } });
@Test(expected = NullPointerException.class) public void windowOpenCloseOpenNull() { just1.window(null, new Function<Object, Publisher<Integer>>() { @Override public Publisher<Integer> apply(Object v) { return just1; } }); }
@Override public Object apply(Flowable<Object> f) throws Exception { return f.window(Flowable.never()).flatMap(new Function<Flowable<Object>, Flowable<Object>>() { @Override public Flowable<Object> apply(Flowable<Object> v) throws Exception { return v; } }); } }, false, 1, 1, 1);
@Test(expected = NullPointerException.class) public void windowBoundarySupplierReturnsNull() { just1.window(new Callable<Publisher<Object>>() { @Override public Publisher<Object> call() { return null; } }).blockingSubscribe(); }
@Override public Publisher<Flowable<Object>> apply(Flowable<Object> f) throws Exception { return f.window(Flowable.never()).takeLast(1); } });
@Test(expected = NullPointerException.class) public void windowOpenCloseCloseReturnsNull() { Flowable.never().window(just1, new Function<Integer, Publisher<Object>>() { @Override public Publisher<Object> apply(Integer v) { return null; } }).blockingSubscribe(); }
@Test public void invalidSpan() { try { Flowable.just(1).window(-99, 1, TimeUnit.SECONDS); fail("Should have thrown!"); } catch (IllegalArgumentException ex) { assertEquals("timespan > 0 required but it was -99", ex.getMessage()); } }
@Override public Object apply(Flowable<Object> f) throws Exception { return f.window(Functions.justCallable(Flowable.never())).flatMap(new Function<Flowable<Object>, Flowable<Object>>() { @Override public Flowable<Object> apply(Flowable<Object> v) throws Exception { return v; } }); } }, false, 1, 1, 1);
@Test public void testNonOverlappingWindows() { Flowable<String> subject = Flowable.just("one", "two", "three", "four", "five"); Flowable<Flowable<String>> windowed = subject.window(3); List<List<String>> windows = toLists(windowed); assertEquals(2, windows.size()); assertEquals(list("one", "two", "three"), windows.get(0)); assertEquals(list("four", "five"), windows.get(1)); }
@Test public void testSkipAndCountGaplessWindows() { Flowable<String> subject = Flowable.just("one", "two", "three", "four", "five"); Flowable<Flowable<String>> windowed = subject.window(3, 3); List<List<String>> windows = toLists(windowed); assertEquals(2, windows.size()); assertEquals(list("one", "two", "three"), windows.get(0)); assertEquals(list("four", "five"), windows.get(1)); }
@SuppressWarnings("unchecked") @Test public void firstWindowMissingBackpressure() { Flowable.never() .window(1, TimeUnit.SECONDS, 1) .test(0L) .assertFailure(MissingBackpressureException.class); }
@Test public void timespanTimeskipCustomSchedulerBufferSize() { Flowable.range(1, 10) .window(1, 1, TimeUnit.MINUTES, Schedulers.io(), 2) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); }
@Test public void mainError() { Flowable.error(new TestException()) .window(Functions.justCallable(Flowable.never())) .test() .assertError(TestException.class); }
@Test public void timespanTimeskipDefaultScheduler() { Flowable.just(1) .window(1, 1, TimeUnit.MINUTES) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void restartTimer() { Flowable.range(1, 5) .window(1, TimeUnit.DAYS, Schedulers.single(), 2, true) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .assertResult(1, 2, 3, 4, 5); }
@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 timeskipJustOverlap() { Flowable.just(1) .window(2, 1, TimeUnit.MINUTES, Schedulers.single()) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void exactBoundaryError() { Flowable.error(new TestException()) .window(1, TimeUnit.DAYS, Schedulers.single(), 2, true) .test() .assertSubscribed() .assertError(TestException.class) .assertNotComplete(); }
@Test public void mainError() { Flowable.<Integer>error(new TestException()) .window(Flowable.never(), Functions.justFunction(Flowable.just(1))) .flatMap(Functions.<Flowable<Integer>>identity()) .test() .assertFailure(TestException.class); }