コード例 #1
0
  public void testListenerDoesntDeadlockOnStopAndWaitFromTerminated() throws Exception {
    final NoOpThreadedService service = new NoOpThreadedService();
    service.addListener(
        new Listener() {
          @Override
          public void starting() {}

          @Override
          public void running() {}

          @Override
          public void stopping(State from) {}

          @Override
          public void terminated(State from) {
            service.stopAndWait();
          }

          @Override
          public void failed(State from, Throwable failure) {}
        },
        MoreExecutors.sameThreadExecutor());
    service.startAndWait();

    Thread thread =
        new Thread() {
          @Override
          public void run() {
            service.stopAndWait();
          }
        };
    thread.start();
    thread.join(100);
    assertFalse(thread + " is deadlocked", thread.isAlive());
  }
コード例 #2
0
  public void testListenerDoesntDeadlockOnStartAndWaitFromRunning() throws Exception {
    final NoOpThreadedService service = new NoOpThreadedService();
    service.addListener(
        new Listener() {
          @Override
          public void starting() {}

          @Override
          public void running() {
            service.startAndWait();
          }

          @Override
          public void stopping(State from) {}

          @Override
          public void terminated(State from) {}

          @Override
          public void failed(State from, Throwable failure) {}
        },
        MoreExecutors.sameThreadExecutor());
    service.start().get(10, TimeUnit.MILLISECONDS);
    service.stop();
  }