Skip to content

Commit 9f527eb

Browse files
committed
Clarify tests
1 parent b34afc1 commit 9f527eb

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

server/src/test/java/org/elasticsearch/search/SearchServiceTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public void testMaybeWrapListenerForStackTraceDebugLog() {
168168
new MockLog.ExceptionSeenEventExpectation(
169169
format("\"[%s]%s: failed to execute search request\" and an exception logged", nodeId, shardId),
170170
SearchService.class.getCanonicalName(),
171-
Level.DEBUG,
171+
Level.DEBUG, // We will throw a 400-level exception, so it should only be logged at the debug level
172172
format("[%s]%s: failed to execute search request", nodeId, shardId),
173173
IllegalArgumentException.class,
174174
exceptionMessage
@@ -187,8 +187,7 @@ public void onFailure(Exception e) {
187187
mockLog.assertAllExpectationsMatched();
188188
}
189189
};
190-
// This is a 400-level exception, so it should only be debug logged
191-
IllegalArgumentException e = new IllegalArgumentException(exceptionMessage);
190+
IllegalArgumentException e = new IllegalArgumentException(exceptionMessage); // 400-level exception
192191
listener = maybeWrapListenerForStackTrace(listener, TransportVersion.current(), nodeId, shardId, threadPool);
193192
listener.onFailure(e);
194193
}
@@ -205,7 +204,7 @@ public void testMaybeWrapListenerForStackTraceWarnLog() {
205204
new MockLog.ExceptionSeenEventExpectation(
206205
format("\"[%s]%s: failed to execute search request\" and an exception logged", nodeId, shardId),
207206
SearchService.class.getCanonicalName(),
208-
Level.WARN,
207+
Level.WARN, // We will throw a 500-level exception, so it should be logged at the warn level
209208
format("[%s]%s: failed to execute search request", nodeId, shardId),
210209
IllegalStateException.class,
211210
exceptionMessage
@@ -224,8 +223,7 @@ public void onFailure(Exception e) {
224223
mockLog.assertAllExpectationsMatched();
225224
}
226225
};
227-
// This is a 400-level exception, so it should only be debug logged
228-
IllegalStateException e = new IllegalStateException(exceptionMessage);
226+
IllegalStateException e = new IllegalStateException(exceptionMessage); // 500-level exception
229227
listener = maybeWrapListenerForStackTrace(listener, TransportVersion.current(), nodeId, shardId, threadPool);
230228
listener.onFailure(e);
231229
}

test/framework/src/main/java/org/elasticsearch/test/MockLog.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,8 @@ public void match(LogEvent event) {
344344
&& event.getThrown().getClass() == clazz
345345
&& event.getThrown().getMessage().equals(exceptionMessage);
346346

347-
if (exceptionMatches) {
348-
if (patternMatches) {
349-
seenLatch.countDown();
350-
}
347+
if (patternMatches && exceptionMatches) {
348+
seenLatch.countDown();
351349
}
352350
}
353351
}

0 commit comments

Comments
 (0)