Browse Source

[TEST] use logger level from test class annotation also in external nodes

closes #8552
Britta Weber 11 years ago
parent
commit
4604a68bef

+ 2 - 0
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.geo.GeoPoint;
 import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
 import org.elasticsearch.common.lucene.search.function.FieldValueFactorFunction;
 import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest;
 import org.elasticsearch.test.ElasticsearchBackwardsCompatIntegrationTest;
+import org.elasticsearch.test.junit.annotations.TestLogging;
 import org.junit.Test;
 import org.junit.Test;
 
 
 import java.io.IOException;
 import java.io.IOException;
@@ -40,6 +41,7 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
 
 
 /**
 /**
  */
  */
+@TestLogging("action.search:TRACE")
 public class FunctionScoreBackwardCompatibilityTests extends ElasticsearchBackwardsCompatIntegrationTest {
 public class FunctionScoreBackwardCompatibilityTests extends ElasticsearchBackwardsCompatIntegrationTest {
 
 
     /**
     /**

+ 21 - 2
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.IndexRoutingTable;
 import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
 import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
 import org.elasticsearch.cluster.routing.ShardRouting;
 import org.elasticsearch.cluster.routing.ShardRouting;
+import org.elasticsearch.common.logging.ESLogger;
 import org.elasticsearch.common.regex.Regex;
 import org.elasticsearch.common.regex.Regex;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.indices.recovery.RecoverySettings;
 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.Transport;
 import org.elasticsearch.transport.TransportModule;
 import org.elasticsearch.transport.TransportModule;
 import org.elasticsearch.transport.TransportService;
 import org.elasticsearch.transport.TransportService;
@@ -37,6 +40,8 @@ import org.junit.Ignore;
 
 
 import java.io.File;
 import java.io.File;
 import java.io.IOException;
 import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
 
 
 import static org.hamcrest.Matchers.is;
 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 {
     protected TestCluster buildTestCluster(Scope scope, long seed) throws IOException {
+        TestLogging logging = getClass().getAnnotation(TestLogging.class);
+        final Map<String, String> loggerLevels = LoggingListener.getLoggersAndLevelsFromAnnotation(logging);
         TestCluster cluster = super.buildTestCluster(scope, seed);
         TestCluster cluster = super.buildTestCluster(scope, seed);
+
         ExternalNode externalNode = new ExternalNode(backwardsCompatibilityPath(), randomLong(), new SettingsSource() {
         ExternalNode externalNode = new ExternalNode(backwardsCompatibilityPath(), randomLong(), new SettingsSource() {
             @Override
             @Override
             public Settings node(int nodeOrdinal) {
             public Settings node(int nodeOrdinal) {
-                return externalNodeSettings(nodeOrdinal);
+                return externalNodeSettings(nodeOrdinal, loggerLevels);
             }
             }
 
 
             @Override
             @Override
@@ -147,10 +155,17 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
         return ExternalNode.REQUIRED_SETTINGS;
         return ExternalNode.REQUIRED_SETTINGS;
     }
     }
 
 
+
     protected Settings nodeSettings(int nodeOrdinal) {
     protected Settings nodeSettings(int nodeOrdinal) {
+        return nodeSettings(nodeOrdinal, new HashMap<String, String>());
+    }
+    protected Settings nodeSettings(int nodeOrdinal, Map<String, String> loggerLevels) {
         ImmutableSettings.Builder builder = ImmutableSettings.builder().put(requiredSettings())
         ImmutableSettings.Builder builder = ImmutableSettings.builder().put(requiredSettings())
                 .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) // run same transport  / disco as external
                 .put(TransportModule.TRANSPORT_TYPE_KEY, NettyTransport.class.getName()) // run same transport  / disco as external
                 .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName());
                 .put(TransportModule.TRANSPORT_SERVICE_TYPE_KEY, TransportService.class.getName());
+        for (Map.Entry<String, String> level : loggerLevels.entrySet()) {
+            builder.put("logger." + level.getKey(), level.getValue());
+        }
         if (compatibilityVersion().before(Version.V_1_3_2)) {
         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
             // if we test against nodes before 1.3.2 we disable all the compression due to a known bug
             // see #7210
             // see #7210
@@ -174,7 +189,11 @@ public abstract class ElasticsearchBackwardsCompatIntegrationTest extends Elasti
         }
         }
     }
     }
 
 
+    protected Settings externalNodeSettings(int nodeOrdinal, Map<String, String> loggerLevels) {
+        return nodeSettings(nodeOrdinal, loggerLevels);
+    }
+
     protected Settings externalNodeSettings(int nodeOrdinal) {
     protected Settings externalNodeSettings(int nodeOrdinal) {
-        return nodeSettings(nodeOrdinal);
+        return nodeSettings(nodeOrdinal, new HashMap<String, String>());
     }
     }
 }
 }

+ 1 - 1
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"));
             builder.put("logger.level", System.getProperty("es.logger.level"));
         }
         }
         if (Strings.hasLength(System.getProperty("es.logger.prefix"))) {
         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
         // Default the watermarks to absurdly low to prevent the tests
         // from failing on nodes without enough disk space
         // from failing on nodes without enough disk space

+ 13 - 3
src/test/java/org/elasticsearch/test/junit/listeners/LoggingListener.java

@@ -76,6 +76,18 @@ public class LoggingListener extends RunListener {
     }
     }
 
 
     private Map<String, String> processTestLogging(TestLogging testLogging) {
     private Map<String, String> processTestLogging(TestLogging testLogging) {
+        Map<String, String> map = getLoggersAndLevelsFromAnnotation(testLogging);
+        if (map == null) {
+            return null;
+        }
+        for (Map.Entry<String, String> entry : map.entrySet()) {
+            ESLogger esLogger = resolveLogger(entry.getKey());
+            esLogger.setLevel(entry.getValue());
+        }
+        return map;
+    }
+
+    public static Map<String, String> getLoggersAndLevelsFromAnnotation(TestLogging testLogging) {
         if (testLogging == null) {
         if (testLogging == null) {
             return null;
             return null;
         }
         }
@@ -86,9 +98,7 @@ public class LoggingListener extends RunListener {
             if (loggerAndLevelArray.length >=2) {
             if (loggerAndLevelArray.length >=2) {
                 String loggerName = loggerAndLevelArray[0];
                 String loggerName = loggerAndLevelArray[0];
                 String level = loggerAndLevelArray[1];
                 String level = loggerAndLevelArray[1];
-                ESLogger esLogger = resolveLogger(loggerName);
-                map.put(loggerName, esLogger.getLevel());
-                esLogger.setLevel(level);
+                map.put(loggerName, level);
             }
             }
         }
         }
         return map;
         return map;