log extra information on failure of testAdapterSendReceiveCallbacks

This commit is contained in:
Boaz Leskes 2017-02-11 15:11:50 +02:00
parent c91848e6a7
commit c2494bbaed
1 changed files with 51 additions and 30 deletions

View File

@ -67,19 +67,20 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.BrokenBarrierException; import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier; import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Semaphore; import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static java.util.Collections.emptyMap; import static java.util.Collections.emptyMap;
import static java.util.Collections.emptySet; import static java.util.Collections.emptySet;
import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith; import static org.hamcrest.Matchers.startsWith;
@ -383,33 +384,41 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
class CountingTracer extends MockTransportService.Tracer { class CountingTracer extends MockTransportService.Tracer {
AtomicInteger requestsReceived = new AtomicInteger(); List<String> requestsReceived = new CopyOnWriteArrayList<>();
AtomicInteger requestsSent = new AtomicInteger(); List<String> requestsSent = new CopyOnWriteArrayList<>();
AtomicInteger responseReceived = new AtomicInteger(); List<String> responseReceived = new CopyOnWriteArrayList<>();
AtomicInteger responseSent = new AtomicInteger(); List<String> responseSent = new CopyOnWriteArrayList<>();
@Override @Override
public void receivedRequest(long requestId, String action) { public void receivedRequest(long requestId, String action) {
requestsReceived.incrementAndGet(); requestsReceived.add(requestId + ":" + action);
} }
@Override @Override
public void responseSent(long requestId, String action) { public void responseSent(long requestId, String action) {
responseSent.incrementAndGet(); responseSent.add(requestId + ":" + action);
} }
@Override @Override
public void responseSent(long requestId, String action, Throwable t) { public void responseSent(long requestId, String action, Throwable t) {
responseSent.incrementAndGet(); responseSent.add(requestId + ":" + action + ":" + t);
} }
@Override @Override
public void receivedResponse(long requestId, DiscoveryNode sourceNode, String action) { public void receivedResponse(long requestId, DiscoveryNode sourceNode, String action) {
responseReceived.incrementAndGet(); responseReceived.add(sourceNode + ":" + requestId + ":" + action);
} }
@Override @Override
public void requestSent(DiscoveryNode node, long requestId, String action, TransportRequestOptions options) { public void requestSent(DiscoveryNode node, long requestId, String action, TransportRequestOptions options) {
requestsSent.incrementAndGet(); requestsSent.add(node + ":" + requestId + ":" + action);
}
public void logRequests(String name) {
logger.info("{}: requestsSent {}", name, requestsSent);
logger.info("{}: requestsReceived {}", name, requestsReceived);
logger.info("{}: responseSent {}", name, responseSent);
logger.info("{}: responseReceived {}", name, responseReceived);
} }
} }
final CountingTracer tracerA = new CountingTracer(); final CountingTracer tracerA = new CountingTracer();
@ -426,16 +435,22 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
} }
// use assert busy as call backs are sometime called after the response have been sent // use assert busy as call backs are sometime called after the response have been sent
try {
assertBusy(() -> { assertBusy(() -> {
assertThat(tracerA.requestsReceived.get(), equalTo(0)); assertThat(tracerA.requestsReceived, empty());
assertThat(tracerA.requestsSent.get(), equalTo(1)); assertThat(tracerA.requestsSent, hasSize(1));
assertThat(tracerA.responseReceived.get(), equalTo(1)); assertThat(tracerA.responseReceived, hasSize(1));
assertThat(tracerA.responseSent.get(), equalTo(0)); assertThat(tracerA.responseSent, empty());
assertThat(tracerB.requestsReceived.get(), equalTo(1)); assertThat(tracerB.requestsReceived, hasSize(1));
assertThat(tracerB.requestsSent.get(), equalTo(0)); assertThat(tracerB.requestsSent, empty());
assertThat(tracerB.responseReceived.get(), equalTo(0)); assertThat(tracerB.responseReceived, empty());
assertThat(tracerB.responseSent.get(), equalTo(1)); assertThat(tracerB.responseSent, hasSize(1));
}); });
} catch (AssertionError e) {
tracerA.logRequests("tracerA");
tracerB.logRequests("tracerB");
throw e;
}
try { try {
serviceA serviceA
@ -446,16 +461,22 @@ public abstract class AbstractSimpleTransportTestCase extends ESTestCase {
} }
// use assert busy as call backs are sometime called after the response have been sent // use assert busy as call backs are sometime called after the response have been sent
try {
assertBusy(() -> { assertBusy(() -> {
assertThat(tracerA.requestsReceived.get(), equalTo(1)); assertThat(tracerA.requestsReceived, hasSize(1));
assertThat(tracerA.requestsSent.get(), equalTo(2)); assertThat(tracerA.requestsSent, hasSize(2));
assertThat(tracerA.responseReceived.get(), equalTo(2)); assertThat(tracerA.responseReceived, hasSize(2));
assertThat(tracerA.responseSent.get(), equalTo(1)); assertThat(tracerA.responseSent, hasSize(1));
assertThat(tracerB.requestsReceived.get(), equalTo(1)); assertThat(tracerB.requestsReceived, hasSize(1));
assertThat(tracerB.requestsSent.get(), equalTo(0)); assertThat(tracerB.requestsSent, hasSize(0));
assertThat(tracerB.responseReceived.get(), equalTo(0)); assertThat(tracerB.responseReceived, hasSize(0));
assertThat(tracerB.responseSent.get(), equalTo(1)); assertThat(tracerB.responseSent, hasSize(1));
}); });
} catch (AssertionError e) {
tracerA.logRequests("tracerA");
tracerB.logRequests("tracerB");
throw e;
}
} }
public void testVoidMessageCompressed() { public void testVoidMessageCompressed() {