Example #1
0
  @Test
  public void successMonitor() throws Exception {
    ProducerToken token = ProducerToken.create(SimpleProducerModule_SettableFutureStrFactory.class);

    SettableFuture<String> strFuture = SettableFuture.create();
    SettableFuture<SettableFuture<String>> strFutureFuture = SettableFuture.create();
    Producer<SettableFuture<String>> strFutureProducer = producerOfFuture(strFutureFuture);
    Producer<String> producer =
        new SimpleProducerModule_SettableFutureStrFactory(
            executorProvider, componentMonitorProvider, strFutureProducer);
    assertThat(producer.get().isDone()).isFalse();

    InOrder order = inOrder(componentMonitor, monitor);
    order.verify(componentMonitor).producerMonitorFor(token);

    strFutureFuture.set(strFuture);
    order.verify(monitor).methodStarting();
    order.verify(monitor).methodFinished();
    assertThat(producer.get().isDone()).isFalse();

    strFuture.set("monkey");
    assertThat(producer.get().get()).isEqualTo("monkey");
    order.verify(monitor).succeeded("monkey");

    order.verifyNoMoreInteractions();
  }
Example #2
0
  @Test
  public void failureMonitor() throws Exception {
    ProducerToken token = ProducerToken.create(SimpleProducerModule_SettableFutureStrFactory.class);

    SettableFuture<String> strFuture = SettableFuture.create();
    SettableFuture<SettableFuture<String>> strFutureFuture = SettableFuture.create();
    Producer<SettableFuture<String>> strFutureProducer = producerOfFuture(strFutureFuture);
    Producer<String> producer =
        new SimpleProducerModule_SettableFutureStrFactory(
            executorProvider, componentMonitorProvider, strFutureProducer);
    assertThat(producer.get().isDone()).isFalse();

    InOrder order = inOrder(componentMonitor, monitor);
    order.verify(componentMonitor).producerMonitorFor(token);

    strFutureFuture.set(strFuture);
    order.verify(monitor).methodStarting();
    order.verify(monitor).methodFinished();
    assertThat(producer.get().isDone()).isFalse();

    Throwable t = new RuntimeException("monkey");
    strFuture.setException(t);
    try {
      producer.get().get();
      fail();
    } catch (ExecutionException e) {
      assertThat(e.getCause()).isSameAs(t);
      order.verify(monitor).failed(t);
    }

    order.verifyNoMoreInteractions();
  }
Example #3
0
 @Test
 public void noArgMethod() throws Exception {
   ProducerToken token = ProducerToken.create(SimpleProducerModule_StrFactory.class);
   Producer<String> producer =
       new SimpleProducerModule_StrFactory(executorProvider, componentMonitorProvider);
   assertThat(producer.get().get()).isEqualTo("str");
   InOrder order = inOrder(componentMonitor, monitor);
   order.verify(componentMonitor).producerMonitorFor(token);
   order.verify(monitor).methodStarting();
   order.verify(monitor).methodFinished();
   order.verify(monitor).succeeded("str");
   order.verifyNoMoreInteractions();
 }
Example #4
0
  @Test
  public void failureMonitorDueToThrowingProducer() throws Exception {
    ProducerToken token = ProducerToken.create(SimpleProducerModule_ThrowingProducerFactory.class);

    Producer<String> producer =
        new SimpleProducerModule_ThrowingProducerFactory(
            executorProvider, componentMonitorProvider);
    assertThat(producer.get().isDone()).isTrue();

    InOrder order = inOrder(componentMonitor, monitor);
    order.verify(componentMonitor).producerMonitorFor(token);

    order.verify(monitor).methodStarting();
    order.verify(monitor).methodFinished();

    try {
      producer.get().get();
      fail();
    } catch (ExecutionException e) {
      order.verify(monitor).failed(e.getCause());
    }

    order.verifyNoMoreInteractions();
  }