Fix usage of latch in RetryTests

This commit is contained in:
Daniel Mitterdorfer 2015-12-18 06:48:52 +01:00
parent 0f5f3ced99
commit 801de8f2ba
1 changed files with 6 additions and 7 deletions

View File

@ -31,6 +31,7 @@ import org.junit.After;
import org.junit.Before; import org.junit.Before;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
@ -91,7 +92,6 @@ public class RetryTests extends ESTestCase {
assertThat(response.getItems().length, equalTo(bulkRequest.numberOfActions())); assertThat(response.getItems().length, equalTo(bulkRequest.numberOfActions()));
} }
@AwaitsFix(bugUrl = "spuriously fails on Jenkins. Investigation ongoing.")
public void testAsyncRetryBacksOff() throws Exception { public void testAsyncRetryBacksOff() throws Exception {
BackoffPolicy backoff = BackoffPolicy.constantBackoff(DELAY, CALLS_TO_FAIL); BackoffPolicy backoff = BackoffPolicy.constantBackoff(DELAY, CALLS_TO_FAIL);
AssertingListener listener = new AssertingListener(); AssertingListener listener = new AssertingListener();
@ -108,7 +108,6 @@ public class RetryTests extends ESTestCase {
listener.assertOnFailureNeverCalled(); listener.assertOnFailureNeverCalled();
} }
@AwaitsFix(bugUrl = "spuriously fails on Jenkins. Investigation ongoing.")
public void testAsyncRetryFailsAfterBacksOff() throws Exception { public void testAsyncRetryFailsAfterBacksOff() throws Exception {
BackoffPolicy backoff = BackoffPolicy.constantBackoff(DELAY, CALLS_TO_FAIL - 1); BackoffPolicy backoff = BackoffPolicy.constantBackoff(DELAY, CALLS_TO_FAIL - 1);
AssertingListener listener = new AssertingListener(); AssertingListener listener = new AssertingListener();
@ -128,7 +127,7 @@ public class RetryTests extends ESTestCase {
private static class AssertingListener implements ActionListener<BulkResponse> { private static class AssertingListener implements ActionListener<BulkResponse> {
private final CountDownLatch latch; private final CountDownLatch latch;
private volatile int countOnResponseCalled = 0; private final AtomicInteger countOnResponseCalled = new AtomicInteger();
private volatile Throwable lastFailure; private volatile Throwable lastFailure;
private volatile BulkResponse response; private volatile BulkResponse response;
@ -142,19 +141,19 @@ public class RetryTests extends ESTestCase {
@Override @Override
public void onResponse(BulkResponse bulkItemResponses) { public void onResponse(BulkResponse bulkItemResponses) {
latch.countDown();
this.response = bulkItemResponses; this.response = bulkItemResponses;
countOnResponseCalled++; countOnResponseCalled.incrementAndGet();
latch.countDown();
} }
@Override @Override
public void onFailure(Throwable e) { public void onFailure(Throwable e) {
latch.countDown();
this.lastFailure = e; this.lastFailure = e;
latch.countDown();
} }
public void assertOnResponseCalled() { public void assertOnResponseCalled() {
assertThat(countOnResponseCalled, equalTo(1)); assertThat(countOnResponseCalled.get(), equalTo(1));
} }
public void assertResponseWithNumberOfItems(int numItems) { public void assertResponseWithNumberOfItems(int numItems) {