|
87 | 87 | import org.apache.log4j.AppenderSkeleton;
|
88 | 88 | import org.apache.log4j.Logger;
|
89 | 89 | import org.apache.log4j.spi.LoggingEvent;
|
| 90 | +import org.junit.jupiter.api.io.TempDir; |
90 | 91 | import org.mockito.Mockito;
|
91 | 92 |
|
92 | 93 | public class TestConfiguration {
|
@@ -120,7 +121,7 @@ public class TestConfiguration {
|
120 | 121 |
|
121 | 122 | @BeforeEach
|
122 | 123 | public void setUp() throws Exception {
|
123 |
| - conf = new Configuration(); |
| 124 | + conf = new Configuration(false); |
124 | 125 | }
|
125 | 126 |
|
126 | 127 | @AfterEach
|
@@ -356,6 +357,33 @@ public void testFinalWarningsMultipleOverride() throws Exception {
|
356 | 357 | }
|
357 | 358 | }
|
358 | 359 |
|
| 360 | + @Test |
| 361 | + public void testDeprecatedPropertyInXMLFileGeneratesLogMessage(@TempDir java.nio.file.Path tmp) throws IOException { |
| 362 | + String oldProp = "test.deprecation.old.conf.a"; |
| 363 | + String newProp = "test.deprecation.new.conf.a"; |
| 364 | + Configuration.addDeprecation(oldProp, newProp); |
| 365 | + java.nio.file.Path confFile = Files.createFile(tmp.resolve("TestConfiguration.xml")); |
| 366 | + String confXml = "<configuration><property><name>" + oldProp + "</name><value>a</value></property></configuration>"; |
| 367 | + Files.write(confFile, confXml.getBytes()); |
| 368 | + |
| 369 | + TestAppender appender = new TestAppender(); |
| 370 | + Logger deprecationLogger = Logger.getLogger("org.apache.hadoop.conf.Configuration.deprecation"); |
| 371 | + deprecationLogger.addAppender(appender); |
| 372 | + |
| 373 | + try { |
| 374 | + conf.addResource(new Path(confFile.toUri())); |
| 375 | + // Properties are lazily initialized so access them to trigger the loading of the resource |
| 376 | + conf.getProps(); |
| 377 | + } finally { |
| 378 | + deprecationLogger.removeAppender(appender); |
| 379 | + } |
| 380 | + |
| 381 | + Pattern deprecationMsgPattern = Pattern.compile(oldProp + " in file:" + confFile + " is deprecated"); |
| 382 | + boolean hasDeprecationMessage = appender.log.stream().map(LoggingEvent::getRenderedMessage) |
| 383 | + .anyMatch(msg -> deprecationMsgPattern.matcher(msg).find()); |
| 384 | + assertTrue(hasDeprecationMessage); |
| 385 | + } |
| 386 | + |
359 | 387 | /**
|
360 | 388 | * A simple appender for white box testing.
|
361 | 389 | */
|
@@ -845,8 +873,7 @@ public void testToString() throws IOException {
|
845 | 873 | conf.addResource(fileResource);
|
846 | 874 |
|
847 | 875 | String expectedOutput =
|
848 |
| - "Configuration: core-default.xml, core-site.xml, " + |
849 |
| - fileResource.toString(); |
| 876 | + "Configuration: " + fileResource; |
850 | 877 | assertEquals(expectedOutput, conf.toString());
|
851 | 878 | }
|
852 | 879 |
|
|
0 commit comments