HADOOP-18614. Ensure that the config writer are closed
This commit is contained in:
parent
af20841fb1
commit
a76b225ec0
|
@ -125,9 +125,10 @@ public class TestConfigurationDeprecation {
|
|||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void testDeprecation() throws IOException {
|
||||
public void testDeprecation() throws Exception {
|
||||
addDeprecationToConfiguration();
|
||||
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||
try(AutoCloseable closeable = out::close) {
|
||||
startConfig();
|
||||
// load an old key and a new key.
|
||||
appendProperty("A", "a");
|
||||
|
@ -137,6 +138,7 @@ public class TestConfigurationDeprecation {
|
|||
endConfig();
|
||||
Path fileResource = new Path(CONFIG);
|
||||
conf.addResource(fileResource);
|
||||
}
|
||||
|
||||
// check if loading of old key with multiple new-key mappings actually loads
|
||||
// the corresponding new keys.
|
||||
|
@ -150,11 +152,13 @@ public class TestConfigurationDeprecation {
|
|||
assertEquals("d", conf.get("D"));
|
||||
|
||||
out=new BufferedWriter(new FileWriter(CONFIG2));
|
||||
try(AutoCloseable closeable = out::close) {
|
||||
startConfig();
|
||||
// load the old/new keys corresponding to the keys loaded before.
|
||||
appendProperty("B", "b");
|
||||
appendProperty("C", "c");
|
||||
endConfig();
|
||||
}
|
||||
Path fileResource1 = new Path(CONFIG2);
|
||||
conf.addResource(fileResource1);
|
||||
|
||||
|
@ -191,9 +195,10 @@ public class TestConfigurationDeprecation {
|
|||
* @throws IOException
|
||||
*/
|
||||
@Test
|
||||
public void testDeprecationForFinalParameters() throws IOException {
|
||||
public void testDeprecationForFinalParameters() throws Exception {
|
||||
addDeprecationToConfiguration();
|
||||
out=new BufferedWriter(new FileWriter(CONFIG));
|
||||
try(AutoCloseable closeable = out::close) {
|
||||
startConfig();
|
||||
// set the following keys:
|
||||
// 1.old key and final
|
||||
|
@ -207,6 +212,7 @@ public class TestConfigurationDeprecation {
|
|||
appendProperty("H", "h", true);
|
||||
appendProperty("J", "", true);
|
||||
endConfig();
|
||||
}
|
||||
Path fileResource = new Path(CONFIG);
|
||||
conf.addResource(fileResource);
|
||||
|
||||
|
@ -222,6 +228,7 @@ public class TestConfigurationDeprecation {
|
|||
assertNull(conf.get("J"));
|
||||
|
||||
out=new BufferedWriter(new FileWriter(CONFIG2));
|
||||
try(AutoCloseable closeable = out::close) {
|
||||
startConfig();
|
||||
// add the corresponding old/new keys of those added to CONFIG1
|
||||
appendProperty("B", "b");
|
||||
|
@ -230,6 +237,7 @@ public class TestConfigurationDeprecation {
|
|||
appendProperty("G", "g");
|
||||
appendProperty("I", "i");
|
||||
endConfig();
|
||||
}
|
||||
Path fileResource1 = new Path(CONFIG2);
|
||||
conf.addResource(fileResource1);
|
||||
|
||||
|
@ -245,6 +253,7 @@ public class TestConfigurationDeprecation {
|
|||
assertNull(conf.get("J"));
|
||||
|
||||
out=new BufferedWriter(new FileWriter(CONFIG3));
|
||||
try(AutoCloseable closeable = out::close) {
|
||||
startConfig();
|
||||
// change the values of all the previously loaded
|
||||
// keys (both deprecated and new)
|
||||
|
@ -259,6 +268,7 @@ public class TestConfigurationDeprecation {
|
|||
appendProperty("I", "i1");
|
||||
appendProperty("J", "j1");
|
||||
endConfig();
|
||||
}
|
||||
fileResource = new Path(CONFIG);
|
||||
conf.addResource(fileResource);
|
||||
|
||||
|
@ -440,17 +450,14 @@ public class TestConfigurationDeprecation {
|
|||
final String newZkAddressKey = CommonConfigurationKeys.ZK_ADDRESS;
|
||||
final String zkAddressValue = "dummyZkAddress";
|
||||
|
||||
try{
|
||||
out = new BufferedWriter(new FileWriter(CONFIG4));
|
||||
try(AutoCloseable closeable = out::close){
|
||||
startConfig();
|
||||
appendProperty(oldZkAddressKey, zkAddressValue);
|
||||
endConfig();
|
||||
|
||||
}
|
||||
Path fileResource = new Path(CONFIG4);
|
||||
conf.addResource(fileResource);
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
|
||||
// ACT
|
||||
conf.get(oldZkAddressKey);
|
||||
|
|
Loading…
Reference in New Issue