Don't assert a second time if awaitBusy returned successfully

This commit is contained in:
Simon Willnauer 2013-08-23 20:50:02 +02:00
parent 86c95ab2ab
commit c688ed6c9f
2 changed files with 5 additions and 6 deletions

View File

@ -44,14 +44,14 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
awaitBusy(breakPredicate, 10, TimeUnit.SECONDS); awaitBusy(breakPredicate, 10, TimeUnit.SECONDS);
} }
public void awaitBusy(Predicate<?> breakPredicate, long maxWaitTime, TimeUnit unit) throws InterruptedException { public boolean awaitBusy(Predicate<?> breakPredicate, long maxWaitTime, TimeUnit unit) throws InterruptedException {
long maxTimeInMillis = TimeUnit.MILLISECONDS.convert(maxWaitTime, unit); long maxTimeInMillis = TimeUnit.MILLISECONDS.convert(maxWaitTime, unit);
long iterations = Math.max(Math.round(Math.log10(maxTimeInMillis) / Math.log10(2)), 1); long iterations = Math.max(Math.round(Math.log10(maxTimeInMillis) / Math.log10(2)), 1);
long timeInMillis = 1; long timeInMillis = 1;
long sum = 0; long sum = 0;
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
if (breakPredicate.apply(null)) { if (breakPredicate.apply(null)) {
return; return true;
} }
sum += timeInMillis; sum += timeInMillis;
Thread.sleep(timeInMillis); Thread.sleep(timeInMillis);
@ -59,6 +59,7 @@ public abstract class ElasticsearchTestCase extends AbstractRandomizedTest {
} }
timeInMillis = maxTimeInMillis - sum; timeInMillis = maxTimeInMillis - sum;
Thread.sleep(Math.max(timeInMillis, 0)); Thread.sleep(Math.max(timeInMillis, 0));
return breakPredicate.apply(null);
} }

View File

@ -39,7 +39,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
/** /**
* *
@ -310,11 +309,10 @@ public class RecoveryWhileUnderLoadTests extends AbstractSharedClusterTest {
} }
private void waitForDocs(final long numDocs) throws InterruptedException { private void waitForDocs(final long numDocs) throws InterruptedException {
awaitBusy(new Predicate<Object>() { assertThat(awaitBusy(new Predicate<Object>() {
public boolean apply(Object o) { public boolean apply(Object o) {
return client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() > numDocs; return client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() > numDocs;
} }
}, 5, TimeUnit.MINUTES); // not really relevant here we just have to wait some time }, 5, TimeUnit.MINUTES), equalTo(true)); // not really relevant here we just have to wait some time
assertThat(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount(), greaterThan(numDocs));
} }
} }