use of org.elasticsearch.common.SuppressLoggerChecks in project elasticsearch by elastic.
the class AbstractLifecycleRunnableTests method testDoRunDoesNotRunWhenStoppedOrClosed.
@SuppressLoggerChecks(reason = "mock usage")
public void testDoRunDoesNotRunWhenStoppedOrClosed() throws Exception {
Callable<?> runCallable = mock(Callable.class);
// it's stopped or closed
when(lifecycle.stoppedOrClosed()).thenReturn(true);
AbstractLifecycleRunnable runnable = new AbstractLifecycleRunnable(lifecycle, logger) {
@Override
public void onFailure(Exception e) {
fail("It should not fail");
}
@Override
protected void doRunInLifecycle() throws Exception {
fail("Should not run with lifecycle stopped or closed.");
}
};
runnable.run();
InOrder inOrder = inOrder(lifecycle, logger, runCallable);
inOrder.verify(lifecycle).stoppedOrClosed();
inOrder.verify(logger).trace(anyString());
// onAfter uses it too, but we're not testing it here
inOrder.verify(lifecycle).stoppedOrClosed();
inOrder.verifyNoMoreInteractions();
}
use of org.elasticsearch.common.SuppressLoggerChecks in project elasticsearch by elastic.
the class DeprecationLogger method deprecated.
/**
* Logs a deprecated message to the deprecation log, as well as to the local {@link ThreadContext}.
*
* @param threadContexts The node's {@link ThreadContext} (outside of concurrent tests, this should only ever have one context).
* @param message The deprecation message.
* @param params The parameters used to fill in the message, if any exist.
*/
@SuppressLoggerChecks(reason = "safely delegates to logger")
void deprecated(final Set<ThreadContext> threadContexts, final String message, final Object... params) {
final Iterator<ThreadContext> iterator = threadContexts.iterator();
if (iterator.hasNext()) {
final String formattedMessage = LoggerMessageFormat.format(message, params);
final String warningHeaderValue = formatWarning(formattedMessage);
assert WARNING_HEADER_PATTERN.matcher(warningHeaderValue).matches();
assert extractWarningValueFromWarningHeader(warningHeaderValue).equals(escape(formattedMessage));
while (iterator.hasNext()) {
try {
final ThreadContext next = iterator.next();
next.addResponseHeader("Warning", warningHeaderValue, DeprecationLogger::extractWarningValueFromWarningHeader);
} catch (final IllegalStateException e) {
// ignored; it should be removed shortly
}
}
logger.warn(formattedMessage);
} else {
logger.warn(message, params);
}
}
Aggregations