当前位置: 首页>>代码示例>>Java>>正文


Java LogThrowable.getCause方法代码示例

本文整理汇总了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;
}
 
开发者ID:apache,项目名称:twill,代码行数:15,代码来源:LogThrowableCodec.java

示例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());
}
 
开发者ID:apache,项目名称:twill,代码行数:57,代码来源:LogHandlerTestRun.java

示例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());
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:57,代码来源:LogHandlerTestRun.java


注:本文中的org.apache.twill.api.logging.LogThrowable.getCause方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。