15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.File;
25 import java.net.UnknownHostException;
26 import java.rmi.RemoteException;
27 import java.rmi.registry.LocateRegistry;
28 import java.rmi.registry.Registry;
29 import java.util.Arrays;
30
31 import jdk.test.lib.thread.ProcessThread;
32 import static jdk.testlibrary.Asserts.*;
33 import jdk.testlibrary.JDKToolLauncher;
34 import jdk.testlibrary.Utils;
35 import jdk.testlibrary.OutputAnalyzer;
36 import jdk.testlibrary.ProcessTools;
37
38 /**
39 * The base class for tests of jstatd.
40 *
41 * The test sequence for TestJstatdDefaults for example is:
42 * <pre>
43 * {@code
44 * // start jstatd process
45 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy
46 *
47 * // run jps and verify its output
48 * jps -J-XX:+UsePerfData hostname
49 *
50 * // run jstat and verify its output
51 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5
52 *
53 * // stop jstatd process and verify that no unexpected exceptions have been thrown
54 * }
55 * </pre>
56 */
311 port = String.valueOf(Utils.getFreePort());
312 }
313
314 if (withExternalRegistry) {
315 Registry registry = startRegistry();
316 if (registry == null) {
317 // The port is already in use. Cancel and try with a new one.
318 continue;
319 }
320 }
321
322 jstatdThread = tryToSetupJstatdProcess();
323 }
324
325 runToolsAndVerify();
326 } finally {
327 cleanUpThread(jstatdThread);
328 }
329
330 // Verify output from jstatd
331 jdk.test.lib.process.OutputAnalyzer output = jstatdThread.getOutput();
332 assertTrue(output.getOutput().isEmpty(),
333 "jstatd should get an empty output, got: "
334 + Utils.NEW_LINE + output.getOutput());
335 assertNotEquals(output.getExitValue(), 0,
336 "jstatd process exited with unexpected exit code");
337 }
338
339 private void verifyNoRmiRegistryOnDefaultPort() throws Exception {
340 try {
341 Registry registry = LocateRegistry.getRegistry();
342 registry.list();
343 throw new Exception("There is already RMI registry on the default port: " + registry);
344 } catch (RemoteException e) {
345 // No RMI registry on default port is detected
346 }
347 }
348
349 }
|
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import java.io.File;
25 import java.net.UnknownHostException;
26 import java.rmi.RemoteException;
27 import java.rmi.registry.LocateRegistry;
28 import java.rmi.registry.Registry;
29 import java.util.Arrays;
30
31 import jdk.test.lib.thread.ProcessThread;
32 import static jdk.testlibrary.Asserts.*;
33 import jdk.testlibrary.JDKToolLauncher;
34 import jdk.testlibrary.Utils;
35 import jdk.test.lib.process.OutputAnalyzer;
36 import jdk.test.lib.process.ProcessTools;
37
38 /**
39 * The base class for tests of jstatd.
40 *
41 * The test sequence for TestJstatdDefaults for example is:
42 * <pre>
43 * {@code
44 * // start jstatd process
45 * jstatd -J-XX:+UsePerfData -J-Djava.security.policy=all.policy
46 *
47 * // run jps and verify its output
48 * jps -J-XX:+UsePerfData hostname
49 *
50 * // run jstat and verify its output
51 * jstat -J-XX:+UsePerfData -J-Duser.language=en -gcutil pid@hostname 250 5
52 *
53 * // stop jstatd process and verify that no unexpected exceptions have been thrown
54 * }
55 * </pre>
56 */
311 port = String.valueOf(Utils.getFreePort());
312 }
313
314 if (withExternalRegistry) {
315 Registry registry = startRegistry();
316 if (registry == null) {
317 // The port is already in use. Cancel and try with a new one.
318 continue;
319 }
320 }
321
322 jstatdThread = tryToSetupJstatdProcess();
323 }
324
325 runToolsAndVerify();
326 } finally {
327 cleanUpThread(jstatdThread);
328 }
329
330 // Verify output from jstatd
331 OutputAnalyzer output = jstatdThread.getOutput();
332 assertTrue(output.getOutput().isEmpty(),
333 "jstatd should get an empty output, got: "
334 + Utils.NEW_LINE + output.getOutput());
335 assertNotEquals(output.getExitValue(), 0,
336 "jstatd process exited with unexpected exit code");
337 }
338
339 private void verifyNoRmiRegistryOnDefaultPort() throws Exception {
340 try {
341 Registry registry = LocateRegistry.getRegistry();
342 registry.list();
343 throw new Exception("There is already RMI registry on the default port: " + registry);
344 } catch (RemoteException e) {
345 // No RMI registry on default port is detected
346 }
347 }
348
349 }
|