01: /*
02: * ========================================================================
03: *
04: * Copyright 2001-2003 The Apache Software Foundation.
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
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;
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 238816 2004-02-29 16:36:46Z vmassol $
34: */
35: public class TestClientServerSynchronization extends ServletTestCase {
36: /**
37: * Verify that the test result can be returned correctly even when the
38: * logic in the method to test takes a long time and thus it verifies that
39: * the test result is only returned after it has been written in the
40: * application scope on the server side.
41: *
42: * @exception Exception on test failure
43: */
44: public void testLongProcess() throws Exception {
45: ServletOutputStream os = response.getOutputStream();
46:
47: os.print("<html><head><Long Process></head><body>");
48: os.flush();
49:
50: // do some processing that takes a while ...
51: Thread.sleep(3000);
52: os.println("Some data</body></html>");
53: }
54:
55: //-------------------------------------------------------------------------
56:
57: /**
58: * Verify that when big amount of data is returned by the servlet output
59: * stream, it does not io-block.
60: *
61: * @exception Exception on test failure
62: */
63: public void testLotsOfData() throws Exception {
64: ServletOutputStream os = response.getOutputStream();
65:
66: os.println("<html><head>Lots of Data</head><body>");
67: os.flush();
68:
69: for (int i = 0; i < 5000; i++) {
70: os.println("<p>Lots and lots of data here");
71: }
72:
73: os.println("</body></html>");
74: }
75: }
|