001: package org.drools.brms.server;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.io.ByteArrayInputStream;
020: import java.io.ObjectInputStream;
021: import java.util.Calendar;
022:
023: import javax.jcr.Node;
024: import javax.jcr.Session;
025:
026: import junit.framework.TestCase;
027:
028: import org.drools.brms.client.rpc.BuilderResult;
029: import org.drools.brms.server.util.TestEnvironmentSessionHelper;
030: import org.drools.repository.AssetItem;
031: import org.drools.repository.PackageItem;
032: import org.drools.repository.RulesRepository;
033: import org.drools.repository.VersionableItem;
034: import org.drools.rule.Package;
035:
036: /**
037: * A playground for performance analysing.
038: * @author Michael Neale
039: *
040: */
041: public class PerfServiceTest extends TestCase {
042:
043: private long time;
044:
045: public void testDummy() {
046: }
047:
048: public void XXXtestWarmup() throws Exception {
049:
050: ServiceImplementation impl = getService();
051: RulesRepository repo = impl.repository;
052:
053: //create our package
054: PackageItem pkg = repo.createPackage(
055: "testBinaryPackageCompile", "");
056: pkg.updateHeader("import org.drools.Person");
057: Session session = repo.getSession();
058: Node pkgNode = repo.getSession().getNodeByUUID(pkg.getUUID());
059:
060: Node assetNode = pkgNode.getNode("assets");
061:
062: for (int i = 0; i < 500; i++) {
063: System.out.println("processing asset:" + i);
064: Node ruleNode = assetNode.addNode("" + i,
065: "drools:assetNodeType");
066:
067: ruleNode.setProperty(AssetItem.TITLE_PROPERTY_NAME, "" + i);
068:
069: ruleNode.setProperty(AssetItem.DESCRIPTION_PROPERTY_NAME,
070: "");
071:
072: ruleNode.setProperty(AssetItem.FORMAT_PROPERTY_NAME, "DRL");
073:
074: ruleNode.setProperty(VersionableItem.CHECKIN_COMMENT,
075: "Initial");
076:
077: Calendar lastModified = Calendar.getInstance();
078:
079: ruleNode.setProperty(AssetItem.LAST_MODIFIED_PROPERTY_NAME,
080: lastModified);
081: // ruleNode.setProperty( AssetItem.PACKAGE_NAME_PROPERTY, this.getName() );
082: ruleNode.setProperty(AssetItem.CREATOR_PROPERTY_NAME,
083: session.getUserID());
084:
085: repo.save();
086: ruleNode.checkin();
087: // AssetItem rule1 = pkg.addAsset( "rule_" + i, "" );
088: // rule1.updateFormat( AssetFormats.DRL );
089: // rule1.updateContent( "rule 'rule_" + i + "' \n when p:Person() \n then p.setAge(" + i + "); \n end");
090: // rule1.checkin( "" );
091:
092: }
093:
094: repo.save();
095:
096: }
097:
098: /**
099: * This will test creating a package, check it compiles, and can exectute rules,
100: * then take a snapshot, and check that it reports errors.
101: */
102: public void XXXtestBinaryPackageCompileAndExecute()
103: throws Exception {
104:
105: ServiceImplementation impl = getService();
106: RulesRepository repo = impl.repository;
107:
108: reset();
109:
110: PackageItem pkg = repo.loadPackage("testBinaryPackageCompile");
111:
112: time("loaded package");
113: reset();
114:
115: BuilderResult[] results = impl
116: .buildPackage(pkg.getUUID(), null);
117:
118: time("built");
119: reset();
120: assertNull(results);
121:
122: pkg = repo.loadPackage("testBinaryPackageCompile");
123: byte[] binPackage = pkg.getCompiledPackageBytes();
124:
125: time("got bytes");
126: reset();
127:
128: assertNotNull(binPackage);
129:
130: ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
131: ObjectInputStream in = new ObjectInputStream(bin);
132: Package binPkg = (Package) in.readObject();
133:
134: assertNotNull(binPkg);
135: assertTrue(binPkg.isValid());
136:
137: impl.createPackageSnapshot("testBinaryPackageCompile", "SNAP1",
138: false, "");
139:
140: }
141:
142: private void time(String m) {
143: System.out.println(m + " : "
144: + (System.currentTimeMillis() - time));
145:
146: }
147:
148: private void reset() {
149: this .time = System.currentTimeMillis();
150:
151: }
152:
153: private ServiceImplementation getService() throws Exception {
154: ServiceImplementation impl = new ServiceImplementation();
155: impl.repository = new RulesRepository(
156: TestEnvironmentSessionHelper.getSession());
157: return impl;
158: }
159:
160: }
|