Avoid angering Log4j in TransportNodesActionTests
When logging a mock exception, Log4j attempts to render the stack trace. On a mock exception, this will be null and Log4j will hit a NullPointerException. This NullPointerException will get recorded in the status logger buffer that we use to ensure that we do not having any misuses of Log4j in production code. This commit replaces the use of a mock exception with an actual exception to avoid angering the Log4j assertions in ESTestCase.
This commit is contained in:
parent
4e996ca9f5
commit
179dd885e2
|
@ -106,12 +106,17 @@ public class TransportNodesActionTests extends ESTestCase {
|
|||
public void testNewResponse() {
|
||||
TestTransportNodesAction action = getTestTransportNodesAction();
|
||||
TestNodesRequest request = new TestNodesRequest();
|
||||
List<TestNodeResponse> expectedNodeResponses = mockList(TestNodeResponse.class, randomIntBetween(0, 2));
|
||||
List<TestNodeResponse> expectedNodeResponses = mockList(TestNodeResponse::new, randomIntBetween(0, 2));
|
||||
expectedNodeResponses.add(new TestNodeResponse());
|
||||
List<BaseNodeResponse> nodeResponses = new ArrayList<>(expectedNodeResponses);
|
||||
// This should be ignored:
|
||||
nodeResponses.add(new OtherNodeResponse());
|
||||
List<FailedNodeException> failures = mockList(FailedNodeException.class, randomIntBetween(0, 2));
|
||||
List<FailedNodeException> failures = mockList(
|
||||
() -> new FailedNodeException(
|
||||
randomAsciiOfLength(8),
|
||||
randomAsciiOfLength(8),
|
||||
new IllegalStateException(randomAsciiOfLength(8))),
|
||||
randomIntBetween(0, 2));
|
||||
|
||||
List<Object> allResponses = new ArrayList<>(expectedNodeResponses);
|
||||
allResponses.addAll(failures);
|
||||
|
@ -141,10 +146,10 @@ public class TransportNodesActionTests extends ESTestCase {
|
|||
assertEquals(clusterService.state().nodes().getDataNodes().size(), capturedRequests.size());
|
||||
}
|
||||
|
||||
private <T> List<T> mockList(Class<T> clazz, int size) {
|
||||
private <T> List<T> mockList(Supplier<T> supplier, int size) {
|
||||
List<T> failures = new ArrayList<>(size);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
failures.add(mock(clazz));
|
||||
failures.add(supplier.get());
|
||||
}
|
||||
return failures;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue