Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

use junit plain formatter by default, log start + end of tests

Yonik Seeley9989774d3366
diff --git a/build.xml b/build.xml
index 381ac26e9e9..0a86244b026 100644
--- a/build.xml
+++ b/build.xml
@@ -400,7 +400,7 @@
<jvmarg line="${args}"/>
<formatter type="brief" usefile="false" if="junit.details"/>
<classpath refid="test.run.classpath"/>
- <formatter type="xml"/>
+ <formatter type="${junit.formatter}"/>
<batchtest fork="yes" todir="${junit.output.dir}" if="runall">
<fileset dir="src/test" includes="${junit.includes}"/>
</batchtest>
diff --git a/common-build.xml b/common-build.xml
index 6118d3b89f8..b30a5327210 100644
--- a/common-build.xml
+++ b/common-build.xml
@@ -102,6 +102,7 @@
<property name="junit.includes" value="**/Test*.java,**/*Test.java"/>
<property name="junit.output.dir" location="${common.dir}/${dest}/test-results"/>
<property name="junit.reports" location="${common.dir}/${dest}/test-results/reports"/>
+ <property name="junit.formatter" value="plain"/>
<!-- Maven properties -->
<property name="maven.build.dir" value="${basedir}/build/maven"/>
diff --git a/src/java/org/apache/solr/util/AbstractSolrTestCase.java b/src/java/org/apache/solr/util/AbstractSolrTestCase.java
index 4a182f24bdd..5a9bda55113 100644
--- a/src/java/org/apache/solr/util/AbstractSolrTestCase.java
+++ b/src/java/org/apache/solr/util/AbstractSolrTestCase.java
@@ -28,6 +28,8 @@ import org.apache.solr.request.*;
import org.apache.solr.util.TestHarness;
import org.xml.sax.SAXException;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
import junit.framework.TestCase;
import javax.xml.xpath.XPathExpressionException;
@@ -95,26 +97,53 @@ public abstract class AbstractSolrTestCase extends TestCase {
* </ul>
*
*/
+
+ public static Logger log = LoggerFactory.getLogger(AbstractSolrTestCase.class);
+
public void setUp() throws Exception {
+ log.info("####SETUP_START " + getName());
dataDir = new File(System.getProperty("java.io.tmpdir")
- + System.getProperty("file.separator")
- + getClass().getName() + "-" + System.currentTimeMillis());
+ + System.getProperty("file.separator")
+ + getClass().getName() + "-" + System.currentTimeMillis());
dataDir.mkdirs();
-
- solrConfig = h.createConfig(getSolrConfigFile());
- h = new TestHarness( dataDir.getAbsolutePath(),
- solrConfig,
- getSchemaFile());
- lrf = h.getRequestFactory
- ("standard",0,20,"version","2.2");
+
+ String configFile = getSolrConfigFile();
+ if (configFile != null) {
+
+ solrConfig = h.createConfig(getSolrConfigFile());
+ h = new TestHarness( dataDir.getAbsolutePath(),
+ solrConfig,
+ getSchemaFile());
+ lrf = h.getRequestFactory
+ ("standard",0,20,"version","2.2");
+ }
+ log.info("####SETUP_END " + getName());
}
-
+
+ /** Subclasses that override setUp can optionally call this method
+ * to log the fact that their setUp process has ended.
+ */
+ public void postSetUp() {
+ log.info("####POSTSETUP " + getName());
+ }
+
+
+ /** Subclasses that override tearDown can optionally call this method
+ * to log the fact that the tearDown process has started. This is necessary
+ * since subclasses will want to call super.tearDown() at the *end* of their
+ * tearDown method.
+ */
+ public void preTearDown() {
+ log.info("####PRETEARDOWN " + getName());
+ }
+
/**
* Shuts down the test harness, and makes the best attempt possible
* to delete dataDir, unless the system property "solr.test.leavedatadir"
* is set.
*/
public void tearDown() throws Exception {
+ log.info("####TEARDOWN_START " + getName());
if (h != null) { h.close(); }
String skip = System.getProperty("solr.test.leavedatadir");
if (null != skip && 0 != skip.trim().length()) {
diff --git a/src/test/org/apache/solr/TestDistributedSearch.java b/src/test/org/apache/solr/TestDistributedSearch.java
index e3e7ff81f1d..f073836e17b 100755
--- a/src/test/org/apache/solr/TestDistributedSearch.java
+++ b/src/test/org/apache/solr/TestDistributedSearch.java
@@ -44,7 +44,15 @@ import junit.framework.TestCase;
* @version $Id$
* @since solr 1.3
*/
-public class TestDistributedSearch extends TestCase {
+public class TestDistributedSearch extends AbstractSolrTestCase {
+ public String getSchemaFile() {
+ return null;
+ }
+
+ public String getSolrConfigFile() {
+ return null;
+ }
+
static Random r = new Random(0);
File testDir;
@@ -75,22 +83,24 @@ public class TestDistributedSearch extends TestCase {
String missingField="missing_but_valid_field_t";
String invalidField="invalid_field_not_in_schema";
-
-
@Override public void setUp() throws Exception
{
+ super.setUp();
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
testDir = new File(System.getProperty("java.io.tmpdir")
+ System.getProperty("file.separator")
+ getClass().getName() + "-" + System.currentTimeMillis());
testDir.mkdirs();
+ super.postSetUp();
}
@Override public void tearDown() throws Exception
{
+ super.preTearDown();
destroyServers();
AbstractSolrTestCase.recurseDelete(testDir);
+ super.tearDown();
}
diff --git a/src/test/org/apache/solr/handler/TestReplicationHandler.java b/src/test/org/apache/solr/handler/TestReplicationHandler.java
index 548adf60d19..19f21fd694f 100644
--- a/src/test/org/apache/solr/handler/TestReplicationHandler.java
+++ b/src/test/org/apache/solr/handler/TestReplicationHandler.java
@@ -40,7 +40,15 @@ import java.net.URL;
* @version $Id$
* @since 1.4
*/
-public class TestReplicationHandler extends TestCase {
+public class TestReplicationHandler extends AbstractSolrTestCase {
+ public String getSchemaFile() {
+ return null;
+ }
+
+ public String getSolrConfigFile() {
+ return null;
+ }
+
private static final String CONF_DIR = "." + File.separator + "solr" + File.separator + "conf" + File.separator;
private static final String SLAVE_CONFIG = CONF_DIR + "solrconfig-slave.xml";
@@ -51,7 +59,9 @@ public class TestReplicationHandler extends TestCase {
String context = "/solr";
+
public void setUp() throws Exception {
+ super.setUp();
master = new SolrInstance("master", null);
master.setUp();
masterJetty = createJetty(master);
@@ -65,10 +75,12 @@ public class TestReplicationHandler extends TestCase {
@Override
public void tearDown() throws Exception {
+ super.preTearDown();
masterJetty.stop();
slaveJetty.stop();
master.tearDown();
slave.tearDown();
+ super.tearDown();
}
private JettySolrRunner createJetty(SolrInstance instance) throws Exception {