diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java index 79a0cb34121fa..a0473015ad058 100755 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/conf/Configuration.java @@ -3433,6 +3433,7 @@ void handleEndProperty() { deprecations.getDeprecatedKeyMap().get(confName); if (keyInfo != null) { + logDeprecation(keyInfo.getWarningMessage(confName, wrapper.toString())); keyInfo.clearAccessed(); for (String key : keyInfo.newKeys) { // update new keys with deprecated key's value diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java index 6dc4c5f7c50d2..4268e526ae4bb 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/conf/TestConfiguration.java @@ -87,6 +87,7 @@ import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; +import org.junit.jupiter.api.io.TempDir; import org.mockito.Mockito; public class TestConfiguration { @@ -120,7 +121,7 @@ public class TestConfiguration { @BeforeEach public void setUp() throws Exception { - conf = new Configuration(); + conf = new Configuration(false); } @AfterEach @@ -356,6 +357,33 @@ public void testFinalWarningsMultipleOverride() throws Exception { } } + @Test + public void testDeprecatedPropertyInXMLFileGeneratesLogMessage(@TempDir java.nio.file.Path tmp) throws IOException { + String oldProp = "test.deprecation.old.conf.a"; + String newProp = "test.deprecation.new.conf.a"; + Configuration.addDeprecation(oldProp, newProp); + java.nio.file.Path confFile = Files.createFile(tmp.resolve("TestConfiguration.xml")); + String confXml = "" + oldProp + "a"; + Files.write(confFile, confXml.getBytes()); + + TestAppender appender = new TestAppender(); + Logger deprecationLogger = Logger.getLogger("org.apache.hadoop.conf.Configuration.deprecation"); + deprecationLogger.addAppender(appender); + + try { + conf.addResource(new Path(confFile.toUri())); + // Properties are lazily initialized so access them to trigger the loading of the resource + conf.getProps(); + } finally { + deprecationLogger.removeAppender(appender); + } + + Pattern deprecationMsgPattern = Pattern.compile(oldProp + " in file:" + confFile + " is deprecated"); + boolean hasDeprecationMessage = appender.log.stream().map(LoggingEvent::getRenderedMessage) + .anyMatch(msg -> deprecationMsgPattern.matcher(msg).find()); + assertTrue(hasDeprecationMessage); + } + /** * A simple appender for white box testing. */ @@ -845,8 +873,7 @@ public void testToString() throws IOException { conf.addResource(fileResource); String expectedOutput = - "Configuration: core-default.xml, core-site.xml, " + - fileResource.toString(); + "Configuration: " + fileResource; assertEquals(expectedOutput, conf.toString()); }