Force java9 log4j hack in testing

This commit is contained in:
Ryan Ernst 2016-05-21 13:41:38 -07:00
parent b26f5711d6
commit 41a5c0cfa1
4 changed files with 40 additions and 1 deletions

View File

@ -27,6 +27,10 @@ import org.apache.log4j.helpers.ThreadLocalMap;
public class Java9Hack { public class Java9Hack {
public static void fixLog4j() { public static void fixLog4j() {
System.out.println("Fixing log4j");
if (MDC.mdc.tlm == null) {
System.out.println("FOR REAL");
MDC.mdc.tlm = new ThreadLocalMap(); MDC.mdc.tlm = new ThreadLocalMap();
} }
}
} }

View File

@ -0,0 +1,28 @@
/*
* Licensed to Elasticsearch under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.log4j;
import org.elasticsearch.test.ESTestCase;
public class Java9HackTests extends ESTestCase {
public void testJava9Hack() {
assertNotNull(MDC.mdc.tlm != null);
}
}

View File

@ -27,6 +27,7 @@ import java.util.Arrays;
import org.apache.log4j.Appender; import org.apache.log4j.Appender;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.log4j.MDC;
import org.elasticsearch.cli.MockTerminal; import org.elasticsearch.cli.MockTerminal;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; import org.elasticsearch.env.Environment;

View File

@ -20,6 +20,8 @@
package org.elasticsearch.bootstrap; package org.elasticsearch.bootstrap;
import com.carrotsearch.randomizedtesting.RandomizedRunner; import com.carrotsearch.randomizedtesting.RandomizedRunner;
import org.apache.log4j.Java9Hack;
import org.apache.lucene.util.Constants;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.elasticsearch.SecureSM; import org.elasticsearch.SecureSM;
import org.elasticsearch.common.Strings; import org.elasticsearch.common.Strings;
@ -89,6 +91,10 @@ public class BootstrapForTesting {
throw new RuntimeException("found jar hell in test classpath", e); throw new RuntimeException("found jar hell in test classpath", e);
} }
if (Constants.JRE_IS_MINIMUM_JAVA9) {
Java9Hack.fixLog4j();
}
// install security manager if requested // install security manager if requested
if (systemPropertyAsBoolean("tests.security.manager", true)) { if (systemPropertyAsBoolean("tests.security.manager", true)) {
try { try {