@Test
  public void testDelayErrorMaxConcurrent() {
    final List<Long> requests = new ArrayList<>();
    Observable<Integer> source =
        Observable.mergeDelayError(
            Observable.just(
                    Observable.just(1).asObservable(),
                    Observable.<Integer>error(new TestException()))
                .doOnRequest(
                    new LongConsumer() {
                      @Override
                      public void accept(long t1) {
                        requests.add(t1);
                      }
                    }),
            1);

    TestSubscriber<Integer> ts = new TestSubscriber<>();

    source.subscribe(ts);

    ts.assertValue(1);
    ts.assertTerminated();
    ts.assertError(TestException.class);
    assertEquals(Arrays.asList(1L, 1L, 1L), requests);
  }
  @Test
  public void testScanWithRequestOne() {
    Observable<Integer> o =
        Observable.just(1, 2)
            .scan(
                0,
                new BiFunction<Integer, Integer, Integer>() {

                  @Override
                  public Integer apply(Integer t1, Integer t2) {
                    return t1 + t2;
                  }
                })
            .take(1);
    TestSubscriber<Integer> subscriber = new TestSubscriber<>();
    o.subscribe(subscriber);
    subscriber.assertValue(0);
    subscriber.assertTerminated();
    subscriber.assertNoErrors();
  }
  @Test
  public void testInitialValueEmittedWithProducer() {
    Observable<Integer> source = Observable.never();

    TestSubscriber<Integer> ts = new TestSubscriber<>();

    source
        .scan(
            0,
            new BiFunction<Integer, Integer, Integer>() {
              @Override
              public Integer apply(Integer t1, Integer t2) {
                return t1 + t2;
              }
            })
        .subscribe(ts);

    ts.assertNoErrors();
    ts.assertNotComplete();
    ts.assertValue(0);
  }