Apache Lucene open-source search software
tests: improve stack traces
Yonik Seeleyb85bf15d38eb
diff --git a/solr/core/src/java/org/apache/solr/core/Diagnostics.java b/solr/core/src/java/org/apache/solr/core/Diagnostics.javanew file mode 100644index 00000000000..c1cc5787ad2--- /dev/null+++ b/solr/core/src/java/org/apache/solr/core/Diagnostics.java@@ -0,0 +1,42 @@+package org.apache.solr.core;+/*+ * 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.+ */+++import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++import java.lang.management.ManagementFactory;+import java.lang.management.ThreadInfo;++public class Diagnostics {+ protected static Logger log = LoggerFactory.getLogger(Diagnostics.class);++ public static void logThreadDumps(String message) {+ StringBuilder sb = new StringBuilder(32768);+ if (message == null) message = "============ THREAD DUMP REQUESTED ============";+ sb.append(message);+ sb.append("\n");+ ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);+ for (ThreadInfo info : threads) {+ sb.append(info);+ // sb.append("\n");+ }+ log.error(sb.toString());+ }++}diff --git a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.javaindex 5964ca66343..c5ff64be114 100644--- a/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java+++ b/solr/test-framework/src/java/org/apache/solr/cloud/AbstractDistribZkTestBase.java@@ -29,6 +29,7 @@ import org.apache.solr.common.cloud.Replica;import org.apache.solr.common.cloud.Slice;import org.apache.solr.common.cloud.SolrZkClient;import org.apache.solr.common.cloud.ZkStateReader;+import org.apache.solr.core.Diagnostics;import org.apache.solr.servlet.SolrDispatchFilter;import org.apache.zookeeper.KeeperException;import org.junit.After;@@ -160,17 +161,9 @@ public abstract class AbstractDistribZkTestBase extends BaseDistributedSearchTesif (!sawLiveRecovering) {if (verbose) System.out.println("no one is recoverying");} else {- if (verbose) System.out- .println("Gave up waiting for recovery to finish..");+ if (verbose) System.out.println("Gave up waiting for recovery to finish..");if (failOnTimeout) {- Map<Thread,StackTraceElement[]> stackTraces = Thread.getAllStackTraces();- for (Map.Entry<Thread,StackTraceElement[]> entry : stackTraces.entrySet()) {- System.out.println("");- System.out.println(entry.getKey().toString());- for (StackTraceElement st : entry.getValue()) {- System.out.println(st);- }- }+ Diagnostics.logThreadDumps("Gave up waiting for recovery to finish. THREAD DUMP:");printLayout();fail("There are still nodes recoverying - waited for " + timeoutSeconds + " seconds");// won't get here