Save This Page
Home » cactus-1.8.0-src » org.apache.cactus.sample.servlet.unit » [javadoc | source]
    1   /* 
    2    * ========================================================================
    3    * 
    4    * Licensed to the Apache Software Foundation (ASF) under one or more
    5    * contributor license agreements.  See the NOTICE file distributed with
    6    * this work for additional information regarding copyright ownership.
    7    * The ASF licenses this file to You under the Apache License, Version 2.0
    8    * (the "License"); you may not use this file except in compliance with
    9    * the License.  You may obtain a copy of the License at
   10    * 
   11    *   http://www.apache.org/licenses/LICENSE-2.0
   12    * 
   13    * Unless required by applicable law or agreed to in writing, software
   14    * distributed under the License is distributed on an "AS IS" BASIS,
   15    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   16    * See the License for the specific language governing permissions and
   17    * limitations under the License.
   18    * 
   19    * ========================================================================
   20    */
   21   package org.apache.cactus.sample.servlet.unit;
   22   
   23   import javax.servlet.ServletOutputStream;
   24   
   25   import org.apache.cactus.ServletTestCase;
   26   
   27   /**
   28    * Verify that the Cactus client side only reads the test result *after* the
   29    * test is finished (ie after the test result has been saved in the application
   30    * scope). This JUnit test need to be the first one to be run. Otherwise, the
   31    * test result might be that of the previous test and not the current test one,
   32    * thus proving nothing !!
   33    *
   34    * @version $Id: TestClientServerSynchronization.java 238816 2004-02-29 16:36:46Z vmassol $
   35    */
   36   public class TestClientServerSynchronization extends ServletTestCase
   37   {
   38       /**
   39        * Verify that the test result can be returned correctly even when the
   40        * logic in the method to test takes a long time and thus it verifies that
   41        * the test result is only returned after it has been written in the
   42        * application scope on the server side.
   43        * 
   44        * @exception Exception on test failure
   45        */
   46       public void testLongProcess() throws Exception
   47       {
   48           ServletOutputStream os = response.getOutputStream();
   49   
   50           os.print("<html><head><Long Process></head><body>");
   51           os.flush();
   52   
   53           // do some processing that takes a while ...
   54           Thread.sleep(3000);
   55           os.println("Some data</body></html>");
   56       }
   57   
   58       //-------------------------------------------------------------------------
   59   
   60       /**
   61        * Verify that when big amount of data is returned by the servlet output
   62        * stream, it does not io-block.
   63        * 
   64        * @exception Exception on test failure
   65        */
   66       public void testLotsOfData() throws Exception
   67       {
   68           ServletOutputStream os = response.getOutputStream();
   69   
   70           os.println("<html><head>Lots of Data</head><body>");
   71           os.flush();
   72   
   73           for (int i = 0; i < 5000; i++)
   74           {
   75               os.println("<p>Lots and lots of data here");
   76           }
   77   
   78           os.println("</body></html>");
   79       }
   80   }

Save This Page
Home » cactus-1.8.0-src » org.apache.cactus.sample.servlet.unit » [javadoc | source]