當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。