提交 04ae560f 编写于 作者: M mchung

6891701: test/java/lang/management/RuntimeMXBean/GetSystemProperties should...

6891701: test/java/lang/management/RuntimeMXBean/GetSystemProperties should restore the system property
Summary: Restore the system properties when the test finishes
Reviewed-by: jjg
上级 829c5b10
......@@ -49,6 +49,21 @@ public class GetSystemProperties {
private static final String VALUE4 = "test.property.value4";
public static void main(String[] argv) throws Exception {
// Save a copy of the original system properties
Properties props = System.getProperties();
try {
// replace the system Properties object for any modification
// in case jtreg caches a copy
System.setProperties(new Properties(props));
runTest();
} finally {
// restore original system properties
System.setProperties(props);
}
}
private static void runTest() throws Exception {
RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();
// Print all system properties
......@@ -88,7 +103,10 @@ public class GetSystemProperties {
Map<String,String> props2 = mbean.getSystemProperties();
// expect the system properties returned should be
// same as the one before adding KEY3 and KEY4
props1.equals(props2);
if (!props1.equals(props2)) {
throw new RuntimeException("Two copies of system properties " +
"are expected to be equal");
}
System.out.println("Test passed.");
}
......
......@@ -40,8 +40,21 @@ import java.lang.management.RuntimeMXBean;
public class PropertiesTest {
private static int NUM_MYPROPS = 3;
public static void main(String[] argv) throws Exception {
Properties sysProps = System.getProperties();
// Save a copy of the original system properties
Properties props = System.getProperties();
try {
// replace the system Properties object for any modification
// in case jtreg caches a copy
System.setProperties(new Properties(props));
runTest(props.size());
} finally {
// restore original system properties
System.setProperties(props);
}
}
private static void runTest(int sysPropsCount) throws Exception {
// Create a new system properties using the old one
// as the defaults
Properties myProps = new Properties( System.getProperties() );
......@@ -65,10 +78,10 @@ public class PropertiesTest {
System.out.println(i++ + ": " + key + " : " + value);
}
if (props.size() != NUM_MYPROPS + sysProps.size()) {
if (props.size() != NUM_MYPROPS + sysPropsCount) {
throw new RuntimeException("Test Failed: " +
"Expected number of properties = " +
NUM_MYPROPS + sysProps.size() +
NUM_MYPROPS + sysPropsCount +
" but found = " + props.size());
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册