mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-06 13:08:29 +00:00
Do not dump stack traces of threads on test failure
Reverts 878301c795e6ad2c47c620c893b3324a564e0d91, relates #12425
This commit is contained in:
parent
9e6115b066
commit
3dcb1a81c8
@ -51,7 +51,6 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.env.NodeEnvironment;
|
import org.elasticsearch.env.NodeEnvironment;
|
||||||
import org.elasticsearch.search.MockSearchService;
|
import org.elasticsearch.search.MockSearchService;
|
||||||
import org.elasticsearch.test.junit.listeners.AssertionErrorThreadDumpPrinter;
|
|
||||||
import org.elasticsearch.test.junit.listeners.LoggingListener;
|
import org.elasticsearch.test.junit.listeners.LoggingListener;
|
||||||
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
|
import org.elasticsearch.test.junit.listeners.ReproduceInfoPrinter;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
@ -68,18 +67,12 @@ import java.nio.file.DirectoryStream;
|
|||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.BooleanSupplier;
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.function.Predicate;
|
|
||||||
|
|
||||||
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
|
import static org.elasticsearch.common.util.CollectionUtils.arrayAsArrayList;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
@ -89,8 +82,7 @@ import static org.hamcrest.Matchers.equalTo;
|
|||||||
*/
|
*/
|
||||||
@Listeners({
|
@Listeners({
|
||||||
ReproduceInfoPrinter.class,
|
ReproduceInfoPrinter.class,
|
||||||
LoggingListener.class,
|
LoggingListener.class
|
||||||
AssertionErrorThreadDumpPrinter.class
|
|
||||||
})
|
})
|
||||||
@ThreadLeakScope(Scope.SUITE)
|
@ThreadLeakScope(Scope.SUITE)
|
||||||
@ThreadLeakLingering(linger = 5000) // 5 sec lingering
|
@ThreadLeakLingering(linger = 5000) // 5 sec lingering
|
||||||
@ -558,7 +550,44 @@ public abstract class ESTestCase extends LuceneTestCase {
|
|||||||
protected static final void printStackDump(ESLogger logger) {
|
protected static final void printStackDump(ESLogger logger) {
|
||||||
// print stack traces if we can't create any native thread anymore
|
// print stack traces if we can't create any native thread anymore
|
||||||
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
|
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
|
||||||
logger.error(StackTraces.formatThreadStacks(allStackTraces));
|
logger.error(formatThreadStacks(allStackTraces));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Dump threads and their current stack trace. */
|
||||||
|
public static String formatThreadStacks(Map<Thread, StackTraceElement[]> threads) {
|
||||||
|
StringBuilder message = new StringBuilder();
|
||||||
|
int cnt = 1;
|
||||||
|
final Formatter f = new Formatter(message, Locale.ENGLISH);
|
||||||
|
for (Map.Entry<Thread, StackTraceElement[]> e : threads.entrySet()) {
|
||||||
|
if (e.getKey().isAlive()) {
|
||||||
|
f.format(Locale.ENGLISH, "\n %2d) %s", cnt++, threadName(e.getKey())).flush();
|
||||||
|
}
|
||||||
|
if (e.getValue().length == 0) {
|
||||||
|
message.append("\n at (empty stack)");
|
||||||
|
} else {
|
||||||
|
for (StackTraceElement ste : e.getValue()) {
|
||||||
|
message.append("\n at ").append(ste);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return message.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String threadName(Thread t) {
|
||||||
|
return "Thread[" +
|
||||||
|
"id=" + t.getId() +
|
||||||
|
", name=" + t.getName() +
|
||||||
|
", state=" + t.getState() +
|
||||||
|
", group=" + groupName(t.getThreadGroup()) +
|
||||||
|
"]";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String groupName(ThreadGroup threadGroup) {
|
||||||
|
if (threadGroup == null) {
|
||||||
|
return "{null group}";
|
||||||
|
} else {
|
||||||
|
return threadGroup.getName();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,63 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch 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.elasticsearch.test;
|
|
||||||
|
|
||||||
import java.util.Formatter;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class StackTraces {
|
|
||||||
/** Dump threads and their current stack trace. */
|
|
||||||
public static String formatThreadStacks(Map<Thread, StackTraceElement[]> threads) {
|
|
||||||
StringBuilder message = new StringBuilder();
|
|
||||||
int cnt = 1;
|
|
||||||
final Formatter f = new Formatter(message, Locale.ENGLISH);
|
|
||||||
for (Map.Entry<Thread, StackTraceElement[]> e : threads.entrySet()) {
|
|
||||||
if (e.getKey().isAlive()) {
|
|
||||||
f.format(Locale.ENGLISH, "\n %2d) %s", cnt++, threadName(e.getKey())).flush();
|
|
||||||
}
|
|
||||||
if (e.getValue().length == 0) {
|
|
||||||
message.append("\n at (empty stack)");
|
|
||||||
} else {
|
|
||||||
for (StackTraceElement ste : e.getValue()) {
|
|
||||||
message.append("\n at ").append(ste);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return message.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String groupName(ThreadGroup threadGroup) {
|
|
||||||
if (threadGroup == null) {
|
|
||||||
return "{null group}";
|
|
||||||
} else {
|
|
||||||
return threadGroup.getName();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String threadName(Thread t) {
|
|
||||||
return "Thread[" +
|
|
||||||
"id=" + t.getId() +
|
|
||||||
", name=" + t.getName() +
|
|
||||||
", state=" + t.getState() +
|
|
||||||
", group=" + groupName(t.getThreadGroup()) +
|
|
||||||
"]";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* Licensed to Elasticsearch under one or more contributor
|
|
||||||
* license agreements. See the NOTICE file distributed with
|
|
||||||
* this work for additional information regarding copyright
|
|
||||||
* ownership. Elasticsearch 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.elasticsearch.test.junit.listeners;
|
|
||||||
|
|
||||||
import org.elasticsearch.test.StackTraces;
|
|
||||||
import org.junit.runner.notification.Failure;
|
|
||||||
import org.junit.runner.notification.RunListener;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class AssertionErrorThreadDumpPrinter extends RunListener {
|
|
||||||
@Override
|
|
||||||
public void testFailure(Failure failure) throws Exception {
|
|
||||||
if (failure.getException() instanceof AssertionError) {
|
|
||||||
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
|
|
||||||
String threadStacks = StackTraces.formatThreadStacks(allStackTraces);
|
|
||||||
System.err.println(threadStacks);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user