Skip to content

Commit 7e326bd

Browse files
committed
Beef up test to use more threads and iterations randomly
1 parent 191887d commit 7e326bd

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

src/test/java/org/elasticsearch/search/basic/SearchWhileRelocatingTests.java

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,38 @@ private void testSearchAndRelocateConcurrently(int numberOfReplicas) throws Exce
7070
}
7171
indexRandom(true, indexBuilders.toArray(new IndexRequestBuilder[indexBuilders.size()]));
7272
assertHitCount(client().prepareSearch().get(), (long) (numDocs));
73-
final int numIters = atLeast(3);
73+
final int numIters = atLeast(10);
7474
for (int i = 0; i < numIters; i++) {
75-
allowNodes("test", between(1, 3));
76-
client().admin().cluster().prepareReroute().get();
7775
final AtomicBoolean stop = new AtomicBoolean(false);
7876
final List<Throwable> thrownExceptions = new CopyOnWriteArrayList<Throwable>();
79-
final Thread t = new Thread() {
80-
public void run() {
81-
try {
82-
while (!stop.get()) {
83-
SearchResponse sr = client().prepareSearch().setSize(numDocs).get();
84-
assertHitCount(sr, (long) (numDocs));
85-
final SearchHits sh = sr.getHits();
86-
assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits(),
87-
equalTo((long) (sh.getHits().length)));
77+
Thread[] threads = new Thread[atLeast(1)];
78+
for (int j = 0; j < threads.length; j++) {
79+
threads[j] = new Thread() {
80+
public void run() {
81+
try {
82+
while (!stop.get()) {
83+
SearchResponse sr = client().prepareSearch().setSize(numDocs).get();
84+
assertHitCount(sr, (long) (numDocs));
85+
final SearchHits sh = sr.getHits();
86+
assertThat("Expected hits to be the same size the actual hits array", sh.getTotalHits(),
87+
equalTo((long) (sh.getHits().length)));
88+
}
89+
} catch (Throwable t) {
90+
thrownExceptions.add(t);
8891
}
89-
} catch (Throwable t) {
90-
thrownExceptions.add(t);
9192
}
92-
}
93-
};
94-
t.start();
93+
};
94+
}
95+
for (int j = 0; j < threads.length; j++) {
96+
threads[j].start();
97+
}
98+
allowNodes("test", between(1, 3));
99+
client().admin().cluster().prepareReroute().get();
95100
ClusterHealthResponse resp = client().admin().cluster().prepareHealth().setWaitForRelocatingShards(0).execute().actionGet();
96101
stop.set(true);
97-
t.join();
102+
for (int j = 0; j < threads.length; j++) {
103+
threads[j].join();
104+
}
98105
assertThat(resp.isTimedOut(), equalTo(false));
99106

100107
if (!thrownExceptions.isEmpty()) {

0 commit comments

Comments
 (0)