Apache Solr open-source search software
LUCENE-3895: ensure we get a random seed if another thread throws uncaught exception
Robert Muir3a4318dd06d0
diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/SorePoint.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/SorePoint.javaindex b0bfebdee7c..48e888421e4 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/SorePoint.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/SorePoint.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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.+ */+/*** A pointcut-like definition where we should trigger* an assumption or error.diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/SoreType.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/SoreType.javaindex e93940b2a50..a246c99fe49 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/SoreType.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/SoreType.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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.+ */+public enum SoreType {ASSUMPTION,FAILURE,diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.javaindex 72b523a316b..bce5c8d778e 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestExceptionInBeforeClassHooks.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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 java.util.*;import java.util.regex.Matcher;import java.util.regex.Pattern;diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestJUnitRuleOrder.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestJUnitRuleOrder.javaindex 9e5f7d3282b..a04fb0ed540 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestJUnitRuleOrder.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestJUnitRuleOrder.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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 java.util.Arrays;import java.util.Stack;diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestReproduceMessage.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestReproduceMessage.javaindex b7b93b8208f..0122391a83a 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestReproduceMessage.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestReproduceMessage.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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 java.util.Arrays;import org.apache.lucene.util.LuceneTestCase;diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.javanew file mode 100644index 00000000000..9b7700babad--- /dev/null+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSeedFromUncaught.java@@ -0,0 +1,60 @@+package org.apache.lucene.util.junitcompat;++/**+ * 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.apache.lucene.util.LuceneTestCase;+import org.junit.Assert;+import org.junit.Test;+import org.junit.runner.JUnitCore;+import org.junit.runner.Result;++/**+ * Check that uncaught exceptions result in seed info being dumped to+ * console.+ */+public class TestSeedFromUncaught extends WithNestedTests {+ public static class ThrowInUncaught extends AbstractNestedTest {+ @Test+ public void testFoo() throws Exception {+ Thread t = new Thread() {+ @Override+ public void run() {+ throw new RuntimeException("foobar");+ }+ };+ t.start();+ t.join();+ }+ }++ public TestSeedFromUncaught() {+ super(/* suppress normal output. */ true);+ }++ /**+ * Verify super method calls on {@link LuceneTestCase#setUp()}.+ */+ @Test+ public void testUncaughtDumpsSeed() {+ Result result = JUnitCore.runClasses(ThrowInUncaught.class);+ Assert.assertEquals(1, result.getFailureCount());+ String consoleOut = super.getSysErr() + "\n\n" + super.getSysOut();+ Assert.assertTrue(consoleOut.contains("-Dtests.seed="));+ Assert.assertTrue(consoleOut.contains("foobar"));+ }+}diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSetupTeardownChaining.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSetupTeardownChaining.javaindex a099d3bc607..5b34754e051 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSetupTeardownChaining.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSetupTeardownChaining.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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.apache.lucene.util.LuceneTestCase;import org.junit.Assert;import org.junit.Test;diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.javaindex 0ea78204919..3b9d77dfaa3 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/TestSystemPropertiesInvariantRule.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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 java.util.Properties;import org.apache.lucene.util.LuceneTestCase;diff --git a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.javaindex 251659442b2..b4bb9d96a39 100644--- a/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java+++ b/lucene/core/src/test/org/apache/lucene/util/junitcompat/WithNestedTests.java@@ -1,5 +1,22 @@package org.apache.lucene.util.junitcompat;+/**+ * 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 java.io.ByteArrayOutputStream;import java.io.PrintStream;import java.io.UnsupportedEncodingException;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex fdb73b73d5b..20181fc17dc 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -274,7 +274,7 @@ public abstract class LuceneTestCase extends Assert {* Catch any uncaught exceptions on threads within the suite scope and fail the test/* suite if they happen.*/- private static final UncaughtExceptionsRule uncaughtExceptionsRule = new UncaughtExceptionsRule();+ private static final UncaughtExceptionsRule uncaughtExceptionsRule = new UncaughtExceptionsRule(null);/*** This controls how suite-level rules are nested. It is important that _all_ rules declared@@ -295,7 +295,7 @@ public abstract class LuceneTestCase extends Assert {@Rulepublic final TestRule ruleChain = RuleChain.outerRule(new RememberThreadRule())- .around(new UncaughtExceptionsRule())+ .around(new UncaughtExceptionsRule(this)).around(new TestResultInterceptorRule()).around(new SystemPropertiesInvariantRule()).around(new InternalSetupTeardownRule())diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/StoreClassNameRule.java b/lucene/test-framework/src/java/org/apache/lucene/util/StoreClassNameRule.javaindex c7d0d74fb53..5f2a7e95eec 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/StoreClassNameRule.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/StoreClassNameRule.java@@ -1,5 +1,22 @@package org.apache.lucene.util;+/**+ * 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.junit.rules.TestRule;import org.junit.runner.Description;import org.junit.runners.model.Statement;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesInvariantRule.java b/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesInvariantRule.javaindex e6876c4950a..de3f40551c4 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesInvariantRule.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesInvariantRule.java@@ -1,5 +1,22 @@package org.apache.lucene.util;+/**+ * 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 java.util.ArrayList;import java.util.Iterator;import java.util.TreeMap;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesRestoreRule.java b/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesRestoreRule.javaindex 77778fc2c92..4e7b57a3588 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesRestoreRule.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/SystemPropertiesRestoreRule.java@@ -1,5 +1,22 @@package org.apache.lucene.util;+/**+ * 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 java.util.*;import org.junit.rules.TestRule;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/UncaughtExceptionsRule.java b/lucene/test-framework/src/java/org/apache/lucene/util/UncaughtExceptionsRule.javaindex 82e506558e8..aaf1f66b951 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/UncaughtExceptionsRule.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/UncaughtExceptionsRule.java@@ -1,5 +1,22 @@package org.apache.lucene.util;+/**+ * 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 java.io.PrintWriter;import java.io.StringWriter;import java.lang.Thread.UncaughtExceptionHandler;@@ -20,6 +37,12 @@ public class UncaughtExceptionsRule implements TestRule {// This was originally volatile, but I don't think it needs to be. It's the same// thread accessing it, always.private UncaughtExceptionHandler savedUncaughtExceptionHandler;++ private final LuceneTestCase ltc;++ public UncaughtExceptionsRule(LuceneTestCase ltc) {+ this.ltc = ltc;+ }public static class UncaughtExceptionEntry {public final Thread thread;@@ -62,6 +85,15 @@ public class UncaughtExceptionsRule implements TestRule {uncaughtExceptions.clear();}+ if (!errors.isEmpty()) {+ if (ltc == null) {+ // class level failure (e.g. afterclass)+ LuceneTestCase.reportPartialFailureInfo();+ } else {+ // failure in a method+ ltc.reportAdditionalFailureInfo();+ }+ }MultipleFailureException.assertEmpty(errors);}};