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: /**
011: * Does stress testing on the RCSProvider.
012: */
013: public class StressTestRCSProvider extends TestCase {
014: public static final String NAME1 = "Test1";
015:
016: Properties props = new Properties();
017:
018: TestEngine engine;
019:
020: public StressTestRCSProvider(String s) {
021: super (s);
022: }
023:
024: public void setUp() throws Exception {
025: props.load(TestEngine
026: .findTestProperties("/jspwiki_rcs.properties"));
027: props.setProperty(CachingProvider.PROP_CACHECAPACITY, "10000");
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: /**
050: * Bug report by Anon: RCS under Windows 2k:
051: * <PRE>
052: * In getPageInfo of RCSFileProvider:
053: *
054: * Problem:
055: *
056: * With a longer rlog result, the break clause in the last "else if"
057: * breaks out of the reading loop before all the lines in the full
058: * rlog have been read in. This causes the process.wait() to hang.
059: *
060: * Suggested quick fix:
061: *
062: * Always read all the contents of the rlog, even if it is slower.
063: * </PRE>
064: *
065: */
066:
067: public void testMillionChanges() throws Exception {
068: String text = "";
069: String name = NAME1;
070: int maxver = 2000; // Save 2000 versions.
071: Benchmark mark = new Benchmark();
072:
073: mark.start();
074: for (int i = 0; i < maxver; i++) {
075: text = text + ".";
076: engine.saveText(name, text);
077: }
078: mark.stop();
079:
080: System.out.println("Benchmark: " + mark.toString(2000)
081: + " pages/second");
082: WikiPage pageinfo = engine.getPage(NAME1);
083:
084: assertEquals("wrong version", maxver, pageinfo.getVersion());
085: // +2 comes from \r\n at the end of each file.
086: assertEquals("wrong text", maxver + 2, engine.getText(NAME1)
087: .length());
088: }
089:
090: private void runMassiveFileTest(int maxpages) throws Exception {
091: String text = "Testing, 1, 2, 3: ";
092: String name = NAME1;
093: Benchmark mark = new Benchmark();
094:
095: System.out.println("Building a massive repository of "
096: + maxpages + " pages...");
097:
098: mark.start();
099: for (int i = 0; i < maxpages; i++) {
100: engine.saveText(name + i, text + i);
101: }
102: mark.stop();
103:
104: System.out.println("Total time to save " + maxpages
105: + " pages was " + mark.toString());
106: System.out.println("Saved " + mark.toString(maxpages)
107: + " pages/second");
108:
109: mark.reset();
110:
111: mark.start();
112: Collection pages = engine.getPageManager().getAllPages();
113: mark.stop();
114:
115: System.out.println("Got a list of all pages in " + mark);
116:
117: mark.reset();
118: mark.start();
119:
120: for (Iterator i = pages.iterator(); i.hasNext();) {
121: String foo = engine.getPureText((WikiPage) i.next());
122:
123: assertNotNull(foo);
124: }
125: mark.stop();
126:
127: System.out.println("Read through all of the pages in " + mark);
128: System.out.println("which is " + mark.toString(maxpages)
129: + " pages/second");
130: }
131:
132: public void testMillionFiles1() throws Exception {
133: runMassiveFileTest(100);
134: }
135:
136: public void testMillionFiles2() throws Exception {
137: runMassiveFileTest(1000);
138: }
139:
140: public void testMillionFiles3() throws Exception {
141: runMassiveFileTest(10000);
142: }
143:
144: public static Test suite() {
145: return new TestSuite(StressTestRCSProvider.class);
146: }
147: }
|