Apache Lucene open-source search software
SOLR-8961: Add a test-the-tests module for solr-test-framework
Alan Woodward6390e22e7446
diff --git a/dev-tools/idea/solr/test-framework/solr-test-framework.iml b/dev-tools/idea/solr/test-framework/solr-test-framework.imlindex 1b3f064f030..b990f7a128c 100644--- a/dev-tools/idea/solr/test-framework/solr-test-framework.iml+++ b/dev-tools/idea/solr/test-framework/solr-test-framework.iml@@ -7,6 +7,8 @@<content url="file://$MODULE_DIR$"><sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" /><sourceFolder url="file://$MODULE_DIR$/src/resources" type="java-resource" />+ <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />+ <sourceFolder url="file://$MODULE_DIR$/src/test-files" type="java-test-resource" /></content><orderEntry type="inheritedJdk" /><orderEntry type="sourceFolder" forTests="false" />diff --git a/dev-tools/maven/solr/test-framework/pom.xml.template b/dev-tools/maven/solr/test-framework/pom.xml.templateindex 22f2fb08e55..17dab4c6f77 100644--- a/dev-tools/maven/solr/test-framework/pom.xml.template+++ b/dev-tools/maven/solr/test-framework/pom.xml.template@@ -61,6 +61,11 @@<directory>${module-path}/src/resources</directory></resource></resources>+ <testResources>+ <testResource>+ <directory>${module-path}/src/test-files</directory>+ </testResource>+ </testResources><plugins><plugin><groupId>org.apache.maven.plugins</groupId>diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 43f1e957a50..20aa5fbb651 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -139,6 +139,8 @@ Other Changes* SOLR-9406: SolrSuggester should selectively register close hook (Gethin James, Joel Bernstein)+* SOLR-8961: Add a test module for solr-test-framework (Alan Woodward)+================== 6.2.0 ==================Versions of Major Componentsdiff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.javaindex 00dbfd01376..c2c99a10a7a 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java@@ -17,7 +17,6 @@package org.apache.solr.cloud;import java.io.File;-import java.io.IOException;import java.lang.invoke.MethodHandles;import java.net.URL;import java.util.ArrayList;@@ -27,10 +26,8 @@ import java.util.HashMap;import java.util.HashSet;import java.util.List;import java.util.Map;-import java.util.concurrent.atomic.AtomicInteger;import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;-import org.apache.lucene.index.TieredMergePolicy;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util.LuceneTestCase.SuppressSysoutChecks;@@ -235,70 +232,6 @@ public class TestMiniSolrCloudCluster extends LuceneTestCase {}}- @Test- public void testErrorsInStartup() throws Exception {-- AtomicInteger jettyIndex = new AtomicInteger();-- MiniSolrCloudCluster cluster = null;- try {- cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {- @Override- public JettySolrRunner startJettySolrRunner(String name, String context, JettyConfig config) throws Exception {- if (jettyIndex.incrementAndGet() != 2)- return super.startJettySolrRunner(name, context, config);- throw new IOException("Fake exception on startup!");- }- };- fail("Expected an exception to be thrown from MiniSolrCloudCluster");- }- catch (Exception e) {- assertEquals("Error starting up MiniSolrCloudCluster", e.getMessage());- assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);- assertEquals("Fake exception on startup!", e.getSuppressed()[0].getMessage());- }- finally {- if (cluster != null)- cluster.shutdown();- }- }-- @Test- public void testErrorsInShutdown() throws Exception {-- AtomicInteger jettyIndex = new AtomicInteger();-- MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {- @Override- protected JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {- JettySolrRunner j = super.stopJettySolrRunner(jetty);- if (jettyIndex.incrementAndGet() == 2)- throw new IOException("Fake IOException on shutdown!");- return j;- }- };-- try {- cluster.shutdown();- fail("Expected an exception to be thrown on MiniSolrCloudCluster shutdown");- }- catch (Exception e) {- assertEquals("Error shutting down MiniSolrCloudCluster", e.getMessage());- assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);- assertEquals("Fake IOException on shutdown!", e.getSuppressed()[0].getMessage());- }-- }-- @Test- public void testExtraFilters() throws Exception {- Builder jettyConfig = JettyConfig.builder();- jettyConfig.waitForLoadingCoresToFinish(null);- jettyConfig.withFilter(JettySolrRunner.DebugFilter.class, "*");- MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(NUM_SERVERS, createTempDir(), jettyConfig.build());- cluster.shutdown();- }-@Testpublic void testCollectionCreateWithoutCoresThenDelete() throws Exception {diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterKerberos.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterKerberos.javaindex d644967481f..e2b0aea3301 100644--- a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterKerberos.java+++ b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudClusterKerberos.java@@ -127,20 +127,6 @@ public class TestMiniSolrCloudClusterKerberos extends TestMiniSolrCloudCluster {public void testCollectionCreateSearchDelete() throws Exception {super.testCollectionCreateSearchDelete();}-- @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/HADOOP-9893")- @Test- @Override- public void testErrorsInShutdown() throws Exception {- super.testErrorsInShutdown();- }-- @AwaitsFix(bugUrl="https://issues.apache.org/jira/browse/HADOOP-9893")- @Test- @Override- public void testErrorsInStartup() throws Exception {- super.testErrorsInStartup();- }@Overridepublic void tearDown() throws Exception {diff --git a/solr/test-framework/build.xml b/solr/test-framework/build.xmlindex 1e0d7b51ad7..baea9969f35 100644--- a/solr/test-framework/build.xml+++ b/solr/test-framework/build.xml@@ -51,9 +51,6 @@<!-- redefine the clover setup, because we dont want to run clover for the test-framework --><target name="-clover.setup" if="run.clover"/>-- <!-- redefine the test compilation, so it's just a no-op -->- <target name="compile-test"/><!-- redefine the forbidden apis for tests, as we check ourselves --><target name="-check-forbidden-tests" depends="-init-forbidden-apis,compile-core">diff --git a/solr/test-framework/src/test-files/log4j.properties b/solr/test-framework/src/test-files/log4j.propertiesnew file mode 100644index 00000000000..f6fedb6ea27--- /dev/null+++ b/solr/test-framework/src/test-files/log4j.properties@@ -0,0 +1,11 @@+# Logging level+log4j.rootLogger=INFO, CONSOLE++log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender+log4j.appender.CONSOLE.Target=System.err+log4j.appender.CONSOLE.layout=org.apache.log4j.EnhancedPatternLayout+log4j.appender.CONSOLE.layout.ConversionPattern=%-4r %-5p (%t) [%X{node_name} %X{collection} %X{shard} %X{replica} %X{core}] %c{1.} %m%n+log4j.logger.org.apache.zookeeper=WARN+log4j.logger.org.apache.hadoop=WARN+log4j.logger.org.apache.directory=WARN+log4j.logger.org.apache.solr.hadoop=INFO\ No newline at end of filediff --git a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.javanew file mode 100644index 00000000000..90eea94e5a4--- /dev/null+++ b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java@@ -0,0 +1,105 @@+/*+ * 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.solr.cloud;++import java.io.IOException;+import java.util.concurrent.atomic.AtomicInteger;++import com.carrotsearch.randomizedtesting.rules.SystemPropertiesRestoreRule;+import org.apache.lucene.util.LuceneTestCase;+import org.apache.solr.client.solrj.embedded.JettyConfig;+import org.apache.solr.client.solrj.embedded.JettySolrRunner;+import org.apache.solr.util.RevertDefaultThreadHandlerRule;+import org.junit.ClassRule;+import org.junit.Test;+import org.junit.rules.RuleChain;+import org.junit.rules.TestRule;+[email protected](bugUrl = "Solr logs to JUL")+public class MiniSolrCloudClusterTest extends LuceneTestCase {++ @ClassRule+ public static TestRule solrClassRules = RuleChain.outerRule(+ new SystemPropertiesRestoreRule()).around(+ new RevertDefaultThreadHandlerRule());++ @Test+ public void testErrorsInStartup() throws Exception {++ AtomicInteger jettyIndex = new AtomicInteger();++ MiniSolrCloudCluster cluster = null;+ try {+ cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {+ @Override+ public JettySolrRunner startJettySolrRunner(String name, String context, JettyConfig config) throws Exception {+ if (jettyIndex.incrementAndGet() != 2)+ return super.startJettySolrRunner(name, context, config);+ throw new IOException("Fake exception on startup!");+ }+ };+ fail("Expected an exception to be thrown from MiniSolrCloudCluster");+ }+ catch (Exception e) {+ assertEquals("Error starting up MiniSolrCloudCluster", e.getMessage());+ assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);+ assertEquals("Fake exception on startup!", e.getSuppressed()[0].getMessage());+ }+ finally {+ if (cluster != null)+ cluster.shutdown();+ }+ }++ @Test+ public void testErrorsInShutdown() throws Exception {++ AtomicInteger jettyIndex = new AtomicInteger();++ MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(3, createTempDir(), JettyConfig.builder().build()) {+ @Override+ protected JettySolrRunner stopJettySolrRunner(JettySolrRunner jetty) throws Exception {+ JettySolrRunner j = super.stopJettySolrRunner(jetty);+ if (jettyIndex.incrementAndGet() == 2)+ throw new IOException("Fake IOException on shutdown!");+ return j;+ }+ };++ try {+ cluster.shutdown();+ fail("Expected an exception to be thrown on MiniSolrCloudCluster shutdown");+ }+ catch (Exception e) {+ assertEquals("Error shutting down MiniSolrCloudCluster", e.getMessage());+ assertEquals("Expected one suppressed exception", 1, e.getSuppressed().length);+ assertEquals("Fake IOException on shutdown!", e.getSuppressed()[0].getMessage());+ }++ }++ @Test+ public void testExtraFilters() throws Exception {+ JettyConfig.Builder jettyConfig = JettyConfig.builder();+ jettyConfig.waitForLoadingCoresToFinish(null);+ jettyConfig.withFilter(JettySolrRunner.DebugFilter.class, "*");+ MiniSolrCloudCluster cluster = new MiniSolrCloudCluster(random().nextInt(3) + 1, createTempDir(), jettyConfig.build());+ cluster.shutdown();+ }++}