Fix failing max map count check test
This commit fixes failing max map count check test due to the use of a logging message supplier.
This commit is contained in:
parent
9a58fc2348
commit
abe3efdfa9
|
@ -26,6 +26,8 @@ import org.apache.lucene.util.Constants;
|
||||||
import org.elasticsearch.common.SuppressLoggerChecks;
|
import org.elasticsearch.common.SuppressLoggerChecks;
|
||||||
import org.elasticsearch.common.io.PathUtils;
|
import org.elasticsearch.common.io.PathUtils;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
import org.mockito.ArgumentMatcher;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -34,6 +36,7 @@ import java.nio.file.Path;
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.argThat;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.reset;
|
import static org.mockito.Mockito.reset;
|
||||||
|
@ -71,21 +74,28 @@ public class MaxMapCountCheckTests extends ESTestCase {
|
||||||
when(reader.readLine()).thenThrow(ioException);
|
when(reader.readLine()).thenThrow(ioException);
|
||||||
final Logger logger = mock(Logger.class);
|
final Logger logger = mock(Logger.class);
|
||||||
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
|
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
|
||||||
verify(logger).warn(
|
verify(logger).warn(argThat(argumentMatcher("I/O exception while trying to read [/proc/sys/vm/max_map_count]")), eq(ioException));
|
||||||
(Supplier<?>) () -> new ParameterizedMessage(
|
|
||||||
"I/O exception while trying to read [{}]", procSysVmMaxMapCountPath), ioException);
|
|
||||||
verify(reader).close();
|
verify(reader).close();
|
||||||
|
|
||||||
reset(reader);
|
reset(reader);
|
||||||
reset(logger);
|
reset(logger);
|
||||||
when(reader.readLine()).thenReturn("eof");
|
when(reader.readLine()).thenReturn("eof");
|
||||||
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
|
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
|
||||||
verify(logger).warn(eq(
|
verify(logger).warn(argThat(argumentMatcher("unable to parse vm.max_map_count [eof]")), any(NumberFormatException.class));
|
||||||
(Supplier<?>) () -> new ParameterizedMessage(
|
|
||||||
"unable to parse vm.max_map_count [{}]", "eof")), any(NumberFormatException.class));
|
|
||||||
verify(reader).close();
|
verify(reader).close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ArgumentMatcher<Supplier<?>> argumentMatcher(final String message) {
|
||||||
|
return new ArgumentMatcher<Supplier<?>>() {
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object o) {
|
||||||
|
final Supplier<?> supplier = (Supplier<?>)o;
|
||||||
|
final ParameterizedMessage parameterizedMessage = (ParameterizedMessage) supplier.get();
|
||||||
|
return parameterizedMessage.getFormattedMessage().equals(message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void testMaxMapCountCheckRead() throws IOException {
|
public void testMaxMapCountCheckRead() throws IOException {
|
||||||
final String rawProcSysVmMaxMapCount = Long.toString(randomIntBetween(1, Integer.MAX_VALUE));
|
final String rawProcSysVmMaxMapCount = Long.toString(randomIntBetween(1, Integer.MAX_VALUE));
|
||||||
final BufferedReader reader = mock(BufferedReader.class);
|
final BufferedReader reader = mock(BufferedReader.class);
|
||||||
|
|
Loading…
Reference in New Issue