Main { void invoke(ClientType clientType) { try { LOGGER.info("Starting service."); ExecutorService[] services = ClientServiceFactory.startClientService(_system, clientType, _jobCounter); LOGGER.info("Service started."); Thread currentThread = Thread.currentThread(); while (!currentThread.isInterrupted()) { try { Thread.sleep(500); } catch (InterruptedException ex) { currentThread.interrupt(); break; } } LOGGER.info("Stopping service."); for (ExecutorService s: services) { s.shutdownNow(); try { if (!s.awaitTermination(60000, TimeUnit.MILLISECONDS)) { LOGGER.warn("Shutdown timed out after 60 seconds. Exiting."); } } catch (InterruptedException iex) { LOGGER.warn("Forcing shutdown."); break; } } LOGGER.info("Service stopped."); } catch (Exception ex) { throw new SystemException("There was a problem invoking the committer.", ex); } finally { if (_system != null) { _system.stop(); } LOGGER.info("Finished"); } } Main();   Main(Properties config); static void main(String[] args);  }
@Test(timeout = 20000L) public void testMetricCommitClientInterrupt() throws InterruptedException { final Main main = new Main(getTestConfig(10000)); Thread invoker = new Thread(new Runnable() { @Override public void run() { main.invoke(ClientType.COMMIT_METRICS); } }, "metriccommitclient"); invoker.setPriority(Thread.MIN_PRIORITY); invoker.start(); Thread.sleep(5000); while (invoker.isAlive()) { invoker.join(500); invoker.interrupt(); } }
@Test(timeout = 20000L) public void testAnnotationCommitClientInterrupt() throws InterruptedException { final Main main = new Main(getTestConfig(10000)); Thread invoker = new Thread(new Runnable() { @Override public void run() { main.invoke(ClientType.COMMIT_ANNOTATIONS); } }, "annotationcommitclient"); invoker.setPriority(Thread.MIN_PRIORITY); invoker.start(); Thread.sleep(5000); while (invoker.isAlive()) { invoker.join(500); invoker.interrupt(); } }
@Test(timeout = 20000L) public void testAlertClientInterrupt() throws InterruptedException { final Main main = new Main(getTestConfig(10000)); Thread invoker = new Thread(new Runnable() { @Override public void run() { main.invoke(ClientType.ALERT); } }, "alertclient"); invoker.setPriority(Thread.MIN_PRIORITY); invoker.start(); Thread.sleep(5000); while (invoker.isAlive()) { invoker.join(500); invoker.interrupt(); } }
@Test(timeout = 20000L) public void testSchemaCommitClientInterrupt() throws InterruptedException { final Main main = new Main(getTestConfig(10000)); Thread invoker = new Thread(new Runnable() { @Override public void run() { main.invoke(ClientType.COMMIT_SCHEMA); } }, "schemacommitclient"); invoker.setPriority(Thread.MIN_PRIORITY); invoker.start(); Thread.sleep(5000); while (invoker.isAlive()) { invoker.join(500); invoker.interrupt(); } }