7187882: TEST_BUG: java/rmi/activation/checkusage/CheckUsage.java fails intermittently
Summary: Tighten up JavaVM test library API, and adjust tests to match.
Reviewed-by: mchung, dmocek
diff --git a/test/java/rmi/testlibrary/JavaVM.java b/test/java/rmi/testlibrary/JavaVM.java
index 6ccae91..c363f8e 100644
--- a/test/java/rmi/testlibrary/JavaVM.java
+++ b/test/java/rmi/testlibrary/JavaVM.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
private OutputStream outputStream = System.out;
private OutputStream errorStream = System.err;
private String policyFileName = null;
+ private StreamPipe outPipe;
+ private StreamPipe errPipe;
private static void mesg(Object mesg) {
System.err.println("JAVAVM: " + mesg.toString());
@@ -145,13 +147,12 @@
}
mesg("command = " + Arrays.asList(javaCommand).toString());
- System.err.println("");
vm = Runtime.getRuntime().exec(javaCommand);
/* output from the execed process may optionally be captured. */
- StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
- StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
+ outPipe = StreamPipe.plugTogether(vm.getInputStream(), this.outputStream);
+ errPipe = StreamPipe.plugTogether(vm.getErrorStream(), this.errorStream);
}
public void destroy() {
@@ -161,7 +162,25 @@
vm = null;
}
- protected Process getVM() {
- return vm;
+ /**
+ * Waits for the subprocess to exit, joins the pipe threads to ensure that
+ * all output is collected, and returns its exit status.
+ */
+ public int waitFor() throws InterruptedException {
+ if (vm == null)
+ throw new IllegalStateException("can't wait for JavaVM that hasn't started");
+
+ int status = vm.waitFor();
+ outPipe.join();
+ errPipe.join();
+ return status;
+ }
+
+ /**
+ * Starts the subprocess, waits for it to exit, and returns its exit status.
+ */
+ public int execute() throws IOException, InterruptedException {
+ start();
+ return waitFor();
}
}