diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java index 1229f286297..8b0e1600003 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java @@ -28,6 +28,8 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.indices.recovery.RecoverySettings; +import org.elasticsearch.test.junit.annotations.TestLogging; +import org.elasticsearch.test.junit.listeners.LoggingListener; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportModule; import org.elasticsearch.transport.TransportService; @@ -37,6 +39,7 @@ import org.junit.Ignore; import java.io.File; import java.io.IOException; +import java.util.Map; import static org.hamcrest.Matchers.is; @@ -97,7 +100,7 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti File file = new File(path, "elasticsearch-" + version); if (!file.exists()) { throw new IllegalArgumentException("Backwards tests location is missing: " + file.getAbsolutePath()); - } + } if (!file.isDirectory()) { throw new IllegalArgumentException("Backwards tests location is not a directory: " + file.getAbsolutePath()); } @@ -124,10 +127,21 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti return new CompositeTestCluster((InternalTestCluster) cluster, between(minExternalNodes(), maxExternalNodes()), externalNode); } - protected int minExternalNodes() { - return 1; + private Settings addLoggerSettings(Settings externalNodesSettings) { + TestLogging logging = getClass().getAnnotation(TestLogging.class); + Map loggingLevels = LoggingListener.getLoggersAndLevelsFromAnnotation(logging); + ImmutableSettings.Builder finalSettings = ImmutableSettings.settingsBuilder(); + if (loggingLevels != null) { + for (Map.Entry level : loggingLevels.entrySet()) { + finalSettings.put("logger." + level.getKey(), level.getValue()); + } + } + finalSettings.put(externalNodesSettings); + return finalSettings.build(); } + protected int minExternalNodes() { return 1; } + protected int maxExternalNodes() { return 2; } @@ -169,6 +183,6 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti } protected Settings externalNodeSettings(int nodeOrdinal) { - return nodeSettings(nodeOrdinal); + return addLoggerSettings(nodeSettings(nodeOrdinal)); } } diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index d71335879db..968827854f3 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -294,7 +294,7 @@ public final class InternalTestCluster extends TestCluster { builder.put("logger.level", System.getProperty("es.logger.level")); } if (Strings.hasLength(System.getProperty("es.logger.prefix"))) { - builder.put("logger.prefix", System.getProperty("es.logger.level")); + builder.put("logger.prefix", System.getProperty("es.logger.prefix")); } // Default the watermarks to absurdly low to prevent the tests // from failing on nodes without enough disk space diff --git a/src/test/java/org/elasticsearch/test/junit/listeners/LoggingListener.java b/src/test/java/org/elasticsearch/test/junit/listeners/LoggingListener.java index 804dab9db3f..b997d880938 100644 --- a/src/test/java/org/elasticsearch/test/junit/listeners/LoggingListener.java +++ b/src/test/java/org/elasticsearch/test/junit/listeners/LoggingListener.java @@ -76,6 +76,18 @@ public class LoggingListener extends RunListener { } private Map processTestLogging(TestLogging testLogging) { + Map map = getLoggersAndLevelsFromAnnotation(testLogging); + if (map == null) { + return null; + } + for (Map.Entry entry : map.entrySet()) { + ESLogger esLogger = resolveLogger(entry.getKey()); + esLogger.setLevel(entry.getValue()); + } + return map; + } + + public static Map getLoggersAndLevelsFromAnnotation(TestLogging testLogging) { if (testLogging == null) { return null; } @@ -86,9 +98,7 @@ public class LoggingListener extends RunListener { if (loggerAndLevelArray.length >=2) { String loggerName = loggerAndLevelArray[0]; String level = loggerAndLevelArray[1]; - ESLogger esLogger = resolveLogger(loggerName); - map.put(loggerName, esLogger.getLevel()); - esLogger.setLevel(level); + map.put(loggerName, level); } } return map;