use test-framework seed for randomness and dont share across threads

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1455899 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-03-13 12:13:08 +00:00
parent bd1a1e5ffc
commit c64b374f96

View File

@ -55,7 +55,6 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
private int numCores = 20; private int numCores = 20;
private Map<String, Long> coreCounts; private Map<String, Long> coreCounts;
private List<String> coreNames; private List<String> coreNames;
Random random = new Random(System.currentTimeMillis());
static final int COMMIT_WITHIN = 5000; static final int COMMIT_WITHIN = 5000;
@ -189,9 +188,9 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
log.info(String.format(Locale.ROOT, "\n\n\n\n\nStarting a %,d second cycle, seconds left: %,d. Seconds run so far: %,d.", log.info(String.format(Locale.ROOT, "\n\n\n\n\nStarting a %,d second cycle, seconds left: %,d. Seconds run so far: %,d.",
cycleSeconds, secondsRemaining, secondsRun)); cycleSeconds, secondsRemaining, secondsRun));
Indexer idxer = new Indexer(this, url, indexingServers, indexingThreads, cycleSeconds); Indexer idxer = new Indexer(this, url, indexingServers, indexingThreads, cycleSeconds, random());
Queries queries = new Queries(this, url, queryServers, queryThreads); Queries queries = new Queries(this, url, queryServers, queryThreads, random());
idxer.waitOnThreads(); idxer.waitOnThreads();
@ -310,7 +309,7 @@ public class OpenCloseCoreStressTest extends SolrTestCaseJ4 {
cumulativeDocs += totalDocsFound; cumulativeDocs += totalDocsFound;
} }
String getRandomCore() { String getRandomCore(Random random) {
return coreNames.get(Math.abs(random.nextInt()) % coreNames.size()); return coreNames.get(Math.abs(random.nextInt()) % coreNames.size());
} }
@ -339,14 +338,14 @@ class Indexer {
ArrayList<OneIndexer> _threads = new ArrayList<OneIndexer>(); ArrayList<OneIndexer> _threads = new ArrayList<OneIndexer>();
public Indexer(OpenCloseCoreStressTest OCCST, String url, List<HttpSolrServer> servers, int numThreads, int secondsToRun) { public Indexer(OpenCloseCoreStressTest OCCST, String url, List<HttpSolrServer> servers, int numThreads, int secondsToRun, Random random) {
stopTime = System.currentTimeMillis() + (secondsToRun * 1000); stopTime = System.currentTimeMillis() + (secondsToRun * 1000);
nextTime = System.currentTimeMillis() + 60000; nextTime = System.currentTimeMillis() + 60000;
docsThisCycle.set(0); docsThisCycle.set(0);
qTimesAccum.set(0); qTimesAccum.set(0);
updateCounts.set(0); updateCounts.set(0);
for (int idx = 0; idx < numThreads; ++idx) { for (int idx = 0; idx < numThreads; ++idx) {
OneIndexer one = new OneIndexer(OCCST, url, servers.get(idx)); OneIndexer one = new OneIndexer(OCCST, url, servers.get(idx), random.nextLong());
_threads.add(one); _threads.add(one);
one.start(); one.start();
} }
@ -385,11 +384,13 @@ class OneIndexer extends Thread {
private final OpenCloseCoreStressTest OCCST; private final OpenCloseCoreStressTest OCCST;
private final HttpSolrServer server; private final HttpSolrServer server;
private final String baseUrl; private final String baseUrl;
private final Random random;
OneIndexer(OpenCloseCoreStressTest OCCST, String url, HttpSolrServer server) { OneIndexer(OpenCloseCoreStressTest OCCST, String url, HttpSolrServer server, long seed) {
this.OCCST = OCCST; this.OCCST = OCCST;
this.server = server; this.server = server;
this.baseUrl = url; this.baseUrl = url;
this.random = new Random(seed);
} }
@Override @Override
@ -399,7 +400,7 @@ class OneIndexer extends Thread {
while (Indexer.stopTime > System.currentTimeMillis()) { while (Indexer.stopTime > System.currentTimeMillis()) {
int myId = Indexer.idUnique.incrementAndGet(); int myId = Indexer.idUnique.incrementAndGet();
Indexer.docsThisCycle.incrementAndGet(); Indexer.docsThisCycle.incrementAndGet();
String core = OCCST.getRandomCore(); String core = OCCST.getRandomCore(random);
OCCST.incrementCoreCount(core); OCCST.incrementCoreCount(core);
Indexer.progress(myId, core); Indexer.progress(myId, core);
for (int idx = 0; idx < 3; ++idx) { for (int idx = 0; idx < 3; ++idx) {
@ -447,10 +448,10 @@ class Queries {
static AtomicInteger _errors = new AtomicInteger(0); static AtomicInteger _errors = new AtomicInteger(0);
String baseUrl; String baseUrl;
public Queries(OpenCloseCoreStressTest OCCST, String url, List<HttpSolrServer> servers, int numThreads) { public Queries(OpenCloseCoreStressTest OCCST, String url, List<HttpSolrServer> servers, int numThreads, Random random) {
baseUrl = url; baseUrl = url;
for (int idx = 0; idx < numThreads; ++idx) { for (int idx = 0; idx < numThreads; ++idx) {
Thread one = new OneQuery(OCCST, url, servers.get(idx)); Thread one = new OneQuery(OCCST, url, servers.get(idx), random.nextLong());
_threads.add(one); _threads.add(one);
one.start(); one.start();
} }
@ -488,18 +489,20 @@ class OneQuery extends Thread {
OpenCloseCoreStressTest OCCST; OpenCloseCoreStressTest OCCST;
private final HttpSolrServer server; private final HttpSolrServer server;
private final String baseUrl; private final String baseUrl;
private final Random random;
OneQuery(OpenCloseCoreStressTest OCCST, String url, HttpSolrServer server) { OneQuery(OpenCloseCoreStressTest OCCST, String url, HttpSolrServer server, long seed) {
this.OCCST = OCCST; this.OCCST = OCCST;
this.server = server; this.server = server;
this.baseUrl = url; this.baseUrl = url;
this.random = new Random(seed);
} }
@Override @Override
public void run() { public void run() {
SolrTestCaseJ4.log.info(String.format(Locale.ROOT, "Starting query thread: " + getId())); SolrTestCaseJ4.log.info(String.format(Locale.ROOT, "Starting query thread: " + getId()));
while (Queries._keepon.get()) { while (Queries._keepon.get()) {
String core = OCCST.getRandomCore(); String core = OCCST.getRandomCore(random);
for (int idx = 0; idx < 3; ++idx) { for (int idx = 0; idx < 3; ++idx) {
ModifiableSolrParams params = new ModifiableSolrParams(); ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/select"); params.set("qt", "/select");