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:
Jason Tedor 2016-08-30 18:49:39 -04:00
parent 9a58fc2348
commit abe3efdfa9
1 changed files with 16 additions and 6 deletions

View File

@ -26,6 +26,8 @@ import org.apache.lucene.util.Constants;
import org.elasticsearch.common.SuppressLoggerChecks;
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.test.ESTestCase;
import org.hamcrest.Matcher;
import org.mockito.ArgumentMatcher;
import java.io.BufferedReader;
import java.io.IOException;
@ -34,6 +36,7 @@ import java.nio.file.Path;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
@ -71,21 +74,28 @@ public class MaxMapCountCheckTests extends ESTestCase {
when(reader.readLine()).thenThrow(ioException);
final Logger logger = mock(Logger.class);
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
verify(logger).warn(
(Supplier<?>) () -> new ParameterizedMessage(
"I/O exception while trying to read [{}]", procSysVmMaxMapCountPath), ioException);
verify(logger).warn(argThat(argumentMatcher("I/O exception while trying to read [/proc/sys/vm/max_map_count]")), eq(ioException));
verify(reader).close();
reset(reader);
reset(logger);
when(reader.readLine()).thenReturn("eof");
assertThat(check.getMaxMapCount(logger), equalTo(-1L));
verify(logger).warn(eq(
(Supplier<?>) () -> new ParameterizedMessage(
"unable to parse vm.max_map_count [{}]", "eof")), any(NumberFormatException.class));
verify(logger).warn(argThat(argumentMatcher("unable to parse vm.max_map_count [eof]")), any(NumberFormatException.class));
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 {
final String rawProcSysVmMaxMapCount = Long.toString(randomIntBetween(1, Integer.MAX_VALUE));
final BufferedReader reader = mock(BufferedReader.class);