diff --git a/core/src/test/java/org/elasticsearch/bootstrap/MaxMapCountCheckTests.java b/core/src/test/java/org/elasticsearch/bootstrap/MaxMapCountCheckTests.java index debb7b4bb3c..cbfc14a7d04 100644 --- a/core/src/test/java/org/elasticsearch/bootstrap/MaxMapCountCheckTests.java +++ b/core/src/test/java/org/elasticsearch/bootstrap/MaxMapCountCheckTests.java @@ -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> argumentMatcher(final String message) { + return new ArgumentMatcher>() { + @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);