Esempio n. 1
0
  @Test(timeout = 10000)
  public void testOnBackpressureDrop() {
    long t = System.currentTimeMillis();
    for (int i = 0; i < 100; i++) {
      // stop the test if we are getting close to the timeout because slow machines
      // may not get through 100 iterations
      if (System.currentTimeMillis() - t > TimeUnit.SECONDS.toMillis(9)) {
        break;
      }
      int NUM = (int) (RxRingBuffer.SIZE * 1.1); // > 1 so that take doesn't prevent buffer overflow
      AtomicInteger c = new AtomicInteger();
      TestSubscriber<Integer> ts = new TestSubscriber<Integer>();
      firehose(c)
          .onBackpressureDrop()
          .observeOn(Schedulers.computation())
          .map(SLOW_PASS_THRU)
          .take(NUM)
          .subscribe(ts);
      ts.awaitTerminalEvent();
      ts.assertNoErrors();

      List<Integer> onNextEvents = ts.getOnNextEvents();
      assertEquals(NUM, onNextEvents.size());

      Integer lastEvent = onNextEvents.get(NUM - 1);

      System.out.println(
          "testOnBackpressureDrop => Received: "
              + onNextEvents.size()
              + "  Emitted: "
              + c.get()
              + " Last value: "
              + lastEvent);
      // it drop, so we should get some number far higher than what would have sequentially
      // incremented
      assertTrue(NUM - 1 <= lastEvent.intValue());
    }
  }
 static {
   String wp = System.getProperty("rx.just.strong-mode", "false");
   STRONG_MODE = Boolean.valueOf(wp);
 }