Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ public boolean shouldCache(Query query) {
thread.start();
}

testHarness.start();

// Wait for all threads to complete before checking results
for (Thread thread : threads) {
thread.join();
}
Expand Down Expand Up @@ -222,28 +221,29 @@ void assertCount(int expectedCount) {

private static class TestHarness {
private final CompletionStatsCache completionStatsCache;
private final CyclicBarrier cyclicBarrier;
private final CyclicBarrier startBarrier;
private final CompletionStats[] results;

TestHarness(CompletionStatsCache completionStatsCache, int resultCount) {
this.completionStatsCache = completionStatsCache;
results = new CompletionStats[resultCount];
cyclicBarrier = new CyclicBarrier(resultCount + 1);
}

void getStats(int threadIndex, String... fieldPatterns) {
start();
results[threadIndex] = completionStatsCache.get(fieldPatterns);
// Only need threads to synchronize at start
startBarrier = new CyclicBarrier(resultCount);
}

void start() {
void waitForStart() {
try {
cyclicBarrier.await();
startBarrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
throw new AssertionError(e);
}
}

void getStats(int threadIndex, String... fieldPatterns) {
waitForStart();
results[threadIndex] = completionStatsCache.get(fieldPatterns);
}

CompletionStats getResult(int index) {
return results[index];
}
Expand Down
Loading