From 24bed6b3fbb54a20ef67201c160de649421cdd51 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Mon, 12 Feb 2018 18:12:08 -0800 Subject: [PATCH] HBASE-19986 If HBaseTestClassRule timesout a test, thread dump; ADDENDUM; white-space, checkstyle, and rb feedback by Duo --- .../hadoop/hbase/HBaseClassTestRule.java | 2 +- .../org/apache/hadoop/hbase/TestTimeout.java | 9 +++----- .../hadoop/hbase/TimedOutTestsListener.java | 22 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java index b964872ccbd..d47b21359e0 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/HBaseClassTestRule.java @@ -1,4 +1,4 @@ -/* +/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java index 495667c8028..d547ddb4204 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestTimeout.java @@ -33,7 +33,7 @@ public class TestTimeout { @Test public void run1() throws InterruptedException { - Thread.sleep(100); + Thread.sleep(100); } /** @@ -46,14 +46,11 @@ public class TestTimeout { Thread t = new Thread("HangingThread") { public void run() { synchronized(this) { - while(true) { - } + while(true) {} } } }; t.start(); - while (true) { - // Just hang out too. - } + while (true) {} } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java index d5c87f3992e..643058c9ac6 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TimedOutTestsListener.java @@ -40,15 +40,15 @@ import org.junit.runner.notification.RunListener; public class TimedOutTestsListener extends RunListener { static final String TEST_TIMED_OUT_PREFIX = "test timed out after"; - + private static String INDENT = " "; private final PrintWriter output; - + public TimedOutTestsListener() { this.output = new PrintWriter(System.err); } - + public TimedOutTestsListener(PrintWriter output) { this.output = output; } @@ -63,16 +63,16 @@ public class TimedOutTestsListener extends RunListener { } output.flush(); } - + public static String buildThreadDiagnosticString() { StringWriter sw = new StringWriter(); PrintWriter output = new PrintWriter(sw); - + DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS"); output.println(String.format("Timestamp: %s", dateFormat.format(new Date()))); output.println(); output.println(buildThreadDump()); - + String deadlocksInfo = buildDeadlockInfo(); if (deadlocksInfo != null) { output.println("====> DEADLOCKS DETECTED <===="); @@ -106,28 +106,28 @@ public class TimedOutTestsListener extends RunListener { } return dump.toString(); } - + static String buildDeadlockInfo() { ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); long[] threadIds = threadBean.findMonitorDeadlockedThreads(); if (threadIds != null && threadIds.length > 0) { StringWriter stringWriter = new StringWriter(); PrintWriter out = new PrintWriter(stringWriter); - + ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true); for (ThreadInfo ti : infos) { printThreadInfo(ti, out); printLockInfo(ti.getLockedSynchronizers(), out); out.println(); } - + out.close(); return stringWriter.toString(); } else { return null; } } - + private static void printThreadInfo(ThreadInfo ti, PrintWriter out) { // print thread information printThread(ti, out); @@ -173,5 +173,5 @@ public class TimedOutTestsListener extends RunListener { } out.println(); } - + }