KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > util > runtime > ThreadDumpTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.util.runtime;
6
7 import com.tc.process.LinkedJavaProcess;
8 import com.tc.process.StreamCollector;
9 import com.tc.test.TCTestCase;
10 import com.tc.test.TestConfigObject;
11
12 import java.io.IOException JavaDoc;
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 JavaDoc, InterruptedException JavaDoc {
23     LinkedJavaProcess process = new LinkedJavaProcess(ThreadDump.class.getName());
24
25     List JavaDoc args = new ArrayList JavaDoc();
26     String JavaDoc libPath = System.getProperty("java.library.path", "");
27     if (!"".equals(libPath)) {
28       args.add("-Djava.library.path=" + libPath);
29     }
30
31     args.add("-D" + TestConfigObject.TC_BASE_DIR + "=" + System.getProperty(TestConfigObject.TC_BASE_DIR));
32     args.add("-D" + TestConfigObject.PROPERTY_FILE_LIST_PROPERTY_NAME + "="
33              + System.getProperty(TestConfigObject.PROPERTY_FILE_LIST_PROPERTY_NAME));
34     process.setJavaArguments((String JavaDoc[]) args.toArray(new String JavaDoc[args.size()]));
35
36     System.err.println("JAVA ARGS: " + args);
37
38     process.start();
39
40     StreamCollector err = new StreamCollector(process.STDERR());
41     StreamCollector out = new StreamCollector(process.STDOUT());
42
43     err.start();
44     out.start();
45
46     process.waitFor();
47
48     err.join();
49     out.join();
50
51     String JavaDoc stderr = err.toString();
52     String JavaDoc stdout = out.toString();
53
54     System.out.println("**** STDOUT BEGIN ****\n" + stdout + "\n**** STDOUT END ****");
55     System.out.println("**** STDERR BEGIN ****\n" + stderr + "\n**** STDERR END ****");
56
57     assertTrue(stderr.toLowerCase().indexOf("full thread dump") >= 0
58                || stdout.toLowerCase().indexOf("full thread dump") >= 0);
59   }
60 }
61
Popular Tags