Source Code Cross Referenced for LinkedJavaProcessTest.java in  » Net » Terracotta » com » tc » process » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.process 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tc.process;
006:
007:        import com.tc.test.TCTestCase;
008:
009:        import java.io.File;
010:
011:        /**
012:         * Unit test for {@link LinkedJavaProcess}.
013:         */
014:        public class LinkedJavaProcessTest extends TCTestCase {
015:            private static final boolean DEBUG = false;
016:
017:            public void testRunsRightCommand() throws Exception {
018:                LinkedJavaProcess process = new LinkedJavaProcess(
019:                        LinkedJavaProcessTestMain1.class.getName());
020:                process.start();
021:
022:                // This is actually stdout...weird Java
023:                StreamCollector outCollector = new StreamCollector(process
024:                        .getInputStream());
025:                // This is stderr
026:                StreamCollector errCollector = new StreamCollector(process
027:                        .getErrorStream());
028:
029:                outCollector.start();
030:                errCollector.start();
031:
032:                process.waitFor();
033:
034:                outCollector.join(30000);
035:                errCollector.join(30000);
036:
037:                assertEquals("Ho there!", ignoreStandardWarnings(
038:                        errCollector.toString()).trim());
039:                assertEquals("Hi there!", ignoreStandardWarnings(
040:                        outCollector.toString()).trim());
041:            }
042:
043:            private static String ignoreStandardWarnings(String input) {
044:                debugPrintln("*****  inputString=[" + input + "]");
045:
046:                String delimiter = System.getProperty("line.separator", "\n");
047:
048:                debugPrintln("*****  delimiter=[" + delimiter + "]");
049:
050:                String[] output = input.split(delimiter);
051:
052:                StringBuffer out = new StringBuffer();
053:                for (int i = 0; i < output.length; ++i) {
054:                    debugPrintln("*****  piece=[" + output[i] + "]");
055:
056:                    if (output[i].startsWith("DATA: ")) {
057:                        out.append(output[i].substring("DATA: ".length())
058:                                + delimiter);
059:                        debugPrintln("***** appending ["
060:                                + output[i].substring("DATA: ".length())
061:                                + delimiter + "] to output string");
062:                    }
063:                }
064:
065:                debugPrintln("*****  outString=[" + out.toString() + "]");
066:
067:                return out.toString();
068:            }
069:
070:            public void testIO() throws Exception {
071:                LinkedJavaProcess process = new LinkedJavaProcess(
072:                        LinkedJavaProcessTestMain2.class.getName());
073:                process.start();
074:
075:                StreamCollector outCollector = new StreamCollector(process
076:                        .getInputStream()); // stdout
077:                StreamCollector errCollector = new StreamCollector(process
078:                        .getErrorStream()); // stderr
079:
080:                outCollector.start();
081:                errCollector.start();
082:
083:                process.getOutputStream().write("Test Input!\n".getBytes());
084:                process.getOutputStream().flush();
085:
086:                process.waitFor();
087:
088:                outCollector.join(30000);
089:                errCollector.join(30000);
090:
091:                assertEquals("out: <Test Input!>", ignoreStandardWarnings(
092:                        outCollector.toString()).trim());
093:                assertEquals("err: <Test Input!>", ignoreStandardWarnings(
094:                        errCollector.toString()).trim());
095:            }
096:
097:            public void testExitCode() throws Exception {
098:                LinkedJavaProcess process = new LinkedJavaProcess(
099:                        LinkedJavaProcessTestMain3.class.getName());
100:                process.start();
101:
102:                process.waitFor();
103:                assertEquals(57, process.exitValue());
104:            }
105:
106:            public void testSetup() throws Exception {
107:                LinkedJavaProcess process = new LinkedJavaProcess(
108:                        LinkedJavaProcessTestMain4.class.getName());
109:
110:                File dir = getTempFile("mydir");
111:                assertTrue(dir.mkdirs());
112:                String pwd = dir.getCanonicalPath();
113:                process.setDirectory(dir);
114:                process
115:                        .setEnvironment(new String[] { "LD_LIBRARY_PATH=myenv" });
116:                process.setJavaArguments(new String[] { "-Dljpt.foo=myprop" });
117:
118:                process.start();
119:
120:                StreamCollector outCollector = new StreamCollector(process
121:                        .getInputStream()); // stdout
122:                StreamCollector errCollector = new StreamCollector(process
123:                        .getErrorStream()); // stderr
124:
125:                outCollector.start();
126:                errCollector.start();
127:
128:                process.waitFor();
129:
130:                outCollector.join(30000);
131:                errCollector.join(30000);
132:
133:                String output = outCollector.toString();
134:                String err = errCollector.toString();
135:
136:                assertEquals("", ignoreStandardWarnings(err).trim());
137:
138:                assertContains("ljpt.foo=myprop", output);
139:                assertContains(pwd.toLowerCase(), output.toLowerCase());
140:            }
141:
142:            public void testKillingParentKillsChildren() throws Exception {
143:                File destFile = getTempFile("tkpkc-file");
144:                File child1File = new File(destFile.getAbsolutePath()
145:                        + "-child-1");
146:                File child2File = new File(destFile.getAbsolutePath()
147:                        + "-child-2");
148:                LinkedJavaProcess process = new LinkedJavaProcess(
149:                        LinkedJavaProcessTestMain5.class.getName(),
150:                        new String[] { destFile.getAbsolutePath(), "true" });
151:
152:                process.start();
153:
154:                StreamCollector stdout = new StreamCollector(process.STDOUT());
155:                stdout.start();
156:                StreamCollector stderr = new StreamCollector(process.STDERR());
157:                stderr.start();
158:
159:                long origSize = destFile.length();
160:                Thread.sleep(6000);
161:                long newSize = destFile.length();
162:
163:                System.err.println("Parent first: new=" + newSize + "  old="
164:                        + origSize);
165:                assertTrue(newSize > origSize); // Make sure it's all started + working
166:
167:                long child1OrigSize = child1File.length();
168:                long child2OrigSize = child2File.length();
169:                Thread.sleep(5000);
170:                long child1NewSize = child1File.length();
171:                long child2NewSize = child2File.length();
172:
173:                System.err.println("Child 1 first: new=" + child1NewSize
174:                        + "  old=" + child1OrigSize);
175:                System.err.println("Child 2 first: new=" + child2NewSize
176:                        + "  old=" + child2OrigSize);
177:                // Make sure the children are all started + working
178:                assertTrue(child1NewSize > child1OrigSize);
179:                assertTrue(child2NewSize > child2OrigSize);
180:
181:                System.out.println(stdout.toString());
182:                System.out.println(stderr.toString());
183:
184:                process.destroy();
185:                // wait for child process heartbeat to time out and kill themselves
186:                Thread.sleep(HeartBeatServer.PULSE_INTERVAL * 2);
187:
188:                origSize = destFile.length();
189:                Thread.sleep(5000);
190:                newSize = destFile.length();
191:
192:                System.err.println("Parent after kill: new=" + newSize
193:                        + "  old=" + origSize);
194:                assertEquals(origSize, newSize); // Make sure the parent is dead
195:
196:                child1OrigSize = child1File.length();
197:                child2OrigSize = child2File.length();
198:                Thread.sleep(5000);
199:                child1NewSize = child1File.length();
200:                child2NewSize = child2File.length();
201:                System.err.println("Child 1 after kill: new=" + child1NewSize
202:                        + "  old=" + child1OrigSize);
203:                System.err.println("Child 2 after kill: new=" + child2NewSize
204:                        + "  old=" + child2OrigSize);
205:
206:                assertEquals(child1NewSize, child1OrigSize); // Make sure child 1 is dead
207:                assertEquals(child2NewSize, child2OrigSize); // Make sure child 1 is dead
208:            }
209:
210:            private static void debugPrintln(String s) {
211:                if (DEBUG) {
212:                    System.err.println(s);
213:                }
214:            }
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.