@Override
  public void run() {
    try {
      coordinator.start();
    } catch (Exception e) {
      LOG.error("Coordinator error during start, exiting thread", e);
      terminated = true;
    }

    while (!terminated) {
      try {
        coordinator.process();
      } catch (Exception e) {
        LOG.error("Coordinator error during process, exiting thread", e);
        terminated = true;
      }
    }

    try {
      coordinator.stop();
    } catch (Exception e) {
      LOG.error("Coordinator error during stop, ignoring", e);
    }
    coordinator = null;
  }
@Test
  public void testRun() {
    Coordinator coordinator = mock(Coordinator.class);
    CoordinatorThread coordinatorThread = new CoordinatorThread(coordinator);

    coordinatorThread.start();

    verify(coordinator, timeout(1000)).start();
    verify(coordinator, timeout(1000).atLeast(1)).process();
    verify(coordinator, times(0)).stop();
    assertThat(coordinatorThread.isTerminated()).isFalse();

    coordinatorThread.terminate();

    verify(coordinator, timeout(1000)).stop();
    assertThat(coordinatorThread.isTerminated()).isTrue();
  }