8163581: Heap Parameters in HSDB cannot handle G1CollectedHeap
authorysuenaga
Thu, 25 Aug 2016 12:24:16 +0900
changeset 40950 41e6677cdff5
parent 40691 6e84cac08e9a
child 40951 bd511b7c7097
child 40958 43f23b5c9fed
8163581: Heap Parameters in HSDB cannot handle G1CollectedHeap Reviewed-by: dholmes, sjohanss
jdk/test/sun/tools/jhsdb/BasicLauncherTest.java
--- a/jdk/test/sun/tools/jhsdb/BasicLauncherTest.java	Wed Aug 24 20:51:37 2016 +0200
+++ b/jdk/test/sun/tools/jhsdb/BasicLauncherTest.java	Thu Aug 25 12:24:16 2016 +0900
@@ -35,6 +35,7 @@
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.InputStreamReader;
 import java.io.File;
 import java.util.ArrayList;
@@ -84,15 +85,24 @@
             ProcessBuilder processBuilder = new ProcessBuilder(launcher.getCommand());
             processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
             Process toolProcess = processBuilder.start();
-            toolProcess.getOutputStream().write("quit\n".getBytes());
-            toolProcess.getOutputStream().close();
+
+            try (OutputStream out = toolProcess.getOutputStream()) {
+                out.write("universe\n".getBytes());
+                out.write("quit\n".getBytes());
+            }
 
             // By default child process output stream redirected to pipe, so we are reading it in foreground.
-            BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()));
+            Exception unexpected = null;
+            try (BufferedReader reader = new BufferedReader(new InputStreamReader(toolProcess.getInputStream()))) {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    line = line.trim();
+                    System.out.println(line);
 
-            String line;
-            while ((line = reader.readLine()) != null) {
-                System.out.println(line.trim());
+                    if (line.contains("unknown subtype of CollectedHeap")) {
+                        unexpected = new RuntimeException("CollectedHeap type should be known.");
+                    }
+                }
             }
 
             toolProcess.waitFor();
@@ -100,6 +110,10 @@
             if (toolProcess.exitValue() != 0) {
                 throw new RuntimeException("FAILED CLHSDB terminated with non-zero exit code " + toolProcess.exitValue());
             }
+
+            if (unexpected != null) {
+                throw unexpected;
+            }
         } catch (Exception ex) {
             throw new RuntimeException("Test ERROR " + ex, ex);
         } finally {