Source Code Cross Referenced for RuntimeAdditionalTest43.java in  » Apache-Harmony-Java-SE » java-package » java » lang » 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 » Apache Harmony Java SE » java package » java.lang 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:
018:        /**
019:         * @author Serguei S.Zapreyev
020:         * @version $Revision$
021:         */package java.lang;
022:
023:        import java.io.File;
024:
025:        import junit.framework.TestCase;
026:
027:        /*
028:         * Created on March 29, 2006
029:         *
030:         * This RuntimeAdditionalTest class is used to test the Core API Runtime class
031:         * 
032:         */
033:
034:        /**
035:         * ###############################################################################
036:         * ###############################################################################
037:         * TODO: 1. should be adopted for linux
038:         * ###############################################################################
039:         * ###############################################################################
040:         */
041:
042:        public class RuntimeAdditionalTest43 extends TestCase {
043:            /**
044:             *  create thread to write and read its streams
045:             *  slightly investigate is the buffering implemented for out
046:             *  (and what about in?)
047:             */
048:            class thread11 extends Thread {
049:                public void run() {
050:                    String cmnd2 = null;
051:                    if (RuntimeAdditionalTest0.os.equals("Win")
052:                            || RuntimeAdditionalTest0.os.equals("Lin")) {
053:                        //cmnd2 = "java -cp \""+System.getProperty("java.class.path")+"\" RuntimeAdditionalSupport2";
054:                        //cmnd2 = "java "+(System.getProperty("java.class.path").length() > 0 ? "-cp \""+System.getProperty("java.class.path")+"\"":"")+" RuntimeAdditionalSupport2";
055:                        //                cmnd2 = "java "
056:                        //                        + (System.getProperty("java.class.path").length() > 0 ? "-cp "
057:                        //                                + System.getProperty("java.class.path")
058:                        //                                : "") + " RuntimeAdditionalSupport2";
059:                        String ttt = System.getProperty("vm.boot.class.path")
060:                                + (System.getProperty("java.class.path")
061:                                        .length() > 0 ? File.pathSeparator
062:                                        + System.getProperty("java.class.path")
063:                                        : "");
064:                        cmnd2 = RuntimeAdditionalTest0.javaStarter
065:                                + " -Xbootclasspath/a:" + ttt + " -cp " + ttt
066:                                + " java.lang.RuntimeAdditionalSupport2";
067:                        /**/System.out.println("|" + cmnd2 + "|");
068:                    } else {
069:                        fail("WARNING (test_41): unknown operating system.");
070:                    }
071:                    try {
072:                        /**/System.out.println("thread11: 1");
073:                        ppp44 = Runtime.getRuntime().exec(cmnd2);
074:                        try {
075:                            Thread.sleep(2000);
076:                        } catch (Exception e) {
077:                        }
078:                        try {
079:                            ppp44.exitValue();
080:                            System.out
081:                                    .println("WARNING (test_41): java-pipe does not work.");
082:                        } catch (IllegalThreadStateException e) {
083:                        }
084:                        java.io.OutputStream os4 = ppp44.getOutputStream();
085:                        ppp44.getErrorStream();
086:                        java.io.InputStream is4 = ppp44.getInputStream();
087:                        /**/System.out.println("thread11: 2");
088:
089:                        int ia;
090:                        while (true && !flg33) {
091:                            if (flg22) {
092:                                flg22 = false;
093:                                if (stage2 == 0) {
094:                                    /**/System.out
095:                                            .println("thread11: stage1 - 1");
096:                                    os4.write('Z');
097:                                    os4.write(10);
098:                                    stage1 = 1;
099:                                    flg0 = true;
100:                                } else if (stage2 == 1) {
101:                                    /**/System.out
102:                                            .println("thread11: stage1 - 2");
103:                                    os4.flush();
104:                                    stage1 = 2;
105:                                    flg0 = true;
106:                                } else if (stage2 == 2) {
107:                                    /**/System.out
108:                                            .println("thread11: stage1 - 3");
109:                                    os4.write('Z');
110:                                    os4.write('S');
111:                                    os4.write('S');
112:                                    os4.write(10);
113:                                    os4.flush();
114:                                    stage1 = 3;
115:                                    flg0 = true;
116:                                } else if (stage2 == 3) {
117:                                    /**/System.out
118:                                            .println("thread11: stage1 - 4");
119:                                    byte[] bbb = new byte[] { 'S', 'e', 'r',
120:                                            'g', 'u', 'e', 'i', ' ', 'S', 't',
121:                                            'e', 'p', 'a', 'n', 'o', 'v', 'i',
122:                                            'c', 'h' };
123:                                    stage1 = 4;
124:                                    flg0 = true;
125:                                    int iii = 0;
126:                                    while (count < 5 && !flg33) {
127:                                        while (iii < 1000/*0*/) {
128:                                            ///**/System.out.println(count+"|"+flg3);
129:                                            os4.write(bbb);
130:                                            os4.write(10);
131:                                            iii++;
132:                                            try {
133:                                                Thread.sleep(2);
134:                                            } catch (Exception e) {
135:                                            }
136:                                        }
137:                                    }
138:                                    stage1 = 5;
139:                                    flg0 = true;
140:                                    os4.write(3);
141:                                    while ((ia = is4.available()) != 0) {
142:                                        bbb = new byte[ia];
143:                                        is4.read(bbb);
144:                                        count++;
145:                                        try {
146:                                            Thread.sleep(2);
147:                                        } catch (Exception e) {
148:                                        }
149:                                    }
150:                                    /**/System.out
151:                                            .println("------------------------------------");
152:                                    ppp44.destroy();
153:                                    ppp44.waitFor();
154:                                    /**/System.out
155:                                            .println("------------------------------------");
156:                                    break;
157:                                }
158:                            }
159:                            try {
160:                                Thread.sleep(20);
161:                            } catch (Exception e) {
162:                            }
163:                        }
164:
165:                    } catch (Exception eeee) {
166:                        eeee.printStackTrace();
167:                        fail("ERROR (test_41, thread11): unexpected exception.");
168:                    }
169:                }
170:
171:                protected void finalize() throws Throwable {
172:                    super .finalize();
173:                    /**/System.out.println("thread11: finalize");
174:                    System.out.flush();
175:                }
176:            }
177:
178:            class thread22 extends Thread {
179:                public void run() {
180:                    if (RuntimeAdditionalTest0.os.equals("Win")
181:                            || RuntimeAdditionalTest0.os.equals("Lin")) {
182:                    } else {
183:                        fail("WARNING (test_41): unknown operating system.");
184:                    }
185:                    try {
186:                        /**/System.out.println("thread22: 1");
187:                        try {
188:                            Thread.sleep(3000);
189:                        } catch (Exception e) {
190:                        }
191:                        java.io.OutputStream os4 = ppp44.getOutputStream();
192:                        java.io.InputStream es4 = ppp44.getErrorStream();
193:                        java.io.InputStream is4 = ppp44.getInputStream();
194:                        /**/System.out.println("thread22: 2");
195:                        ///\\\while (es4.available() == 0) {}
196:                        byte[] bbb5 = new byte[is4.available()];
197:                        is4.read(bbb5);
198:                        /**/System.out.println(new String(bbb5));
199:                        ///\\\while (is4.available() == 0) {}
200:                        /**/System.out.println("thread22: 21");
201:                        Thread.sleep(100);
202:                        bbb5 = new byte[is4.available()];
203:                        is4.read(bbb5);
204:                        /**/System.out.println(new String(bbb5));
205:                        /**/System.out.println("thread22: 22");
206:
207:                        //special test case (zero array):
208:                        byte[] bbb6 = new byte[0];
209:                        is4.read(bbb6);
210:                        os4.write(bbb6);
211:                        /**/System.out.println("thread22: 23");
212:
213:                        flg22 = true;
214:                        int ia;
215:                        while (true) {
216:                            if (flg0) {
217:                                int ii = 0;
218:                                flg0 = false;
219:                                if (stage1 == 1) {
220:                                    /**/System.out
221:                                            .println("thread22: stage2 - 1");
222:                                    while ((ia = es4.available()) == 0
223:                                            && ii < 500) {
224:                                        ii++;
225:                                        try {
226:                                            Thread.sleep(1);
227:                                        } catch (Exception e) {
228:                                        }
229:                                    }
230:                                    if ((ia = is4.available()) != 0) {
231:                                        System.out
232:                                                .println("ERROR (test_41, thread22): Nothing should be readable before flush.");
233:                                        /**/System.out.println(ia);
234:                                        while (is4.available() != 0) {
235:                                            os4.flush();
236:                                            /*System.out.println("=" + */is4
237:                                                    .available()/*)*/;
238:                                            /*System.out.println("|"
239:                                                    + Character.toString((char) */is4
240:                                                    .read()/*) + "|")*/;
241:                                        }
242:                                        System.out
243:                                                .println("######################################################");
244:                                        System.out
245:                                                .println("## test_41 WARNING: unbuffered stream is diagnosed. ##");
246:                                        System.out
247:                                                .println("######################################################");
248:                                        flg33 = true;
249:                                        return;
250:                                    }
251:                                    stage2 = 1;
252:                                    flg22 = true;
253:                                } else if (stage1 == 2) {
254:                                    /**/System.out
255:                                            .println("thread22: stage2 - 2");
256:                                    if ((ia = is4.available()) != 2
257:                                            && is4.read() != 'Z'
258:                                            && is4.read() != 10) {
259:                                        System.out
260:                                                .println("ERROR (test_41, thread22): Z'10' should be to read.");
261:                                        flg33 = true;
262:                                        return;
263:                                    }
264:                                    stage2 = 2;
265:                                    flg22 = true;
266:                                } else if (stage1 == 3) {
267:                                    /**/System.out
268:                                            .println("thread22: stage2 - 3");
269:                                    if ((ia = is4.available()) != 4
270:                                            && is4.read() != 'Z'
271:                                            && is4.read() != 'S'
272:                                            && is4.read() != 'S'
273:                                            && is4.read() != 10) {
274:                                        System.out
275:                                                .println("ERROR (test_41, thread22): ZSS'10' should be to read.");
276:                                        //ppp44.destroy();
277:                                        flg33 = true;
278:                                        return;
279:                                    }
280:                                    stage2 = 3;
281:                                    flg22 = true;
282:                                } else if (stage1 == 4) {
283:                                    /**/System.out
284:                                            .println("thread22: stage2 - 4");
285:                                    while ((ia = is4.available()) != 0
286:                                            || stage1 != 5) {
287:                                        /**/System.out
288:                                                .println("thread22 length of reading: "
289:                                                        + ia);
290:                                        byte[] bbb = new byte[ia];
291:                                        is4.read(bbb);
292:                                        count++;
293:                                        try {
294:                                            Thread.sleep(2);
295:                                        } catch (Exception e) {
296:                                        }
297:                                    }
298:                                    try {
299:                                        Thread.sleep(1000);
300:                                    } catch (Exception e) {
301:                                    }
302:                                    /**/System.out.println("thread22: "
303:                                            + count);
304:                                    System.out.println("#####################");
305:                                    System.out.println("## test_41 PASSED. ##");
306:                                    System.out.println("#####################");
307:                                    flg33 = true;
308:                                    return;
309:                                }
310:                            }
311:                            try {
312:                                Thread.sleep(20);
313:                            } catch (Exception e) {
314:                            }
315:                        }
316:
317:                    } catch (Exception eeee) {
318:                        eeee.printStackTrace();
319:                        fail("ERROR (test_41, thread22): unexpected exception.");
320:                    }
321:                }
322:
323:                protected void finalize() throws Throwable {
324:                    super .finalize();
325:                    /**/System.out.println("thread22: finalize");
326:                    System.out.flush();
327:                }
328:            }
329:
330:            static Process ppp44 = null;
331:
332:            static int count = 0;
333:
334:            static int stage1 = 0;
335:
336:            static int stage2 = 0;
337:
338:            static boolean flg0 = false;
339:
340:            static boolean flg22 = false;
341:
342:            static boolean flg33 = false;
343:
344:            public void test_41() {
345:                System.out.println("==test_41===");
346:                if (RuntimeAdditionalTest0.os.equals("Unk")) {
347:                    fail("WARNING (test_41): unknown operating system.");
348:                } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
349:                    return;
350:                }
351:
352:                Runtime.runFinalizersOnExit(true);
353:                Thread t1 = null;
354:                Thread t2 = null;
355:                try {
356:                    t1 = new thread11();
357:                    t1.start();
358:                    t2 = new thread22();
359:                    t2.start();
360:                    //t2.join();
361:                    //t1.join();
362:                    while (!flg33) {
363:                        try {
364:                            Thread.sleep(10);
365:                        } catch (Exception e) {
366:                        }
367:                    }
368:                    try {
369:                        Thread.sleep(1000);
370:                    } catch (Exception e) {
371:                    }
372:                    ppp44.destroy();
373:                    ppp44.waitFor();
374:                    /**/System.out.println("== joined ===");
375:                } catch (Exception e) {
376:                    e.printStackTrace();
377:                    try {
378:                        ppp44.destroy();
379:                    } catch (Exception eee) {
380:                        eee.printStackTrace();
381:                        return;
382:                    }
383:                }
384:            }
385:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.