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: *
022: */package java.lang;
023:
024: import junit.framework.TestCase;
025:
026: /*
027: * Created on March 29, 2006
028: *
029: * This RuntimeAdditionalTest class is used to test the Core API Runtime class
030: *
031: */
032:
033: /**
034: * ###############################################################################
035: * ###############################################################################
036: * TODO: 1. The following issue should be investigated:
037: * if we have uncommented "BUG: DRL is hanging here"-marked lines then the test fails on DRLVM on LINUX.
038: * So, it looks like the bug in DRLVM ("writing into the input stream of unwaiting process spoils the receiving
039: * its output").
040: * ###############################################################################
041: * ###############################################################################
042: */
043:
044: public class RuntimeAdditionalTest39 extends TestCase {
045: /**
046: * creat two cat-process, multi_byte-read from one multi_byte-write (using
047: * flushing) to another and multi_byte-read there again disturb this process
048: * by writing some unwaited info
049: */
050: public void test_37() {
051: System.out.println("==test_37===");
052: //String cmnd = null;
053: String cmnd1 = null;
054: String cmnd2 = null;
055: if (RuntimeAdditionalTest0.os.equals("Win")) {
056: //cmnd1 = RuntimeAdditionalTest0.cm + " /C tree \"C:\\Documents and Settings\"";
057: //cmnd2 = RuntimeAdditionalTest0.cm + " /C cat";
058: cmnd1 = RuntimeAdditionalTest0.treeStarter
059: + " \"C:\\Documents and Settings\"";
060: cmnd2 = RuntimeAdditionalTest0.catStarter;
061: } else if (RuntimeAdditionalTest0.os.equals("Lin")) {
062: //cmnd1 = "sh -c \"tree /lib\"";
063: //cmnd1 = "/usr/bin/tree /lib";
064: //cmnd1 = "/usr/bin/tree /bin";
065: //cmnd2 = "sh -c cat";
066: cmnd1 = RuntimeAdditionalTest0.treeStarter + " /bin";
067: cmnd2 = RuntimeAdditionalTest0.catStarter;
068: } else {
069: fail("WARNING (test_1): unknown operating system.");
070: }
071: try {
072:
073: Process pi3 = Runtime.getRuntime().exec(cmnd1);
074: //Process pi4 = Runtime.getRuntime().exec(cmnd2);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
075: try {
076: Thread.sleep(2000);
077: } catch (Exception e) {
078: }
079: java.io.OutputStream os = pi3.getOutputStream();
080: pi3.getErrorStream();
081: java.io.InputStream is = pi3.getInputStream();
082: while ((is.available()) == 0) {
083: RuntimeAdditionalTest0.doMessage("1\n");
084: }//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
085: //RuntimeAdditionalTest0.doMessage("2\n");
086: Process pi4 = Runtime.getRuntime().exec(cmnd2);//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
087: java.io.OutputStream os4 = pi4.getOutputStream();
088: pi4.getErrorStream();
089: java.io.InputStream is4 = pi4.getInputStream();
090: int ia;
091: int ia3 = 0;
092: while (true) {
093: while ((ia = is.available()) != 0) {
094: byte[] bbb = new byte[ia];
095: is.read(bbb);
096: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
097: // os.write(bbb); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!!!!!!!!!! BUG: DRL is hanging here !!!!!!!
098: // // write into the unwaiting
099: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
100: os4.write(bbb);
101: int ia2 = 0;
102: //while (ia != is4.available()) {
103: // os4.flush();
104: // ia2++;
105: // if (ia2 > 100) {
106: // System.out.println("Warning (test_37): something wrong? We are waiting about the same number of bytes as were written.");
107: // break;
108: // }
109: //}
110: while ((ia = is4.available()) != 0) {
111: byte[] bbb4 = new byte[ia];
112: is4.read(bbb4);
113: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
114: // os.write(bbb4); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< !!!!!!!!!!! BUG: DRL is hanging here !!!!!!!
115: // // write into the unwaiting
116: ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
117: //\\//\\System.out.println(new String(bbb4));
118: }
119: }
120: try {
121: pi3.exitValue();
122: while ((ia = is.available()) != 0) {
123: byte[] bbb = new byte[ia];
124: is.read(bbb);
125: os4.write(bbb);
126: while ((ia = is4.available()) != 0) {
127: byte[] bbb4 = new byte[ia];
128: is4.read(bbb4);
129: //\\//\\System.out.println(new String(bbb4));
130: }
131: }
132: break;
133: } catch (IllegalThreadStateException e) {
134: if (ia3++ > 1000)
135: break;
136: continue;
137: }
138: }
139: RuntimeAdditionalTest0.killTree();
140: RuntimeAdditionalTest0.killCat();
141: } catch (Exception eeee) {
142: eeee.printStackTrace();
143: fail("ERROR (test_37): unexpected exception.");
144: }
145: }
146: }
|