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