KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > sample > servlet > unit > TestClientServerSynchronization


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 at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * 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 and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.sample.servlet.unit;
21
22 import javax.servlet.ServletOutputStream JavaDoc;
23
24 import org.apache.cactus.ServletTestCase;
25
26 /**
27  * Verify that the Cactus client side only reads the test result *after* the
28  * test is finished (ie after the test result has been saved in the application
29  * scope). This JUnit test need to be the first one to be run. Otherwise, the
30  * 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 public class TestClientServerSynchronization extends ServletTestCase
36 {
37     /**
38      * Verify that the test result can be returned correctly even when the
39      * logic in the method to test takes a long time and thus it verifies that
40      * the test result is only returned after it has been written in the
41      * application scope on the server side.
42      *
43      * @exception Exception on test failure
44      */

45     public void testLongProcess() throws Exception JavaDoc
46     {
47         ServletOutputStream JavaDoc 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 output
61      * stream, it does not io-block.
62      *
63      * @exception Exception on test failure
64      */

65     public void testLotsOfData() throws Exception JavaDoc
66     {
67         ServletOutputStream JavaDoc 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
Popular Tags