diff --git a/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreBackwardCompatibilityTests.java b/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreBackwardCompatibilityTests.java index 831b0ce374b..c296d9cf0c2 100644 --- a/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreBackwardCompatibilityTests.java +++ b/src/test/java/org/elasticsearch/search/functionscore/FunctionScoreBackwardCompatibilityTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction; import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest; +import org.elasticsearch.test.junit.annotations.TestLogging; import org.junit.Test; import java.io.IOException; @@ -40,6 +41,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*; /** */ +@TestLogging("action.search:TRACE") public class FunctionScoreBackwardCompatibilityTests extends ElasticsearchBackwardsCompatIntegrationTest { /** diff --git a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java index b8a2fdbf8c1..3eba8be5c80 100644 --- a/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java +++ b/src/test/java/org/elasticsearch/test/ElasticsearchBackwardsCompatIntegrationTest.java @@ -24,10 +24,13 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.cluster.routing.ShardRouting; +import org.elasticsearch.common.logging.ESLogger; 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 +40,8 @@ import org.junit.Ignore; import java.io.File; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import static org.hamcrest.Matchers.is; @@ -109,11 +114,14 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti } protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException { + TestLogging logging = getClass().getAnnotation(TestLogging.class); + final Map loggerLevels = LoggingListener.getLoggersAndLevelsFromAnnotation(logging); TestCluster cluster = super.buildTestCluster(scope, seed); + ExternalNode externalNode = new ExternalNode(backwardsCompatibilityPath(), randomLong(), new SettingsSource() { @Override public Settings node(int nodeOrdinal) { - return externalNodeSettings(nodeOrdinal); + return externalNodeSettings(nodeOrdinal, loggerLevels); } @Override @@ -147,10 +155,17 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti return ExternalNode.REQUIRED_SETTINGS; } + protected Settings nodeSettings(int nodeOrdinal) { + return nodeSettings(nodeOrdinal, new HashMap()); + } + protected Settings nodeSettings(int nodeOrdinal, Map loggerLevels) { ImmutableSettings.Builder builder = ImmutableSettings.builder().put(requiredSettings()) .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) // run same transport / disco as external .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName()); + for (Map.Entry level : loggerLevels.entrySet()) { + builder.put("logger." + level.getKey(), level.getValue()); + } if (compatibilityVersion().before(Version.V_1_3_2)) { // if we test against nodes before 1.3.2 we disable all the compression due to a known bug // see #7210 @@ -174,7 +189,11 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti } } + protected Settings externalNodeSettings(int nodeOrdinal, Map loggerLevels) { + return nodeSettings(nodeOrdinal, loggerLevels); + } + protected Settings externalNodeSettings(int nodeOrdinal) { - return nodeSettings(nodeOrdinal); + return nodeSettings(nodeOrdinal, new HashMap()); } } diff --git a/src/test/java/org/elasticsearch/test/InternalTestCluster.java b/src/test/java/org/elasticsearch/test/InternalTestCluster.java index 9f07c3b42ff..7ff3a738218 100644 --- a/src/test/java/org/elasticsearch/test/InternalTestCluster.java +++ b/src/test/java/org/elasticsearch/test/InternalTestCluster.java @@ -288,7 +288,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;