From 6390e22e7446d33e9d996ee76330b4cc94f654a4 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Fri, 2 Sep 2016 13:15:58 +0100 Subject: [PATCH] SOLR-8961: Add a test-the-tests module for solr-test-framework --- .../test-framework/solr-test-framework.iml | 2 + .../solr/test-framework/pom.xml.template | 5 + solr/CHANGES.txt | 2 + .../solr/cloud/TestMiniSolrCloudCluster.java | 67 ----------- .../TestMiniSolrCloudClusterKerberos.java | 14 --- solr/test-framework/build.xml | 3 - .../src/test-files/log4j.properties | 11 ++ .../solr/cloud/MiniSolrCloudClusterTest.java | 105 ++++++++++++++++++ 8 files changed, 125 insertions(+), 84 deletions(-) create mode 100644 solr/test-framework/src/test-files/log4j.properties create mode 100644 solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java diff --git a/dev-tools/idea/solr/test-framework/solr-test-framework.iml b/dev-tools/idea/solr/test-framework/solr-test-framework.iml index 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 @@ + + diff --git a/dev-tools/maven/solr/test-framework/pom.xml.template b/dev-tools/maven/solr/test-framework/pom.xml.template index 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 @@ ${module-path}/src/resources + + + ${module-path}/src/test-files + + org.apache.maven.plugins diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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 Components diff --git a/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java b/solr/core/src/test/org/apache/solr/cloud/TestMiniSolrCloudCluster.java index 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(); - } - @Test public 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.java index 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(); - } @Override public void tearDown() throws Exception { diff --git a/solr/test-framework/build.xml b/solr/test-framework/build.xml index 1e0d7b51ad7..baea9969f35 100644 --- a/solr/test-framework/build.xml +++ b/solr/test-framework/build.xml @@ -51,9 +51,6 @@ - - - diff --git a/solr/test-framework/src/test-files/log4j.properties b/solr/test-framework/src/test-files/log4j.properties new file mode 100644 index 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 file diff --git a/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java b/solr/test-framework/src/test/org/apache/solr/cloud/MiniSolrCloudClusterTest.java new file mode 100644 index 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; + +@LuceneTestCase.SuppressSysoutChecks(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(); + } + +}