Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,17 @@ private <T> T runWithTimeout(Invocation<T> invocation, ExtensionContext ctx) thr
} catch (ExecutionException e) {
throw ExceptionUtils.throwAsUncheckedException(e.getCause());
} catch (TimeoutException e) {

printThreadDump();
throw new JUnitException(
"Test " + ctx.getDisplayName() + " timed out, deadline is " + deadline, e);
}
}

private void printThreadDump() {
LOG.info("====> TEST TIMED OUT. PRINTING THREAD DUMP. <====");
LOG.info(TimedOutTestsListener.buildThreadDiagnosticString());
}

@Override
public void interceptBeforeAllMethod(Invocation<Void> invocation,
ReflectiveInvocationContext<Method> invocationContext, ExtensionContext extensionContext)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hbase;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

import org.apache.hadoop.hbase.testclassification.MiscTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag(MiscTests.TAG)
@Tag(SmallTests.TAG)
public class TestBuildThreadDiagnosticString {

@Test
public void test() {
String threadDump = TimedOutTestsListener.buildThreadDiagnosticString();
System.out.println(threadDump);
assertThat(threadDump,
containsString(getClass().getName() + ".test(" + getClass().getSimpleName() + ".java:"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import java.util.Map;
import org.junit.runner.notification.Failure;
Expand All @@ -40,7 +40,10 @@
*/
public class TimedOutTestsListener extends RunListener {

static final String TEST_TIMED_OUT_PREFIX = "test timed out after";
private static final String TEST_TIMED_OUT_PREFIX = "test timed out after";

private static final DateTimeFormatter TIMESTAMP_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS Z").withZone(ZoneId.systemDefault());
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date pattern 'HH:mm:ss' uses 24-hour format, but the original SimpleDateFormat used 'hh:mm:ss' which is 12-hour format. This changes the timestamp output format and may break existing log parsing or expectations.

Suggested change
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss,SSS Z").withZone(ZoneId.systemDefault());
DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss,SSS Z").withZone(ZoneId.systemDefault());

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional, the old style uses 12 hour format but does not include AM/PM, I guess the original author also wanted to use HH instead of hh.


private static String INDENT = " ";

Expand All @@ -67,13 +70,11 @@ public void testFailure(Failure failure) throws Exception {
output.flush();
}

@SuppressWarnings("JavaUtilDate")
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(String.format("Timestamp: %s", TIMESTAMP_FORMATTER.format(Instant.now())));
output.println();
output.println(buildThreadDump());

Expand All @@ -87,7 +88,7 @@ public static String buildThreadDiagnosticString() {
return sw.toString();
}

static String buildThreadDump() {
private static String buildThreadDump() {
StringBuilder dump = new StringBuilder();
Map<Thread, StackTraceElement[]> stackTraces = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> e : stackTraces.entrySet()) {
Expand All @@ -109,7 +110,7 @@ static String buildThreadDump() {
return dump.toString();
}

static String buildDeadlockInfo() {
private static String buildDeadlockInfo() {
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long[] threadIds = threadBean.findMonitorDeadlockedThreads();
if (threadIds != null && threadIds.length > 0) {
Expand Down