Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -120,7 +121,7 @@ public class TestConfiguration {

@BeforeEach
public void setUp() throws Exception {
conf = new Configuration();
conf = new Configuration(false);
}

@AfterEach
Expand Down Expand Up @@ -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 = "<configuration><property><name>" + oldProp + "</name><value>a</value></property></configuration>";
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.
*/
Expand Down Expand Up @@ -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());
}

Expand Down