本文整理汇总了Java中org.apache.twill.api.logging.LogThrowable.getCause方法的典型用法代码示例。如果您正苦于以下问题:Java LogThrowable.getCause方法的具体用法?Java LogThrowable.getCause怎么用?Java LogThrowable.getCause使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.twill.api.logging.LogThrowable
的用法示例。
在下文中一共展示了LogThrowable.getCause方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.apache.twill.api.logging.LogThrowable; //导入方法依赖的package包/类
@Override
public JsonElement serialize(LogThrowable throwable, Type typeOfSrc, JsonSerializationContext context) {
JsonObject json = new JsonObject();
json.addProperty("className", throwable.getClassName());
json.addProperty("message", throwable.getMessage());
json.add("stackTraces", context.serialize(throwable.getStackTraces(), StackTraceElement[].class));
LogThrowable cause = throwable.getCause();
if (cause != null) {
json.add("cause", context.serialize(cause, LogThrowable.class));
}
return json;
}
示例2: testLogHandler
import org.apache.twill.api.logging.LogThrowable; //导入方法依赖的package包/类
@Test
public void testLogHandler() throws ExecutionException, InterruptedException, TimeoutException {
final CountDownLatch latch = new CountDownLatch(3);
final Queue<LogThrowable> throwables = new ConcurrentLinkedQueue<LogThrowable>();
final Queue<String> runnables = new ConcurrentLinkedQueue<String>();
LogHandler logHandler = new LogHandler() {
@Override
public void onLog(LogEntry logEntry) {
// Would expect logs from AM and the runnable.
if (logEntry.getSourceClassName().contains("LogHandlerTestRun")) {
runnables.add(logEntry.getRunnableName());
}
// Runnable name for AM should be null
if (logEntry.getSourceClassName().contains("ApplicationMasterService")) {
Assert.assertNull(logEntry.getRunnableName());
}
if (logEntry.getMessage().startsWith("Starting runnable " + LogRunnable.class.getSimpleName())) {
latch.countDown();
} else if (logEntry.getMessage().equals("Running")) {
latch.countDown();
} else if (logEntry.getMessage().equals("Got exception") && logEntry.getThrowable() != null) {
throwables.add(logEntry.getThrowable());
latch.countDown();
}
}
};
TwillRunner runner = getTwillRunner();
TwillController controller = runner.prepare(new LogRunnable())
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
.addLogHandler(logHandler)
.start();
try {
Assert.assertTrue(latch.await(100, TimeUnit.SECONDS));
} finally {
controller.terminate().get(120, TimeUnit.SECONDS);
}
// Verify the runnable names
Assert.assertEquals(2, runnables.size());
Assert.assertArrayEquals(new String[] {"LogRunnable", "LogRunnable"}, runnables.toArray());
// Verify the log throwable
Assert.assertEquals(1, throwables.size());
LogThrowable t = throwables.poll();
Assert.assertEquals(RuntimeException.class.getName(), t.getClassName());
Assert.assertNotNull(t.getCause());
Assert.assertEquals(5, t.getStackTraces().length);
t = t.getCause();
Assert.assertEquals(Exception.class.getName(), t.getClassName());
Assert.assertEquals("Exception", t.getMessage());
}
示例3: testLogHandler
import org.apache.twill.api.logging.LogThrowable; //导入方法依赖的package包/类
@Test
public void testLogHandler() throws ExecutionException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(3);
final Queue<LogThrowable> throwables = new ConcurrentLinkedQueue<LogThrowable>();
final Queue<String> runnables = new ConcurrentLinkedQueue<String>();
LogHandler logHandler = new LogHandler() {
@Override
public void onLog(LogEntry logEntry) {
// Would expect logs from AM and the runnable.
if (logEntry.getSourceClassName().contains("LogHandlerTestRun")) {
runnables.add(logEntry.getRunnableName());
}
// Runnable name for AM should be null
if (logEntry.getSourceClassName().contains("ApplicationMasterService")) {
Assert.assertNull(logEntry.getRunnableName());
}
if (logEntry.getMessage().startsWith("Starting runnable " + LogRunnable.class.getSimpleName())) {
latch.countDown();
} else if (logEntry.getMessage().equals("Running")) {
latch.countDown();
} else if (logEntry.getMessage().equals("Got exception") && logEntry.getThrowable() != null) {
throwables.add(logEntry.getThrowable());
latch.countDown();
}
}
};
TwillRunner runner = YarnTestUtils.getTwillRunner();
TwillController controller = runner.prepare(new LogRunnable())
.addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
.addLogHandler(logHandler)
.start();
try {
Assert.assertTrue(latch.await(100, TimeUnit.SECONDS));
} finally {
controller.stopAndWait();
}
// Verify the runnable names
Assert.assertEquals(2, runnables.size());
Assert.assertArrayEquals(new String[] {"LogRunnable", "LogRunnable"}, runnables.toArray());
// Verify the log throwable
Assert.assertEquals(1, throwables.size());
LogThrowable t = throwables.poll();
Assert.assertEquals(RuntimeException.class.getName(), t.getClassName());
Assert.assertNotNull(t.getCause());
Assert.assertEquals(5, t.getStackTraces().length);
t = t.getCause();
Assert.assertEquals(Exception.class.getName(), t.getClassName());
Assert.assertEquals("Exception", t.getMessage());
}