Github user chtyim commented on a diff in the pull request:
https://github.com/apache/incubator-twill/pull/46#discussion_r32979605
--- Diff:
twill-yarn/src/test/java/org/apache/twill/yarn/LogLevelTestRun.java ---
@@ -68,17 +74,73 @@ public void stop() {
}
}
+ /**
+ * A test TwillApplication to test setting log level to DEBUG.
+ */
+ public static final class LogLevelTestApplication implements
TwillApplication {
+
+ @Override
+ public TwillSpecification configure() {
+ return TwillSpecification.Builder.with()
+ .setName(LogLevelTestApplication.class.getSimpleName())
+ .withRunnable()
+ .add(LogLevelTestRunnable.class.getSimpleName(), new
LogLevelTestRunnable()).noLocalFiles()
+ .anyOrder()
+ .build();
+ }
+ }
+
@Test
public void testDebugLogLevel()throws Exception {
YarnTwillRunnerService runner = getTwillRunner();
runner.start();
- TwillController controller = runner.prepare(new LogLevelTestRunnable())
+ // Set log level to DEBUG
+ TwillController controller = runner.prepare(new
LogLevelTestApplication())
.setLogLevel(LogEntry.Level.DEBUG)
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out)))
.start();
+ // Lets wait until the service is running
+ final CountDownLatch running = new CountDownLatch(1);
+ controller.onRunning(new Runnable() {
+ @Override
+ public void run() {
+ running.countDown();
+ }
+ }, Threads.SAME_THREAD_EXECUTOR);
+ Assert.assertTrue(running.await(200, TimeUnit.SECONDS));
+
+ String logLevel = waitForLogLevel(controller,
LogLevelTestRunnable.class.getSimpleName(), 30);
+
+ // Verify we got DEBUG log level.
+ Assert.assertEquals(LogEntry.Level.DEBUG.toString(), logLevel);
+
controller.terminate().get(120, TimeUnit.SECONDS);
+
+ // Sleep a bit for full cleanup
+ TimeUnit.SECONDS.sleep(2);
}
+ // Need helper method here to wait for getting resource report because
{@link TwillController#getResourceReport()}
+ // could return null if the application has not fully started.
+ private String waitForLogLevel(TwillController controller, String
runnable, int timeLimit)
--- End diff --
better to take a `long, TimeUnit` for the timeout. Also, you can use guava
`Stopwatch` to help tracking time elapse easier.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---