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();
    }
  }
 @Test(expected = NullPointerException.class)
 public void testInvokingTimerWithNullMethodName() throws Throwable {
   try {
     helper.invokeTimerFor(TestAggregator.class, null);
   } catch (RuntimeException e) {
     assertThat(e.getClass().getName(), is(RuntimeException.class.getName()));
     throw e.getCause();
   }
 }
 @Test(expected = NullPointerException.class)
 public void testInvokingNotExistentTimer() throws Throwable {
   try {
     helper.invokeTimerFor(TestAggregator.class, "blkjhsdgfksdyufgks");
   } catch (RuntimeException e) {
     assertThat(e.getClass().getName(), is(RuntimeException.class.getName()));
     throw e.getCause();
   }
 }
Exemplo n.º 4
0
  @Test
  public void shouldReThrowWebServerException() throws IOException, InterruptedException {
    WebDaemon webDaemon = spy(new WebDaemon());
    ReflectionUtils.setField(main, "webDaemon", webDaemon);

    InterruptedException toBeThrown = new InterruptedException("Ouch!");
    doThrow(toBeThrown).when(webDaemon).start(any(ConfigurationForServer.class));

    try {
      main.runMain(new String[] {"-ws", "--port=1234"});
      fail("Should have thrown exception");
    } catch (RuntimeException rte) {
      assertThat((InterruptedException) rte.getCause(), sameInstance(toBeThrown));
    }
  }