[TEST] Pass class level test logging to external nodes
This commit passes the test logging annotation from the class level to the external nodes as well. Closes #8552
This commit is contained in:
parent
83bb65a020
commit
84066128ed
|
@ -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<String, String> loggingLevels = LoggingListener.getLoggersAndLevelsFromAnnotation(logging);
|
||||
ImmutableSettings.Builder finalSettings = ImmutableSettings.settingsBuilder();
|
||||
if (loggingLevels != null) {
|
||||
for (Map.Entry<String, String> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -76,6 +76,18 @@ public class LoggingListener extends RunListener {
|
|||
}
|
||||
|
||||
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) {
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue