Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.

1 /* 2 * ========================================================================3 * 4 * Copyright 2001-2003 The Apache Software Foundation.5 *6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 * 10 * http://www.apache.org/licenses/LICENSE-2.011 * 12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 * 18 * ========================================================================19 */20 package org.apache.cactus.sample.servlet.unit;21 22 importjavax.servlet.ServletOutputStream;23 24 importorg.apache.cactus.ServletTestCase;25 26 /**27 * Verify that the Cactus client side only reads the test result *after* the28 * test is finished (ie after the test result has been saved in the application29 * scope). This JUnit test need to be the first one to be run. Otherwise, the30 * test result might be that of the previous test and not the current test one,31 * thus proving nothing !!32 *33 * @version $Id: TestClientServerSynchronization.java,v 1.3 2004/02/29 16:36:44 vmassol Exp $34 */35 publicclass TestClientServerSynchronization extendsServletTestCase36 {37 /**38 * Verify that the test result can be returned correctly even when the39 * logic in the method to test takes a long time and thus it verifies that40 * the test result is only returned after it has been written in the41 * application scope on the server side.42 * 43 * @exception Exception on test failure44 */45 publicvoid testLongProcess() throwsException46 {47 ServletOutputStream os = response.getOutputStream();48 49 os.print("<html><head><Long Process></head><body>");50 os.flush();51 52 // do some processing that takes a while ...53 Thread.sleep(3000);54 os.println("Some data</body></html>");55 }56 57 //-------------------------------------------------------------------------58 59 /**60 * Verify that when big amount of data is returned by the servlet output61 * stream, it does not io-block.62 * 63 * @exception Exception on test failure64 */65 publicvoid testLotsOfData() throwsException66 {67 ServletOutputStream os = response.getOutputStream();68 69 os.println("<html><head>Lots of Data</head><body>");70 os.flush();71 72 for (int i = 0; i < 5000; i++)73 {74 os.println("<p>Lots and lots of data here");75 }76 77 os.println("</body></html>");78 }79 }80