01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.util.runtime;
06:
07: import com.tc.process.LinkedJavaProcess;
08: import com.tc.process.StreamCollector;
09: import com.tc.test.TCTestCase;
10: import com.tc.test.TestConfigObject;
11:
12: import java.io.IOException;
13: import java.util.ArrayList;
14: import java.util.List;
15:
16: public class ThreadDumpTest extends TCTestCase {
17:
18: // XXX: This test is known to fail under jrockit on the monkey. When we decide to deal with JRockit, we'll have to get
19: // this thing working too. One alternative: If there is a magic jrockit specific way to get thread dumps, feel to try
20: // it instead of kill -3 or CTRL-Break
21:
22: public void testDump() throws IOException, InterruptedException {
23: LinkedJavaProcess process = new LinkedJavaProcess(
24: ThreadDump.class.getName());
25:
26: List args = new ArrayList();
27: args.add("-D" + TestConfigObject.TC_BASE_DIR + "="
28: + System.getProperty(TestConfigObject.TC_BASE_DIR));
29: args
30: .add("-D"
31: + TestConfigObject.PROPERTY_FILE_LIST_PROPERTY_NAME
32: + "="
33: + System
34: .getProperty(TestConfigObject.PROPERTY_FILE_LIST_PROPERTY_NAME));
35: if (Vm.isIBM()) {
36: args.add("-Xdump:java:file=-");
37: }
38: process.setJavaArguments((String[]) args
39: .toArray(new String[args.size()]));
40:
41: System.err.println("JAVA ARGS: " + args);
42:
43: process.start();
44:
45: StreamCollector err = new StreamCollector(process.STDERR());
46: StreamCollector out = new StreamCollector(process.STDOUT());
47:
48: err.start();
49: out.start();
50:
51: process.waitFor();
52:
53: err.join();
54: out.join();
55:
56: String stderr = err.toString();
57: String stdout = out.toString();
58:
59: System.out.println("**** STDOUT BEGIN ****\n" + stdout
60: + "\n**** STDOUT END ****");
61: System.out.println("**** STDERR BEGIN ****\n" + stderr
62: + "\n**** STDERR END ****");
63:
64: assertTrue(stderr.toLowerCase().indexOf("full thread dump") >= 0
65: || stdout.toLowerCase().indexOf("full thread dump") >= 0);
66: }
67:
68: }
|