@Override public void awaitTerminated() throws ExecutionException { delegate.awaitTerminated(); }
@Override public void awaitTerminated() throws ExecutionException { delegate.awaitTerminated(); }
@Override public void awaitTerminated(long timeout, TimeUnit timeoutUnit) throws TimeoutException, ExecutionException { delegate.awaitTerminated(timeout, timeoutUnit); }
@Override public void awaitTerminated(long timeout, TimeUnit timeoutUnit) throws TimeoutException, ExecutionException { delegate.awaitTerminated(timeout, timeoutUnit); }
try { controller.terminate(); controller.awaitTerminated(); } catch (ExecutionException e) { LOG.warn("Exception while Stopping one extra instance of {} - {}", Constants.Service.MASTER_SERVICES, e);
twillController.terminate(); try { twillController.awaitTerminated(); LOG.info("Master twill application terminated successfully"); } catch (ExecutionException e) {
controller.awaitTerminated(); } catch (final ExecutionException e) { e.printStackTrace();
controller.awaitTerminated(); } catch (ExecutionException e) { e.printStackTrace();
controller.awaitTerminated(); } catch (ExecutionException e) { LOG.error("Error", e);
controller.awaitTerminated(120, TimeUnit.SECONDS);
@Test public void testKilled() throws IOException, InterruptedException, TimeoutException, ExecutionException { // Create a parent folder to be written by EventHandler File parentFolder = TMP_FOLDER.newFolder(); parentFolder.setWritable(true, false); TwillController controller = getTwillRunner().prepare(new SleepApplication(parentFolder.getAbsolutePath())) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); // Wait for the runnable to run and create runFile within 120 secs File runFile = new File(parentFolder, RUN_FILE); Stopwatch stopwatch = new Stopwatch().start(); while (!runFile.exists() && stopwatch.elapsedTime(TimeUnit.SECONDS) < 120) { TimeUnit.SECONDS.sleep(1); } Assert.assertTrue(runFile.exists()); // Terminate the app once the runnable runs controller.terminate(); controller.awaitTerminated(120, TimeUnit.SECONDS); // EventHandler#killed() method should be called to create a file Assert.assertTrue(new File(parentFolder.getAbsolutePath(), KILLED_FILE).exists()); // EventHandler#completed() method should not be called Assert.assertFalse(new File(parentFolder.getAbsolutePath(), COMPLETED_FILE).exists()); // EventHandler#aborted() method should not be called Assert.assertFalse(new File(parentFolder.getAbsolutePath(), ABORTED_FILE).exists()); }
@Test public void testProvisionTimeout() throws InterruptedException, ExecutionException, TimeoutException, IOException { TwillRunner runner = getTwillRunner(); // Create a parent folder to be written by EventHandler#aborted() File parentFolder = TMP_FOLDER.newFolder(); parentFolder.setWritable(true, false); TwillController controller = runner.prepare(new TimeoutApplication(parentFolder.getAbsolutePath())) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); // The provision should failed in 30 seconds after AM started, which AM could took a while to start. // Hence we give 90 seconds max time here. try { controller.awaitTerminated(90, TimeUnit.SECONDS); // EventHandler#aborted() method should be called to create a file Assert.assertTrue(new File(parentFolder.getAbsolutePath(), ABORTED_FILE).exists()); String[] abortedFiles = parentFolder.list(); Assert.assertNotNull(abortedFiles); Assert.assertEquals(1, abortedFiles.length); } finally { // If it timeout, kill the app as cleanup. controller.kill(); } }
@Test public void testInitFail() throws InterruptedException, ExecutionException, TimeoutException { TwillRunner runner = getTwillRunner(); final CountDownLatch logLatch = new CountDownLatch(1); // Verify that it receives the exception log entry that thrown when runnable initialize LogHandler logVerifyHandler = new LogHandler() { @Override public void onLog(LogEntry logEntry) { if (logEntry.getMessage().endsWith("exited abnormally with state COMPLETE, exit code 10.")) { logLatch.countDown(); } } }; TwillController controller = runner .prepare(new InitFailRunnable()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out))) .addLogHandler(logVerifyHandler) .start(); controller.awaitTerminated(2, TimeUnit.MINUTES); Assert.assertTrue(logLatch.await(10, TimeUnit.SECONDS)); }
@Test public void testAppSessionExpire() throws InterruptedException, ExecutionException, TimeoutException { TwillRunner runner = getTwillRunner(); TwillController controller = runner.prepare(new SleepRunnable(600)) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); final CountDownLatch runLatch = new CountDownLatch(1); controller.onRunning(new Runnable() { @Override public void run() { runLatch.countDown(); } }, Threads.SAME_THREAD_EXECUTOR); // Wait for application running Assert.assertTrue(runLatch.await(60, TimeUnit.SECONDS)); // Find the app master ZK session and expire it two times, 10 seconds apart. for (int i = 0; i < 2; i++) { Assert.assertTrue(expireAppMasterZKSession(controller, 10, TimeUnit.SECONDS)); try { controller.awaitTerminated(10, TimeUnit.SECONDS); Assert.fail("Unexpected application termination."); } catch (TimeoutException e) { // OK, expected. } } controller.terminate().get(120, TimeUnit.SECONDS); }
private void maxRetriesRun(final int instances) throws TimeoutException, ExecutionException { TwillRunner runner = getTwillRunner(); final int maxRetries = 3; final AtomicInteger retriesSeen = new AtomicInteger(0); ResourceSpecification resource = ResourceSpecification.Builder.with().setVirtualCores(1) .setMemory(512, ResourceSpecification.SizeUnit.MEGA).setInstances(instances).build(); TwillController controller = runner.prepare(new FailingServer(), resource) .withMaxRetries(FailingServer.class.getSimpleName(), maxRetries) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .addLogHandler(new LogHandler() { @Override public void onLog(LogEntry logEntry) { if (logEntry.getMessage().contains("retries for instance")) { retriesSeen.incrementAndGet(); } } }) .start(); controller.awaitTerminated(2, TimeUnit.MINUTES); Assert.assertEquals(maxRetries * instances, retriesSeen.get()); }
@Test public void testTaskCompleted() throws InterruptedException, TimeoutException, ExecutionException { TwillRunner twillRunner = getTwillRunner(); TwillController controller = twillRunner.prepare(new SleepTask(), ResourceSpecification.Builder.with() .setVirtualCores(1) .setMemory(512, ResourceSpecification.SizeUnit.MEGA) .setInstances(3).build()) .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true))) .start(); final CountDownLatch runLatch = new CountDownLatch(1); controller.onRunning(new Runnable() { @Override public void run() { runLatch.countDown(); } }, Threads.SAME_THREAD_EXECUTOR); Assert.assertTrue(runLatch.await(1, TimeUnit.MINUTES)); controller.awaitTerminated(1, TimeUnit.MINUTES); Assert.assertEquals(ServiceController.TerminationStatus.SUCCEEDED, controller.getTerminationStatus()); }