Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-4606: set the random seed used to shuffle shards within tests

Robert Muir1e656d42c5c1
diff --git a/solr/core/src/java/org/apache/solr/core/SolrProperties.java b/solr/core/src/java/org/apache/solr/core/SolrProperties.java
index 309b4324544..ded4ba9ec64 100644
--- a/solr/core/src/java/org/apache/solr/core/SolrProperties.java
+++ b/solr/core/src/java/org/apache/solr/core/SolrProperties.java
@@ -270,8 +270,7 @@ public class SolrProperties implements ConfigSolr {
try {
fac = loader.findClass(info.className, ShardHandlerFactory.class).newInstance();
} catch (Exception e) {
- throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,
- "Error instantiating shardHandlerFactory class " + info.className);
+ throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, e);
}
if (fac instanceof PluginInfoInitialized) {
((PluginInfoInitialized) fac).init(info);
diff --git a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
index 5b582f3b686..21c4dfffadd 100644
--- a/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
+++ b/solr/core/src/java/org/apache/solr/handler/component/HttpShardHandlerFactory.java
@@ -124,6 +124,12 @@ public class HttpShardHandlerFactory extends ShardHandlerFactory implements org.
this.keepAliveTime = getParameter(args, MAX_THREAD_IDLE_TIME, keepAliveTime);
this.queueSize = getParameter(args, INIT_SIZE_OF_QUEUE, queueSize);
this.accessPolicy = getParameter(args, INIT_FAIRNESS_POLICY, accessPolicy);
+
+ // magic sysprop to make tests reproducible: set by SolrTestCaseJ4.
+ String v = System.getProperty("tests.shardhandler.randomSeed");
+ if (v != null) {
+ r.setSeed(Long.parseLong(v));
+ }
BlockingQueue<Runnable> blockingQueue = (this.queueSize == -1) ?
new SynchronousQueue<Runnable>(this.accessPolicy) :
diff --git a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
index 9662e3d7cf1..70d4ef29599 100644
--- a/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
+++ b/solr/core/src/test/org/apache/solr/TestSolrCoreProperties.java
@@ -46,6 +46,7 @@ public class TestSolrCoreProperties extends LuceneTestCase {
super.setUp();
setUpMe();
System.setProperty("solr.data.dir", getDataDir());
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
solrJetty = new JettySolrRunner(getHomeDir(), "/solr", 0);
@@ -58,6 +59,7 @@ public class TestSolrCoreProperties extends LuceneTestCase {
@Override
public void tearDown() throws Exception {
solrJetty.stop();
+ System.clearProperty("tests.shardhandler.randomSeed");
AbstractSolrTestCase.recurseDelete(homeDir);
super.tearDown();
}
diff --git a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
index 1d8a2019042..9ab0c60e85f 100644
--- a/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
+++ b/solr/core/src/test/org/apache/solr/schema/TestBinaryField.java
@@ -76,6 +76,7 @@ public class TestBinaryField extends LuceneTestCase {
System.setProperty("solr.data.dir", dataDir.getAbsolutePath());
System.setProperty("solr.test.sys.prop1", "propone");
System.setProperty("solr.test.sys.prop2", "proptwo");
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
jetty = new JettySolrRunner(homeDir.getAbsolutePath(), context, 0);
jetty.start();
@@ -182,6 +183,7 @@ public class TestBinaryField extends LuceneTestCase {
@Override
public void tearDown() throws Exception {
jetty.stop();
+ System.clearProperty("tests.shardhandler.randomSeed");
super.tearDown();
}
}
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
index 16c0b6cac75..54ebbf621e7 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/TestLBHttpSolrServer.java
@@ -72,6 +72,7 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
public static void beforeClass() {
savedFactory = System.getProperty("solr.DirectoryFactory");
System.setProperty("solr.directoryFactory", "org.apache.solr.core.MockFSDirectoryFactory");
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
}
@AfterClass
@@ -81,6 +82,7 @@ public class TestLBHttpSolrServer extends LuceneTestCase {
} else {
System.setProperty("solr.directoryFactory", savedFactory);
}
+ System.clearProperty("tests.shardhandler.randomSeed");
}
@Override
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
index 43e9fdae760..2b7a18b7cbf 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/AbstractEmbeddedSolrServerTestCase.java
@@ -60,7 +60,7 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
System.setProperty("dataDir1", dataDir.getAbsolutePath());
System.setProperty("dataDir2", dataDir2.getAbsolutePath());
System.setProperty("tempDir", tempDir.getAbsolutePath());
-
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
cores = new CoreContainer(SOLR_HOME.getAbsolutePath(), getSolrXml());
}
@@ -74,7 +74,8 @@ public abstract class AbstractEmbeddedSolrServerTestCase extends LuceneTestCase
System.clearProperty("dataDir1");
System.clearProperty("dataDir2");
-
+ System.clearProperty("tests.shardhandler.randomSeed");
+
deleteAdditionalFiles();
File dataDir = new File(tempDir,"data");
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
index bb1d93baa7d..4d96ce01317 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/embedded/JettyWebappTest.java
@@ -55,7 +55,8 @@ public class JettyWebappTest extends LuceneTestCase
{
super.setUp();
System.setProperty("solr.solr.home", ExternalPaths.EXAMPLE_HOME);
-
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
+
File dataDir = new File(LuceneTestCase.TEMP_DIR,
getClass().getName() + "-" + System.currentTimeMillis());
dataDir.mkdirs();
@@ -84,6 +85,7 @@ public class JettyWebappTest extends LuceneTestCase
try {
server.stop();
} catch( Exception ex ) {}
+ System.clearProperty("tests.shardhandler.randomSeed");
super.tearDown();
}
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index c02c2d27f11..c611c4a9455 100755
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -85,6 +85,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
@SuppressWarnings("unused")
private static void beforeClass() {
System.setProperty("jetty.testMode", "true");
+ System.setProperty("tests.shardhandler.randomSeed", Long.toString(random().nextLong()));
setupLogging();
startTrackingSearchers();
startTrackingZkClients();
@@ -101,6 +102,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
resetFactory();
coreName = CoreContainer.DEFAULT_DEFAULT_CORE_NAME;
System.clearProperty("jetty.testMode");
+ System.clearProperty("tests.shardhandler.randomSeed");
}
private static boolean changedFactory = false;