001: package org.drools.repository;
002:
003: import java.util.ArrayList;
004: import java.util.Calendar;
005: import java.util.Iterator;
006: import java.util.List;
007:
008: import javax.jcr.Node;
009: import javax.jcr.Repository;
010: import javax.jcr.Session;
011: import javax.jcr.SimpleCredentials;
012: import javax.jcr.UnsupportedRepositoryOperationException;
013:
014: import org.apache.jackrabbit.core.TransientRepository;
015: import org.drools.repository.AssetItem;
016: import org.drools.repository.RulesRepository;
017: import org.drools.repository.RulesRepositoryException;
018: import org.drools.repository.VersionableItem;
019:
020: import junit.framework.TestCase;
021:
022: /**
023: * This is a bit of a hacked scalability test.
024: * It will add 5000 odd rule nodes, and then do some basic operations.
025: * It will take a LONG time to add these nodes, and does it in batches.
026: *
027: */
028: public class ScalabilityTest extends TestCase {
029:
030: private static final int NUM = 5000;
031: private RulesRepository repo;
032:
033: public void testDummy() {
034:
035: }
036:
037: public void xxtestRun() throws Exception {
038: JCRRepositoryConfigurator config = new JackrabbitRepositoryConfigurator();
039:
040: Session session = config.getJCRRepository(
041: "./scalabilityTestRepo").login(
042: new SimpleCredentials("alan_parsons", "password"
043: .toCharArray()));
044:
045: repo = new RulesRepository(session);
046:
047: long start = System.currentTimeMillis();
048: //setupData( repo );
049: System.out.println("time to add, version and tag 5000: "
050: + (System.currentTimeMillis() - start));
051: List list = listACat(repo);
052: System.out.println("list size is: " + list.size());
053:
054: start = System.currentTimeMillis();
055: AssetItem item = (AssetItem) list.get(0);
056: item.updateContent("this is a description");
057: item.checkin("newer");
058: System.out.println("time to update and version: "
059: + (System.currentTimeMillis() - start));
060:
061: start = System.currentTimeMillis();
062: item = (AssetItem) list.get(42);
063: item.updateContent("this is a description");
064: item.updateContent("wooooooooooooooooooooooooooooooooooot");
065: item.checkin("latest");
066: System.out.println("time to update and version: "
067: + (System.currentTimeMillis() - start));
068:
069: }
070:
071: // /** This tests it "bare" just setting properties on node types directly. */
072: // public void xxxtestBare() throws Exception {
073: // hackit();
074: // }
075:
076: private List listACat(RulesRepository repo) {
077: long start = System.currentTimeMillis();
078: List results = repo.findAssetsByCategory("HR/CAT_1");
079: System.out.println("Time for listing a cat: "
080: + (System.currentTimeMillis() - start));
081:
082: start = System.currentTimeMillis();
083: List results2 = repo.findAssetsByCategory("HR/CAT_1");
084: System.out.println("Time for listing a cat: "
085: + (System.currentTimeMillis() - start));
086:
087: start = System.currentTimeMillis();
088: results2 = repo.findAssetsByCategory("HR/CAT_100");
089: System.out.println("Time for listing a cat: "
090: + (System.currentTimeMillis() - start));
091:
092: start = System.currentTimeMillis();
093: results2 = repo.findAssetsByCategory("HR/CAT_100");
094: System.out.println("Time for listing a cat: "
095: + (System.currentTimeMillis() - start));
096:
097: return results;
098: }
099:
100: /** To run this, need to hack the addRule method to not save a session */
101: private void setupData(RulesRepository repo) throws Exception {
102:
103: int count = 1;
104:
105: List list = new ArrayList();
106:
107: String prefix = "HR/";
108: String cat = prefix + "CAT_1";
109: for (int i = 1; i <= NUM; i++) {
110:
111: if (i % 500 == 0) {
112: repo.getSession().save();
113: for (Iterator iter = list.iterator(); iter.hasNext();) {
114: AssetItem element = (AssetItem) iter.next();
115: element.getNode().checkin();
116: }
117: list.clear();
118: }
119:
120: if (i > 2500) {
121: prefix = "FINANCE/";
122: }
123:
124: if (count == 100) {
125: count = 1;
126: cat = prefix + "CAT_" + i;
127: System.err.println("changing CAT");
128: System.gc();
129:
130: } else {
131: count++;
132: }
133:
134: String ruleName = "rule_" + i + "_"
135: + System.currentTimeMillis();
136: System.out.println("ADDING rule: " + ruleName);
137:
138: AssetItem item = repo.loadDefaultPackage().addAsset(
139: ruleName, "Foo(bar == " + i + ")panic(" + i + ");");
140: item.addCategory(cat);
141: list.add(item);
142:
143: }
144:
145: }
146:
147: // private void hackit() throws Exception {
148: //
149: //
150: // RulesRepository repo = new RulesRepository(true);
151: // Session session = repo.getSession();
152: //
153: //
154: // Node folderNode = session.getRootNode().getNode("drools:repository/drools:rule_area");
155: //
156: // for (int i=1 ; i <= 50; i++) {
157: //
158: // System.out.println("doing: Rule " + i);
159: //
160: // //create the node - see section 6.7.22.6 of the spec
161: // Node ruleNode = folderNode.addNode("Rule_" + i, RuleItem.RULE_NODE_TYPE_NAME );
162: //
163: // ruleNode.setProperty(RuleItem.TITLE_PROPERTY_NAME, "Rule_" + i);
164: //
165: // //TODO: set this property correctly once we've figured out logging in / JAAS
166: // ruleNode.setProperty(RuleItem.CONTRIBUTOR_PROPERTY_NAME, "not yet implemented");
167: //
168: // ruleNode.setProperty(RuleItem.DESCRIPTION_PROPERTY_NAME, "");
169: // ruleNode.setProperty(RuleItem.FORMAT_PROPERTY_NAME, RuleItem.RULE_FORMAT);
170: // ruleNode.setProperty(RuleItem.LHS_PROPERTY_NAME, "LHS_" + i);
171: // ruleNode.setProperty(RuleItem.RHS_PROPERTY_NAME, "RHS_" + i);
172: // ruleNode.setProperty( VersionableItem.CHECKIN_COMMENT, "Initial" );
173: //
174: //
175: // Calendar lastModified = Calendar.getInstance();
176: // ruleNode.setProperty(RuleItem.LAST_MODIFIED_PROPERTY_NAME, lastModified);
177: // if (i % 500 == 0) {
178: // System.out.println("saving......");
179: // session.save();
180: // System.out.println("finished.");
181: // }
182: // }
183: //
184: // }
185:
186: }
|