@Override public ObservableSource<Object> apply(Observable<Object> o) throws Exception { return o.skipLast(1, TimeUnit.DAYS); } });
@Test(expected = NullPointerException.class) public void skipLastTimedSchedulerNull() { just1.skipLast(1, TimeUnit.SECONDS, null); }
/** * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window * (defined on a specified scheduler) before the source completes. * <p> * <img width="640" height="340" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipLast.ts.png" alt=""> * <p> * Note: this action will cache the latest items arriving in the specified time window. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>You specify which {@link Scheduler} this operator will use for tracking the current time</dd> * </dl> * * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the scheduler used as the time source * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} and {@code scheduler} * @see <a href="http://reactivex.io/documentation/operators/skiplast.html">ReactiveX operators documentation: SkipLast</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable<T> skipLast(long time, TimeUnit unit, Scheduler scheduler) { return skipLast(time, unit, scheduler, false, bufferSize()); }
/** * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window * (defined on a specified scheduler) before the source completes. * <p> * <img width="640" height="340" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipLast.ts.png" alt=""> * <p> * Note: this action will cache the latest items arriving in the specified time window. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>You specify which {@link Scheduler} this operator will use for tracking the current time</dd> * </dl> * * @param time * the length of the time window * @param unit * the time unit of {@code time} * @param scheduler * the scheduler used as the time source * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} and {@code scheduler} * @see <a href="http://reactivex.io/documentation/operators/skiplast.html">ReactiveX operators documentation: SkipLast</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.CUSTOM) public final Observable<T> skipLast(long time, TimeUnit unit, Scheduler scheduler) { return skipLast(time, unit, scheduler, false, bufferSize()); }
@Test public void testSkipLast2() { Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two")).skipLast(2); Observer<String> observer = TestHelper.mockObserver(); o.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test(expected = IndexOutOfBoundsException.class) public void testSkipLastWithNegativeCount() { Observable.just("one").skipLast(-1); }
@Test public void testSkipLast1() { Observable<String> o = Observable.fromIterable(Arrays.asList("one", "two", "three")).skipLast(2); Observer<String> observer = TestHelper.mockObserver(); InOrder inOrder = inOrder(observer); o.subscribe(observer); inOrder.verify(observer, never()).onNext("two"); inOrder.verify(observer, never()).onNext("three"); verify(observer, times(1)).onNext("one"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test(expected = NullPointerException.class) public void skipLastTimedUnitNull() { just1.skipLast(1, null, Schedulers.single()); }
@Test public void testSkipLastEmpty() { Observable<String> o = Observable.<String> empty().skipLast(2); Observer<String> observer = TestHelper.mockObserver(); o.subscribe(observer); verify(observer, never()).onNext(any(String.class)); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
/** * Returns an Observable that drops items emitted by the source ObservableSource during a specified time window * before the source completes. * <p> * <img width="640" height="305" src="https://raw.github.com/wiki/ReactiveX/RxJava/images/rx-operators/skipLast.t.png" alt=""> * <p> * Note: this action will cache the latest items arriving in the specified time window. * <dl> * <dt><b>Scheduler:</b></dt> * <dd>{@code skipLast} does not operate on any particular scheduler but uses the current time * from the {@code computation} {@link Scheduler}.</dd> * </dl> * * @param time * the length of the time window * @param unit * the time unit of {@code time} * @return an Observable that drops those items emitted by the source ObservableSource in a time window before the * source completes defined by {@code time} * @see <a href="http://reactivex.io/documentation/operators/skiplast.html">ReactiveX operators documentation: SkipLast</a> */ @CheckReturnValue @SchedulerSupport(SchedulerSupport.TRAMPOLINE) public final Observable<T> skipLast(long time, TimeUnit unit) { return skipLast(time, unit, Schedulers.trampoline(), false, bufferSize()); }
@Test public void testSkipLastWithZeroCount() { Observable<String> w = Observable.just("one", "two"); Observable<String> observable = w.skipLast(0); Observer<String> observer = TestHelper.mockObserver(); observable.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext("two"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test @Ignore("Null values not allowed") public void testSkipLastWithNull() { Observable<String> o = Observable.fromIterable(Arrays.asList("one", null, "two")).skipLast(1); Observer<String> observer = TestHelper.mockObserver(); o.subscribe(observer); verify(observer, times(1)).onNext("one"); verify(observer, times(1)).onNext(null); verify(observer, never()).onNext("two"); verify(observer, never()).onError(any(Throwable.class)); verify(observer, times(1)).onComplete(); }
@Test public void dispose() { TestHelper.checkDisposed(Observable.just(1).skipLast(1)); }
@Test public void error() { Observable.error(new TestException()) .skipLast(1) .test() .assertFailure(TestException.class); } }
@Test public void take() { Observable.just(1) .skipLast(0, TimeUnit.SECONDS) .take(1) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); } }
@Test public void errorDelayed() { Observable.error(new TestException()) .skipLast(1, TimeUnit.DAYS, new TestScheduler(), true) .test() .assertFailure(TestException.class); }
@Test public void skipLastTimedDefaultSchedulerDelayError() { Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS)) .skipLast(300, TimeUnit.MILLISECONDS, true) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void skipLastTimedDefaultScheduler() { Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS)) .skipLast(300, TimeUnit.MILLISECONDS) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void skipLastTimedCustomSchedulerDelayError() { Observable.just(1).concatWith(Observable.just(2).delay(500, TimeUnit.MILLISECONDS)) .skipLast(300, TimeUnit.MILLISECONDS, Schedulers.io(), true) .test() .awaitDone(5, TimeUnit.SECONDS) .assertResult(1); }
@Test public void testSkipLastWithBackpressure() { Observable<Integer> o = Observable.range(0, Observable.bufferSize() * 2).skipLast(Observable.bufferSize() + 10); TestObserver<Integer> ts = new TestObserver<Integer>(); o.observeOn(Schedulers.computation()).subscribe(ts); ts.awaitTerminalEvent(); ts.assertNoErrors(); assertEquals((Observable.bufferSize()) - 10, ts.valueCount()); }