001: package stress;
002:
003: import junit.framework.*;
004: import java.io.*;
005: import java.util.*;
006:
007: import com.ecyrd.jspwiki.*;
008: import com.ecyrd.jspwiki.providers.*;
009:
010: public class StressTestVersioningProvider extends TestCase {
011: public static final String NAME1 = "Test1";
012:
013: Properties props = new Properties();
014:
015: TestEngine engine;
016:
017: public StressTestVersioningProvider(String s) {
018: super (s);
019: }
020:
021: public void setUp() throws Exception {
022: props.load(TestEngine
023: .findTestProperties("/jspwiki_vers.properties"));
024:
025: props.setProperty(CachingProvider.PROP_CACHECAPACITY, "10000");
026: engine = new TestEngine(props);
027: }
028:
029: public void tearDown() {
030: String files = props
031: .getProperty(FileSystemProvider.PROP_PAGEDIR);
032:
033: // Remove file
034: File f = new File(files, NAME1 + FileSystemProvider.FILE_EXT);
035: f.delete();
036:
037: f = new File(files, "OLD");
038:
039: TestEngine.deleteAll(f);
040: }
041:
042: public void testMillionChanges() throws Exception {
043: String text = "";
044: String name = NAME1;
045: int maxver = 2000; // Save 2000 versions.
046: Benchmark mark = new Benchmark();
047:
048: mark.start();
049: for (int i = 0; i < maxver; i++) {
050: text = text + ".";
051: engine.saveText(name, text);
052: }
053:
054: mark.stop();
055:
056: System.out.println("Benchmark: " + mark.toString(2000)
057: + " pages/second");
058: WikiPage pageinfo = engine.getPage(NAME1);
059:
060: assertEquals("wrong version", maxver, pageinfo.getVersion());
061:
062: // +2 comes from \r\n.
063: assertEquals("wrong text", maxver + 2, engine.getText(NAME1)
064: .length());
065: }
066:
067: private void runMassiveFileTest(int maxpages) throws Exception {
068: String text = "Testing, 1, 2, 3: ";
069: String name = NAME1;
070: Benchmark mark = new Benchmark();
071:
072: System.out.println("Building a massive repository of "
073: + maxpages + " pages...");
074:
075: mark.start();
076: for (int i = 0; i < maxpages; i++) {
077: engine.saveText(name + i, text + i);
078: }
079: mark.stop();
080:
081: System.out.println("Total time to save " + maxpages
082: + " pages was " + mark.toString());
083: System.out.println("Saved " + mark.toString(maxpages)
084: + " pages/second");
085:
086: mark.reset();
087:
088: mark.start();
089: Collection pages = engine.getPageManager().getAllPages();
090: mark.stop();
091:
092: System.out.println("Got a list of all pages in " + mark);
093:
094: mark.reset();
095: mark.start();
096:
097: for (Iterator i = pages.iterator(); i.hasNext();) {
098: String foo = engine.getPureText((WikiPage) i.next());
099:
100: assertNotNull(foo);
101: }
102: mark.stop();
103:
104: System.out.println("Read through all of the pages in " + mark);
105: System.out.println("which is " + mark.toString(maxpages)
106: + " pages/second");
107: }
108:
109: public void testMillionFiles1() throws Exception {
110: runMassiveFileTest(100);
111: }
112:
113: public void testMillionFiles2() throws Exception {
114: runMassiveFileTest(1000);
115: }
116:
117: public void testMillionFiles3() throws Exception {
118: runMassiveFileTest(10000);
119: }
120:
121: /*
122: public void testMillionFiles4()throws Exception
123: {
124: runMassiveFileTest(100000);
125: }
126: */
127: public static Test suite() {
128: return new TestSuite(StressTestVersioningProvider.class);
129: }
130: }
|