You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/13 07:19:56 UTC
svn commit: r627266 - in
/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress: ./
Benchmark.java MassiveRepositoryTest.java StressTestRCSProvider.java
StressTestSpeed.java StressTestVersioningProvider.java
Author: ajaquith
Date: Tue Feb 12 22:19:55 2008
New Revision: 627266
URL: http://svn.apache.org/viewvc?rev=627266&view=rev
Log:
Initial commit.
Added:
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/Benchmark.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/MassiveRepositoryTest.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestRCSProvider.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestSpeed.java
incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestVersioningProvider.java
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/Benchmark.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/Benchmark.java?rev=627266&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/Benchmark.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/Benchmark.java Tue Feb 12 22:19:55 2008
@@ -0,0 +1,35 @@
+/*
+ JSPWiki - a JSP-based WikiWiki clone.
+
+ Copyright (C) 2001-2007 Janne Jalkanen (Janne.Jalkanen@iki.fi)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package stress;
+
+import org.apache.commons.lang.time.StopWatch;
+
+public class Benchmark extends StopWatch
+{
+ /**
+ * How many operations/second?
+ */
+ public String toString( int operations )
+ {
+ double totalTime = getTime();
+
+ return Double.toString( (operations/totalTime) * 1000.0 );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/MassiveRepositoryTest.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/MassiveRepositoryTest.java?rev=627266&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/MassiveRepositoryTest.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/MassiveRepositoryTest.java Tue Feb 12 22:19:55 2008
@@ -0,0 +1,134 @@
+package stress;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.Random;
+
+import junit.framework.TestCase;
+
+import com.ecyrd.jspwiki.TestEngine;
+import com.ecyrd.jspwiki.TextUtil;
+import com.ecyrd.jspwiki.WikiProvider;
+import com.ecyrd.jspwiki.providers.CachingProvider;
+import com.ecyrd.jspwiki.providers.FileSystemProvider;
+
+public class MassiveRepositoryTest extends TestCase
+{
+ Properties props = new Properties();
+
+ TestEngine engine;
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ props.load( TestEngine.findTestProperties("/jspwiki_vers.properties") );
+
+ props.setProperty( CachingProvider.PROP_CACHECAPACITY, "1000" );
+ engine = new TestEngine(props);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ // Remove file
+ File f = new File( files );
+
+ TestEngine.deleteAll(f);
+ }
+
+ private String getName( int i )
+ {
+ String baseName = "Page";
+ return baseName + i;
+ }
+
+ public void testMassiveRepository1()
+ throws Exception
+ {
+ String baseText = "!This is a page %d\r\n\r\nX\r\n\r\nLinks to [%1], [%2], [%3], [%4], [%5], [%6], [%7], [%8], [%9], [%0]";
+ int numPages = 1000;
+ int numRevisions = 1000;
+ int numRenders = 10000;
+ int tickmarks = 100;
+
+ Random random = new Random();
+ Benchmark sw = new Benchmark();
+ sw.start();
+
+ System.out.println("Creating "+numPages+" pages");
+ //
+ // Create repository
+ //
+
+ int pm = numPages/tickmarks;
+
+ for( int i = 0; i < numPages; i++ )
+ {
+ String name = getName(i);
+ String text = TextUtil.replaceString( baseText, "%d", name );
+
+ for( int r = 0; r < 10; r++ )
+ {
+ text = TextUtil.replaceString( text, "%"+r, getName(i+r-5) );
+ }
+
+ engine.saveText( name, text );
+ if( i % pm == 0 ) { System.out.print("."); System.out.flush(); }
+ }
+
+ System.out.println("\nTook "+sw.toString()+", which is "+sw.toString(numPages)+" adds/second");
+ //
+ // Create new versions
+ //
+ sw.stop();
+ sw.reset();
+ sw.start();
+
+ System.out.println("Checking in "+numRevisions+" revisions");
+ pm = numRevisions/tickmarks;
+
+ for( int i = 0; i < numRevisions; i++ )
+ {
+ String page = getName( random.nextInt( numPages ) );
+
+ String content = engine.getPureText( page, WikiProvider.LATEST_VERSION );
+
+ content = TextUtil.replaceString( content, "X", "XX" );
+
+ engine.saveText( page, content );
+
+ if( i % pm == 0 ) { System.out.print("."); System.out.flush(); }
+ }
+
+ System.out.println("\nTook "+sw.toString()+", which is "+sw.toString(numRevisions)+" adds/second");
+
+ assertEquals( "Right number of pages", numPages, engine.getPageCount() );
+
+ //
+ // Rendering random pages
+ //
+ sw.stop();
+ sw.reset();
+ sw.start();
+
+ System.out.println("Rendering "+numRenders+" pages");
+ pm = numRenders/tickmarks;
+
+ for( int i = 0; i < numRenders; i++ )
+ {
+ String page = getName( random.nextInt( numPages ) );
+
+ String content = engine.getHTML( page, WikiProvider.LATEST_VERSION );
+
+ if( i % pm == 0 ) { System.out.print("."); System.out.flush(); }
+ }
+
+ sw.stop();
+ System.out.println("\nTook "+sw.toString()+", which is "+sw.toString(numRenders)+" renders/second");
+
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestRCSProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestRCSProvider.java?rev=627266&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestRCSProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestRCSProvider.java Tue Feb 12 22:19:55 2008
@@ -0,0 +1,153 @@
+package stress;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.providers.*;
+
+/**
+ * Does stress testing on the RCSProvider.
+ */
+public class StressTestRCSProvider extends TestCase
+{
+ public static final String NAME1 = "Test1";
+
+ Properties props = new Properties();
+
+ TestEngine engine;
+
+ public StressTestRCSProvider( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties("/jspwiki_rcs.properties") );
+ props.setProperty( CachingProvider.PROP_CACHECAPACITY, "10000" );
+ engine = new TestEngine(props);
+ }
+
+ public void tearDown()
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+
+ f.delete();
+
+ f = new File( files+File.separator+"RCS", NAME1+FileSystemProvider.FILE_EXT+",v" );
+
+ f.delete();
+
+ f = new File( files, "RCS" );
+
+ f.delete();
+ }
+
+ /**
+ * Bug report by Anon: RCS under Windows 2k:
+ * <PRE>
+ * In getPageInfo of RCSFileProvider:
+ *
+ * Problem:
+ *
+ * With a longer rlog result, the break clause in the last "else if"
+ * breaks out of the reading loop before all the lines in the full
+ * rlog have been read in. This causes the process.wait() to hang.
+ *
+ * Suggested quick fix:
+ *
+ * Always read all the contents of the rlog, even if it is slower.
+ * </PRE>
+ *
+ */
+
+ public void testMillionChanges()
+ throws Exception
+ {
+ String text = "";
+ String name = NAME1;
+ int maxver = 2000; // Save 2000 versions.
+ Benchmark mark = new Benchmark();
+
+ mark.start();
+ for( int i = 0; i < maxver; i++ )
+ {
+ text = text + ".";
+ engine.saveText( name, text );
+ }
+ mark.stop();
+
+ System.out.println("Benchmark: "+mark.toString(2000)+" pages/second");
+ WikiPage pageinfo = engine.getPage( NAME1 );
+
+ assertEquals( "wrong version", maxver, pageinfo.getVersion() );
+ // +2 comes from \r\n at the end of each file.
+ assertEquals( "wrong text", maxver+2, engine.getText(NAME1).length() );
+ }
+
+ private void runMassiveFileTest(int maxpages) throws Exception
+ {
+ String text = "Testing, 1, 2, 3: ";
+ String name = NAME1;
+ Benchmark mark = new Benchmark();
+
+ System.out.println("Building a massive repository of "+maxpages+" pages...");
+
+ mark.start();
+ for( int i = 0; i < maxpages; i++ )
+ {
+ engine.saveText( name+i, text+i );
+ }
+ mark.stop();
+
+ System.out.println("Total time to save "+maxpages+" pages was "+mark.toString() );
+ System.out.println("Saved "+mark.toString(maxpages)+" pages/second");
+
+ mark.reset();
+
+ mark.start();
+ Collection pages = engine.getPageManager().getAllPages();
+ mark.stop();
+
+ System.out.println("Got a list of all pages in "+mark);
+
+ mark.reset();
+ mark.start();
+
+ for( Iterator i = pages.iterator(); i.hasNext(); )
+ {
+ String foo = engine.getPureText( (WikiPage)i.next() );
+
+ assertNotNull( foo );
+ }
+ mark.stop();
+
+ System.out.println("Read through all of the pages in "+mark);
+ System.out.println("which is "+mark.toString(maxpages)+" pages/second");
+ }
+
+ public void testMillionFiles1() throws Exception
+ {
+ runMassiveFileTest(100);
+ }
+
+ public void testMillionFiles2() throws Exception
+ {
+ runMassiveFileTest(1000);
+ }
+
+ public void testMillionFiles3() throws Exception
+ {
+ runMassiveFileTest(10000);
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( StressTestRCSProvider.class );
+ }
+}
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestSpeed.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestSpeed.java?rev=627266&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestSpeed.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestSpeed.java Tue Feb 12 22:19:55 2008
@@ -0,0 +1,113 @@
+package stress;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.providers.*;
+
+public final class StressTestSpeed extends TestCase
+{
+ private static int ITERATIONS = 100;
+ public static final String NAME1 = "Test1";
+
+ Properties props = new Properties();
+
+ TestEngine engine;
+
+ public StressTestSpeed( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties("/jspwiki_rcs.properties") );
+
+ props.setProperty( "jspwiki.usePageCache", "true" );
+ props.setProperty( "jspwiki.newRenderingEngine", "true" );
+
+ engine = new TestEngine(props);
+ }
+
+ public void tearDown()
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+
+ f.delete();
+
+ f = new File( files+File.separator+"RCS", NAME1+FileSystemProvider.FILE_EXT+",v" );
+
+ f.delete();
+
+ f = new File( files, "RCS" );
+
+ f.delete();
+ }
+
+ public void testSpeed1()
+ throws Exception
+ {
+ InputStream is = getClass().getResourceAsStream("/TextFormattingRules.txt");
+ Reader in = new InputStreamReader( is, "ISO-8859-1" );
+ StringWriter out = new StringWriter();
+ Benchmark mark = new Benchmark();
+
+ FileUtil.copyContents( in, out );
+
+ engine.saveText( NAME1, out.toString() );
+
+ mark.start();
+
+ for( int i = 0; i < ITERATIONS; i++ )
+ {
+ String txt = engine.getHTML( NAME1 );
+ assertTrue( 0 != txt.length() );
+ }
+
+ mark.stop();
+
+ System.out.println( ITERATIONS+" pages took "+mark+" (="+
+ mark.getTime()/ITERATIONS+" ms/page)" );
+ }
+
+ public void testSpeed2()
+ throws Exception
+ {
+ InputStream is = getClass().getResourceAsStream("/TestPlugins.txt");
+ Reader in = new InputStreamReader( is, "ISO-8859-1" );
+ StringWriter out = new StringWriter();
+ Benchmark mark = new Benchmark();
+
+ FileUtil.copyContents( in, out );
+
+ engine.saveText( NAME1, out.toString() );
+
+ mark.start();
+
+ for( int i = 0; i < ITERATIONS; i++ )
+ {
+ String txt = engine.getHTML( NAME1 );
+ assertTrue( 0 != txt.length() );
+ }
+
+ mark.stop();
+
+ System.out.println( ITERATIONS+" plugin pages took "+mark+" (="+
+ mark.getTime()/ITERATIONS+" ms/page)" );
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite( StressTestSpeed.class );
+ }
+
+ public static void main( String[] argv )
+ {
+ junit.textui.TestRunner.run(suite());
+ }
+}
+
Added: incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestVersioningProvider.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestVersioningProvider.java?rev=627266&view=auto
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestVersioningProvider.java (added)
+++ incubator/jspwiki/branches/JSPWIKI_STRIPES_BRANCH/tests/stress/StressTestVersioningProvider.java Tue Feb 12 22:19:55 2008
@@ -0,0 +1,137 @@
+package stress;
+
+import junit.framework.*;
+import java.io.*;
+import java.util.*;
+
+import com.ecyrd.jspwiki.*;
+import com.ecyrd.jspwiki.providers.*;
+
+public class StressTestVersioningProvider extends TestCase
+{
+ public static final String NAME1 = "Test1";
+
+ Properties props = new Properties();
+
+ TestEngine engine;
+
+ public StressTestVersioningProvider( String s )
+ {
+ super( s );
+ }
+
+ public void setUp()
+ throws Exception
+ {
+ props.load( TestEngine.findTestProperties("/jspwiki_vers.properties") );
+
+ props.setProperty( CachingProvider.PROP_CACHECAPACITY, "10000" );
+ engine = new TestEngine(props);
+ }
+
+ public void tearDown()
+ {
+ String files = props.getProperty( FileSystemProvider.PROP_PAGEDIR );
+
+ // Remove file
+ File f = new File( files, NAME1+FileSystemProvider.FILE_EXT );
+ f.delete();
+
+ f = new File( files, "OLD" );
+
+ TestEngine.deleteAll(f);
+ }
+
+ public void testMillionChanges()
+ throws Exception
+ {
+ String text = "";
+ String name = NAME1;
+ int maxver = 2000; // Save 2000 versions.
+ Benchmark mark = new Benchmark();
+
+ mark.start();
+ for( int i = 0; i < maxver; i++ )
+ {
+ text = text + ".";
+ engine.saveText( name, text );
+ }
+
+ mark.stop();
+
+ System.out.println("Benchmark: "+mark.toString(2000)+" pages/second");
+ WikiPage pageinfo = engine.getPage( NAME1 );
+
+ assertEquals( "wrong version", maxver, pageinfo.getVersion() );
+
+ // +2 comes from \r\n.
+ assertEquals( "wrong text", maxver+2, engine.getText(NAME1).length() );
+ }
+
+ private void runMassiveFileTest(int maxpages)
+ throws Exception
+ {
+ String text = "Testing, 1, 2, 3: ";
+ String name = NAME1;
+ Benchmark mark = new Benchmark();
+
+ System.out.println("Building a massive repository of "+maxpages+" pages...");
+
+ mark.start();
+ for( int i = 0; i < maxpages; i++ )
+ {
+ engine.saveText( name+i, text+i );
+ }
+ mark.stop();
+
+ System.out.println("Total time to save "+maxpages+" pages was "+mark.toString() );
+ System.out.println("Saved "+mark.toString(maxpages)+" pages/second");
+
+ mark.reset();
+
+ mark.start();
+ Collection pages = engine.getPageManager().getAllPages();
+ mark.stop();
+
+ System.out.println("Got a list of all pages in "+mark);
+
+ mark.reset();
+ mark.start();
+
+ for( Iterator i = pages.iterator(); i.hasNext(); )
+ {
+ String foo = engine.getPureText( (WikiPage)i.next() );
+
+ assertNotNull( foo );
+ }
+ mark.stop();
+
+ System.out.println("Read through all of the pages in "+mark);
+ System.out.println("which is "+mark.toString(maxpages)+" pages/second");
+ }
+
+ public void testMillionFiles1() throws Exception
+ {
+ runMassiveFileTest(100);
+ }
+
+ public void testMillionFiles2() throws Exception
+ {
+ runMassiveFileTest(1000);
+ }
+
+ public void testMillionFiles3() throws Exception
+ {
+ runMassiveFileTest(10000);
+ }
+ /*
+ public void testMillionFiles4()throws Exception
+ {
+ runMassiveFileTest(100000);
+ }
+ */
+ public static Test suite()
+ {
+ return new TestSuite( StressTestVersioningProvider.class );
+ }
+}