001: package stress;
002:
003: import junit.framework.*;
004: import java.io.*;
005: import java.util.*;
006: import com.ecyrd.jspwiki.*;
007: import com.ecyrd.jspwiki.providers.*;
008:
009: public final class StressTestSpeed extends TestCase {
010: private static int ITERATIONS = 100;
011: public static final String NAME1 = "Test1";
012:
013: Properties props = new Properties();
014:
015: TestEngine engine;
016:
017: public StressTestSpeed(String s) {
018: super (s);
019: }
020:
021: public void setUp() throws Exception {
022: props.load(TestEngine
023: .findTestProperties("/jspwiki_rcs.properties"));
024:
025: props.setProperty("jspwiki.usePageCache", "true");
026: props.setProperty("jspwiki.newRenderingEngine", "true");
027:
028: engine = new TestEngine(props);
029: }
030:
031: public void tearDown() {
032: String files = props
033: .getProperty(FileSystemProvider.PROP_PAGEDIR);
034:
035: File f = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
036:
037: f.delete();
038:
039: f = new File(files + File.separator + "RCS", NAME1
040: + FileSystemProvider.FILE_EXT + ",v");
041:
042: f.delete();
043:
044: f = new File(files, "RCS");
045:
046: f.delete();
047: }
048:
049: public void testSpeed1() throws Exception {
050: InputStream is = getClass().getResourceAsStream(
051: "/TextFormattingRules.txt");
052: Reader in = new InputStreamReader(is, "ISO-8859-1");
053: StringWriter out = new StringWriter();
054: Benchmark mark = new Benchmark();
055:
056: FileUtil.copyContents(in, out);
057:
058: engine.saveText(NAME1, out.toString());
059:
060: mark.start();
061:
062: for (int i = 0; i < ITERATIONS; i++) {
063: String txt = engine.getHTML(NAME1);
064: assertTrue(0 != txt.length());
065: }
066:
067: mark.stop();
068:
069: System.out.println(ITERATIONS + " pages took " + mark + " (="
070: + mark.getTime() / ITERATIONS + " ms/page)");
071: }
072:
073: public void testSpeed2() throws Exception {
074: InputStream is = getClass().getResourceAsStream(
075: "/TestPlugins.txt");
076: Reader in = new InputStreamReader(is, "ISO-8859-1");
077: StringWriter out = new StringWriter();
078: Benchmark mark = new Benchmark();
079:
080: FileUtil.copyContents(in, out);
081:
082: engine.saveText(NAME1, out.toString());
083:
084: mark.start();
085:
086: for (int i = 0; i < ITERATIONS; i++) {
087: String txt = engine.getHTML(NAME1);
088: assertTrue(0 != txt.length());
089: }
090:
091: mark.stop();
092:
093: System.out.println(ITERATIONS + " plugin pages took " + mark
094: + " (=" + mark.getTime() / ITERATIONS + " ms/page)");
095: }
096:
097: public static Test suite() {
098: return new TestSuite(StressTestSpeed.class);
099: }
100:
101: public static void main(String[] argv) {
102: junit.textui.TestRunner.run(suite());
103: }
104: }
|