You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by re...@apache.org on 2001/01/21 22:29:30 UTC

cvs commit: jakarta-slide/src/tests/transaction PutTestCase.java

remm        01/01/21 13:29:29

  Modified:    .        build.bat build.sh build.xml
               lib      README
               src/doc  changelog.xml installation.xml
  Added:       src/tests test.bat test.sh
               src/tests/transaction PutTestCase.java
  Log:
  - Update build scipts.
  - Add new "tests" target.
  - Add a first test written by Juergen Pill, designed to test concurrency in the
    transaction manager.
  - Update documentation (add JUnit to the optional dependencies list) and
    changelog.
  
  Revision  Changes    Path
  1.8       +2 -2      jakarta-slide/build.bat
  
  Index: build.bat
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/build.bat,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- build.bat	2000/12/18 01:21:39	1.7
  +++ build.bat	2001/01/21 21:29:20	1.8
  @@ -14,12 +14,12 @@
   
   rem else
   set _CLASSPATH=%CLASSPATH%
  -set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar;%JAVA_HOME%\lib\tools.jar;%SERVLETAPI_HOME%\lib\servlet.jar;%JAXP_HOME%\crimson.jar;%JAXP_HOME%\jaxp.jar;%JAXP_HOME%\xalan.jar
  +set CLASSPATH=%CLASSPATH%;%ANT_HOME%\lib\ant.jar;%ANT_HOME%\lib\optional.jar;%JAVA_HOME%\lib\tools.jar;%SERVLETAPI_HOME%\lib\servlet.jar;%JAXP_HOME%\crimson.jar;%JAXP_HOME%\jaxp.jar;%JAXP_HOME%\xalan.jar;.\lib\junit.jar
   goto next
   
   :noclasspath
   set _CLASSPATH=
  -set CLASSPATH=%ANT_HOME%\lib\ant.jar;%JAVA_HOME%\lib\tools.jar;%SERVLETAPI_HOME%\lib\servlet.jar;%JAXP_HOME%\crimson.jar;%JAXP_HOME%\jaxp.jar;%JAXP_HOME%\xalan.jar
  +set CLASSPATH=%ANT_HOME%\lib\ant.jar;%ANT_HOME%\lib\optional.jar;%JAVA_HOME%\lib\tools.jar;%SERVLETAPI_HOME%\lib\servlet.jar;%JAXP_HOME%\crimson.jar;%JAXP_HOME%\jaxp.jar;%JAXP_HOME%\xalan.jar;.\lib\junit.jar
   goto next
   
   :next
  
  
  
  1.6       +2 -2      jakarta-slide/build.sh
  
  Index: build.sh
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/build.sh,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- build.sh	2000/12/17 17:20:28	1.5
  +++ build.sh	2001/01/21 21:29:21	1.6
  @@ -1,6 +1,6 @@
   #! /bin/sh
   
  -# $Id: build.sh,v 1.5 2000/12/17 17:20:28 remm Exp $
  +# $Id: build.sh,v 1.6 2001/01/21 21:29:21 remm Exp $
   
   BUILDFILE=build.xml
   
  @@ -12,7 +12,7 @@
   fi
   
   if test -f ${JAVA_HOME}/lib/tools.jar ; then
  -    CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar:${ANT_HOME}/lib/ant.jar:${SERVLETAPI_HOME}/lib/servlet.jar:${JAXP_HOME}/crimson.jar:${JAXP_HOME}/jaxp.jar:${JAXP_HOME}/xalan.jar
  +    CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar:${ANT_HOME}/lib/ant.jar:${ANT_HOME}/lib/optional.jar:${SERVLETAPI_HOME}/lib/servlet.jar:${JAXP_HOME}/crimson.jar:${JAXP_HOME}/jaxp.jar:${JAXP_HOME}/xalan.jar:./lib/junit.jar
   fi
   
   # convert the existing path to unix
  
  
  
  1.64      +31 -1     jakarta-slide/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/build.xml,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- build.xml	2001/01/15 13:00:04	1.63
  +++ build.xml	2001/01/21 21:29:22	1.64
  @@ -17,6 +17,7 @@
     <property name="jaxp.home"             value="../jaxp"/>
     <property name="jmx.home"              value="../jmx"/>
     <property name="regexp.jar"            value="../jakarta-regexp/bin/jakarta-regexp-1.1.jar"/>
  +  <property name="junit.jar"             value="./lib/junit.jar"/>
     <property name="tomcat.build"          value="../build/tomcat" />
     <property name="avalon.dist"           value="../dist/avalon" />
     <property name="slide.build"           value="../build/slide" />
  @@ -42,6 +43,7 @@
       <echo message="main (default) : Builds Slide API" />
       <echo message="doc : Builds the HTML documentation" />
       <echo message="examples : Builds some examples" />
  +    <echo message="tests : Builds some tests" />
       <echo message="clean : Removes build and distribution directories" />
       <echo message="dist : Creates a packaged version of the Slide API and WebDAV servlet" />
       <echo message="" />
  @@ -77,6 +79,7 @@
       <mkdir dir="${slide.build}"/>
       <mkdir dir="${slide.build}/classes"/>
       <mkdir dir="${slide.build}/examples"/>
  +    <mkdir dir="${slide.build}/tests"/>
       <mkdir dir="${slide.build}/lib"/>
       <mkdir dir="${slide.build}/doc"/>
       <mkdir dir="${slide.build}/doc/schema"/>
  @@ -345,6 +348,27 @@
   
   
     <!-- =================================================================== -->
  +  <!-- Build some tests                                                    -->
  +  <!-- =================================================================== -->
  +  <target name="tests" depends="main, webdav-client-dist" 
  +   if="junit.present">
  +    <javac srcdir="src/tests" destdir="${slide.build}/tests"
  +     debug="on" deprecation="on" excludes="**/CVS/**"
  +     classpath="${slide.build}/classes:${webdavclient.build}/classes" />
  +    <copy todir="${slide.build}/tests">
  +      <fileset dir="src/tests">
  +        <exclude name="**/CVS/**" />
  +        <exclude name="**/*.java" />
  +      </fileset>
  +    </copy>
  +    <copy file="${webdavclient.dist}/lib/webdavlib.jar"
  +     tofile="${slide.build}/tests/webdavlib.jar" />
  +    <copy file="${junit.jar}"
  +     tofile="${slide.build}/tests/junit.jar" />
  +  </target>
  +
  +
  +  <!-- =================================================================== -->
     <!-- Clean build and distribution directories                            -->
     <!-- =================================================================== -->
     <target name="clean">
  @@ -375,6 +399,7 @@
       <mkdir dir="${slide.dist}/webapp" />
       <mkdir dir="${slide.dist}/lib" />
       <mkdir dir="${slide.dist}/examples" />
  +    <mkdir dir="${slide.dist}/tests" />
       <mkdir dir="${slide.dist}/doc" />
       <mkdir dir="${slide.dist}/wrappers" />
     </target>
  @@ -383,7 +408,7 @@
     <!-- =================================================================== -->
     <!-- Build a Slide distribution                                          -->
     <!-- =================================================================== -->
  -  <target name="dist" depends="no-debug, examples, prepare-dist, doc,
  +  <target name="dist" depends="no-debug, examples, tests, prepare-dist, doc,
      javadoc">
   
       <copy file="src/etc/MANIFEST.MF"
  @@ -441,6 +466,11 @@
       <echo message="Copying examples" />
       <copy todir="${slide.dist}/examples">
         <fileset dir="${slide.build}/examples" />
  +    </copy>
  +
  +    <echo message="Copying tests" />
  +    <copy todir="${slide.dist}/tests">
  +      <fileset dir="${slide.build}/tests" />
       </copy>
   
     </target>
  
  
  
  1.5       +1 -1      jakarta-slide/lib/README
  
  Index: README
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/lib/README,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- README	2000/07/18 22:44:55	1.4
  +++ README	2001/01/21 21:29:24	1.5
  @@ -1,4 +1,4 @@
   Put in this directory :
  -- JAXP and a JAXP compliant parser
  +- JUnit
   
   Or alternatively, if you already have them eleswhere, be sure to add them to your classpath.
  
  
  
  1.20      +13 -0     jakarta-slide/src/doc/changelog.xml
  
  Index: changelog.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/doc/changelog.xml,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- changelog.xml	2001/01/18 01:21:47	1.19
  +++ changelog.xml	2001/01/21 21:29:25	1.20
  @@ -74,6 +74,19 @@
             The WebDAV servlet now uses transaction demarcation between each
             DAV request (JP, RM)
           </update>
  +        <add>
  +          Add a new Service abstract implementation which handles mulpiple
  +          concurrent transaction contexts (JP)
  +        </add>
  +        <scode>
  +          Rename the Service abstract implementation : the single context
  +          implementation is now AbstractSimpleService, and the new multiple
  +          context implementation is AbstractService (RM)
  +        </scode>
  +        <add>
  +          Add the first test case of a test suite, based on JUnit; the first
  +          test case is testing concurrency in the transaction manager (JP, RM)
  +        </add>
         </changelog>
   
       </p>
  
  
  
  1.6       +1 -0      jakarta-slide/src/doc/installation.xml
  
  Index: installation.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-slide/src/doc/installation.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- installation.xml	2001/01/18 01:21:48	1.5
  +++ installation.xml	2001/01/21 21:29:26	1.6
  @@ -49,6 +49,7 @@
           <li>Ant optional package</li>
           <li>An Ant supported XSLT processor (Xalan or XSL:P)</li>
           <li>A JMX MBean server, and the JMX libraries</li>
  +        <li>JUnit 3.5</li>
         </ul>
       </p>
       
  
  
  
  1.1                  jakarta-slide/src/tests/test.bat
  
  Index: test.bat
  ===================================================================
  @echo off
  REM $Id: test.bat,v 1.1 2001/01/21 21:29:28 remm Exp $
  set JAVA=%JAVA_HOME%\bin\java
  set _OLD=%_CLASSPATH%
  set _CLASSPATH=..\classes;..\lib\slide.jar;..\lib\slidestores.jar;.\junit.jar;.\webdavlib.jar;%CLASSPATH%
  
  %JAVA% -classpath %_CLASSPATH% junit.swingui.TestRunner %1
  
  set _CLASSPATH=%_OLD%
  
  
  1.1                  jakarta-slide/src/tests/test.sh
  
  Index: test.sh
  ===================================================================
  #! /bin/sh
  
  # $Id: test.sh,v 1.1 2001/01/21 21:29:28 remm Exp $
  
  if [ -z "$JAVA_HOME" ] ; then
    JAVA=`which java`
    if [ -z "$JAVA" ] ; then
      echo "Cannot find JAVA. Please set your PATH."
      exit 1
    fi
    JAVA_BIN=`dirname $JAVA`
    JAVA_HOME=$JAVA_BIN/..
  fi
  
  JAVA=$JAVA_HOME/bin/java
  
  TEMPCLASSPATH=../classes:../lib/slide.jar:../lib/slidestores.jar:./junit.jar:./webdavlib.jar:$CLASSPATH
  
  if [ -z $1 ] ; then
    echo "Usage: example <pkg>";
    exit;
  fi
  $JAVA -cp $TEMPCLASSPATH junit.swingui.TestRunner $1
  
  
  
  1.1                  jakarta-slide/src/tests/transaction/PutTestCase.java
  
  Index: PutTestCase.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-slide/src/tests/transaction/PutTestCase.java,v 1.1 2001/01/21 21:29:29 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2001/01/21 21:29:29 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  package transaction;
  
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  import junit.ui.TestRunner;
  
  import org.apache.webdav.lib.Cookie;
  import org.apache.webdav.lib.Header;
  import org.apache.webdav.lib.WebdavException;
  
  // Slide
  import org.apache.webdav.lib.*;
  import org.apache.webdav.lib.methods.*;
  
  // Java
  import java.io.*;
  import java.util.*;
  
  /**
   * Test cases for the PUT method
   *
   * @author Juergen Pill
   * @version $Revision: 1.1 $
   */
  public class PutTestCase extends TestCase {
  
  
      private static final String destination = "/slide/Patients/myFile.txt";
      private static final String fileContent = "<patient1>\n <name>\n  <surname>pat rec 1</surname>\n  <firstname>1</firstname>\n  </name>\n</patient1>\n";
      private static final int    portNumber  = 8080;
  
  	
      /**
       * Class initialisation
       */
  	public PutTestCase(String name) {
          super(name);
      }
  
  
  	/**********************************************************************/
  	/*                                                                    */
  	/* public methods which are called by Junit                           */
  	/*                                                                    */
  	/**********************************************************************/
  	
  	
  
      /**
       * Test a simple PUT command
       */
      public void test1PutCommand() throws Exception {
      	System.out.println("Starting test1PutCommand");
  		excutePut(1);
  		excutePut(1);
  		excutePut(1);
  		excutePut(1);
  		excutePut(1);
  		excutePut(1);
      }
  
      /**
       * Test 10 simple PUT command
       */
      public void test10PutCommand() throws Exception {
      	System.out.println("Starting test10PutCommand");
  		excutePut(10);
      }
  
      /**
       * Test 100 simple PUT command
       */
      public void test100PutCommand() throws Exception {
      	System.out.println("Starting test100PutCommand");
  		//excutePut(100);
      }
  
  
  	
  
      /**
       * Test a simple PUT command in one thread
       */
      public void testParallel1PutCommand() throws Exception {
      	System.out.println("Starting testParallel1PutCommand");
  		parallelExcutePut(1, 1);
  		parallelExcutePut(1, 1);
  		parallelExcutePut(1, 1);
  		parallelExcutePut(1, 1);
  		parallelExcutePut(1, 1);
      }
  
      /**
       * Test 10 simple PUT command in 10 thread
       */
      public void testParallel10PutCommand() throws Exception {
      	System.out.println("Starting testParallel10PutCommand");
  		parallelExcutePut(10, 10);
      }
  
      /**
       * Test 100 simple PUT command in 100 thread
       */
      public void testParallel100PutCommand() throws Exception {
      	System.out.println("Starting testParallel100PutCommand");
  		parallelExcutePut(100, 100);
      }
  
  
  	
  	
  	
  	/**********************************************************************/
  	/*                                                                    */
  	/* private method which perform the test cases                        */
  	/*                                                                    */
  	/**********************************************************************/
  	
  	
  	
  	
  
  	
  	
  
      /**
       * Execute a multiple test cases in many threads
       */
      private void parallelExcutePut(int threadCount, int putCount) throws Exception {
      	Vector allThreads = new Vector(threadCount);
  		for (int i = 1 ; i<=threadCount; i++) {
  			allThreads.add(new Thread(new PutRunner(putCount), "parallelExcutePut-"+i));
  		}
  		for (int i = 0 ; i<threadCount; i++) {
  			((Thread)allThreads.elementAt(i)).start();
  		}
  		for (int i = 0 ; i<threadCount; i++) {
  			((Thread)allThreads.elementAt(i)).join();
  		}
  	}
  	
  
      /**
       * Execute a individual test case in many threads
       */
      private void parallelExcutePut(int threadCount) throws Exception {
  		for (int i = 1 ; i<=threadCount; i++) parallelExcutePut(threadCount, 1);
  	}
  	
  	
  	
  
      /**
       * Execute multiple test cases
       */
      private void excutePut(int putCount) throws Exception {
  		for (int i = 1 ; i<=putCount; i++) excutePut(destination+i);
  	}
  	
  	
  	
      /**
       * Execute a individual test case
       */
      private void excutePut(String resourceName) throws Exception {
  		long startTime = System.currentTimeMillis();
  	    WebdavClient client = new WebdavClient();
  		PutMethod pm = new PutMethod();
  		try {
  //        	client.setDebug(1);
  			client.startSession("localhost", portNumber);
  			client.setCredentials(new Credentials("guest", "guest"));
  			pm.setPath( resourceName );
  			pm.sendData( new StringBufferInputStream(fileContent));
  			client.executeMethod( pm );
  			
  			System.out.println( "PUT  to " + resourceName + " : " + pm.getStatusCode() +
  								"  " + pm.getStatusText() +
  								" (time: " + (System.currentTimeMillis() - startTime) + " ms)" );
  		}
  		catch (Exception e) {
  			e.printStackTrace();
  			throw e;
  		}
  		
  		assertEquals("Response code ", 200, pm.getStatusCode());
  	}
  	
  	
  	
  	/**************************************************************/
  	/* Inner class to help the thread to execute the put function */
  	/**************************************************************/
  	public class PutRunner implements Runnable{
  		int putCount;
  		public PutRunner(int putCount) {
  			this.putCount = putCount;
  		}
  		public void run() {
  			try {excutePut(putCount);}
  			catch (Exception e) {e.printStackTrace();};}
  	}
  	
  	
  	
  }