Exemplo n.º 1
0
  @Test
  public void testInterruptTerminalEventAwaitTimed() {
    TestSubscriber<Integer> ts = TestSubscriber.create();

    final Thread t0 = Thread.currentThread();
    Worker w = Schedulers.computation().createWorker();
    try {
      w.schedule(
          new Action0() {
            @Override
            public void call() {
              t0.interrupt();
            }
          },
          200,
          TimeUnit.MILLISECONDS);

      try {
        ts.awaitTerminalEvent(5, TimeUnit.SECONDS);
        fail("Did not interrupt wait!");
      } catch (RuntimeException ex) {
        if (!(ex.getCause() instanceof InterruptedException)) {
          fail("The cause is not InterruptedException! " + ex.getCause());
        }
      }
    } finally {
      w.unsubscribe();
    }
  }
Exemplo n.º 2
0
 @Test
 public void testAwaitTerminalEventWithDuration() {
   TestSubscriber<Object> ts = new TestSubscriber<Object>();
   Observable.just(1).subscribe(ts);
   ts.awaitTerminalEvent(1, TimeUnit.SECONDS);
   ts.assertTerminalEvent();
 }
Exemplo n.º 3
0
  @Test(timeout = 1000)
  public void testOnErrorCrashCountsDownLatch() {
    TestObserver<Integer> to =
        new TestObserver<Integer>() {
          @Override
          public void onError(Throwable e) {
            throw new TestException();
          }
        };
    TestSubscriber<Integer> ts = TestSubscriber.create(to);

    try {
      ts.onError(new RuntimeException());
    } catch (TestException ex) {
      // expected
    }

    ts.awaitTerminalEvent();
  }