001: package stress;
002:
003: import java.io.File;
004: import java.util.Properties;
005: import java.util.Random;
006:
007: import junit.framework.TestCase;
008:
009: import com.ecyrd.jspwiki.TestEngine;
010: import com.ecyrd.jspwiki.TextUtil;
011: import com.ecyrd.jspwiki.WikiProvider;
012: import com.ecyrd.jspwiki.providers.CachingProvider;
013: import com.ecyrd.jspwiki.providers.FileSystemProvider;
014:
015: public class MassiveRepositoryTest extends TestCase {
016: Properties props = new Properties();
017:
018: TestEngine engine;
019:
020: protected void setUp() throws Exception {
021: super .setUp();
022:
023: props.load(TestEngine
024: .findTestProperties("/jspwiki_vers.properties"));
025:
026: props.setProperty(CachingProvider.PROP_CACHECAPACITY, "1000");
027: engine = new TestEngine(props);
028: }
029:
030: protected void tearDown() throws Exception {
031: super .tearDown();
032:
033: String files = props
034: .getProperty(FileSystemProvider.PROP_PAGEDIR);
035:
036: // Remove file
037: File f = new File(files);
038:
039: TestEngine.deleteAll(f);
040: }
041:
042: private String getName(int i) {
043: String baseName = "Page";
044: return baseName + i;
045: }
046:
047: public void testMassiveRepository1() throws Exception {
048: 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]";
049: int numPages = 1000;
050: int numRevisions = 1000;
051: int numRenders = 10000;
052: int tickmarks = 100;
053:
054: Random random = new Random();
055: Benchmark sw = new Benchmark();
056: sw.start();
057:
058: System.out.println("Creating " + numPages + " pages");
059: //
060: // Create repository
061: //
062:
063: int pm = numPages / tickmarks;
064:
065: for (int i = 0; i < numPages; i++) {
066: String name = getName(i);
067: String text = TextUtil.replaceString(baseText, "%d", name);
068:
069: for (int r = 0; r < 10; r++) {
070: text = TextUtil.replaceString(text, "%" + r, getName(i
071: + r - 5));
072: }
073:
074: engine.saveText(name, text);
075: if (i % pm == 0) {
076: System.out.print(".");
077: System.out.flush();
078: }
079: }
080:
081: System.out.println("\nTook " + sw.toString() + ", which is "
082: + sw.toString(numPages) + " adds/second");
083: //
084: // Create new versions
085: //
086: sw.stop();
087: sw.reset();
088: sw.start();
089:
090: System.out
091: .println("Checking in " + numRevisions + " revisions");
092: pm = numRevisions / tickmarks;
093:
094: for (int i = 0; i < numRevisions; i++) {
095: String page = getName(random.nextInt(numPages));
096:
097: String content = engine.getPureText(page,
098: WikiProvider.LATEST_VERSION);
099:
100: content = TextUtil.replaceString(content, "X", "XX");
101:
102: engine.saveText(page, content);
103:
104: if (i % pm == 0) {
105: System.out.print(".");
106: System.out.flush();
107: }
108: }
109:
110: System.out.println("\nTook " + sw.toString() + ", which is "
111: + sw.toString(numRevisions) + " adds/second");
112:
113: assertEquals("Right number of pages", numPages, engine
114: .getPageCount());
115:
116: //
117: // Rendering random pages
118: //
119: sw.stop();
120: sw.reset();
121: sw.start();
122:
123: System.out.println("Rendering " + numRenders + " pages");
124: pm = numRenders / tickmarks;
125:
126: for (int i = 0; i < numRenders; i++) {
127: String page = getName(random.nextInt(numPages));
128:
129: String content = engine.getHTML(page,
130: WikiProvider.LATEST_VERSION);
131:
132: if (i % pm == 0) {
133: System.out.print(".");
134: System.out.flush();
135: }
136: }
137:
138: sw.stop();
139: System.out.println("\nTook " + sw.toString() + ", which is "
140: + sw.toString(numRenders) + " renders/second");
141:
142: }
143: }
|