Java Code Examples for org.apache.ratis.util.ExitUtils#assertNotTerminated()

The following examples show how to use org.apache.ratis.util.ExitUtils#assertNotTerminated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MiniRaftCluster.java    From incubator-ratis with Apache License 2.0 6 votes vote down vote up
public void shutdown() {
  LOG.info("************************************************************** ");
  LOG.info("*** ");
  LOG.info("***     Stopping " + getClass().getSimpleName());
  LOG.info("*** ");
  LOG.info("************************************************************** ");
  LOG.info(printServers());

  // TODO: classes like RaftLog may throw uncaught exception during shutdown (e.g. write after close)
  ExitUtils.setTerminateOnUncaughtException(false);

  final ExecutorService executor = Executors.newFixedThreadPool(servers.size(), Daemon::new);
  getServers().forEach(proxy -> executor.submit(proxy::close));
  try {
    executor.shutdown();
    // just wait for a few seconds
    executor.awaitTermination(5, TimeUnit.SECONDS);
  } catch(InterruptedException e) {
    LOG.warn("shutdown interrupted", e);
  }

  Optional.ofNullable(timer.get()).ifPresent(Timer::cancel);
  ExitUtils.assertNotTerminated();
  LOG.info(getClass().getSimpleName() + " shutdown completed");
}
 
Example 2
Source File: MiniRaftCluster.java    From ratis with Apache License 2.0 6 votes vote down vote up
public void shutdown() {
  LOG.info("************************************************************** ");
  LOG.info("*** ");
  LOG.info("***     Stopping " + getClass().getSimpleName());
  LOG.info("*** ");
  LOG.info("************************************************************** ");
  LOG.info(printServers());

  // TODO: classes like RaftLog may throw uncaught exception during shutdown (e.g. write after close)
  ExitUtils.setTerminateOnUncaughtException(false);

  final ExecutorService executor = Executors.newFixedThreadPool(servers.size(), Daemon::new);
  getServers().forEach(proxy -> executor.submit(proxy::close));
  try {
    executor.shutdown();
    // just wait for a few seconds
    executor.awaitTermination(5, TimeUnit.SECONDS);
  } catch(InterruptedException e) {
    LOG.warn("shutdown interrupted", e);
  }

  Optional.ofNullable(timer.get()).ifPresent(Timer::cancel);
  ExitUtils.assertNotTerminated();
  LOG.info(getClass().getSimpleName() + " shutdown completed");
}
 
Example 3
Source File: BaseTest.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@After
public void assertNoFailures() {
  final Throwable e = firstException.get();
  if (e != null) {
    throw new IllegalStateException("Failed: first exception was set", e);
  }

  ExitUtils.assertNotTerminated();
}
 
Example 4
Source File: LeaderElectionTests.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeLeader() throws Exception {
  SegmentedRaftLogTestUtils.setRaftLogWorkerLogLevel(Level.TRACE);
  LOG.info("Running testChangeLeader");
  final MiniRaftCluster cluster = newCluster(3);
  cluster.start();

  RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId();
  for(int i = 0; i < 10; i++) {
    leader = RaftTestUtil.changeLeader(cluster, leader, IllegalStateException::new);
    ExitUtils.assertNotTerminated();
  }
  SegmentedRaftLogTestUtils.setRaftLogWorkerLogLevel(Level.INFO);
  cluster.shutdown();
}
 
Example 5
Source File: LeaderElectionTests.java    From ratis with Apache License 2.0 5 votes vote down vote up
@Test
public void testChangeLeader() throws Exception {
  RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.TRACE);
  LOG.info("Running testChangeLeader");
  final MiniRaftCluster cluster = newCluster(3);
  cluster.start();

  RaftPeerId leader = RaftTestUtil.waitForLeader(cluster).getId();
  for(int i = 0; i < 10; i++) {
    leader = RaftTestUtil.changeLeader(cluster, leader);
    ExitUtils.assertNotTerminated();
  }
  RaftStorageTestUtils.setRaftLogWorkerLogLevel(Level.INFO);
  cluster.shutdown();
}
 
Example 6
Source File: BaseTest.java    From ratis with Apache License 2.0 4 votes vote down vote up
@After
public void assertNotTerminated() {
  ExitUtils.assertNotTerminated();
}