01: package org.drools.integrationtests;
02:
03: import java.io.InputStreamReader;
04: import java.util.ArrayList;
05: import java.util.List;
06:
07: import org.drools.Address;
08: import org.drools.Person;
09: import org.drools.RuleBase;
10: import org.drools.RuleBaseFactory;
11: import org.drools.StatelessSession;
12: import org.drools.compiler.PackageBuilder;
13:
14: import junit.framework.TestCase;
15:
16: /**
17: * This is for testing possible PermSpace issues (leaking) when spawning lots of sessions in concurrent threads.
18: * Normally this test will be XXX'ed out, as when running it will not terminate.
19: * @author Michael Neale
20: */
21: public class StatelessStressTest extends TestCase {
22:
23: public void testDummy() {
24:
25: }
26:
27: public void XXXtestLotsOfStateless() throws Exception {
28: final PackageBuilder builder = new PackageBuilder();
29: builder.addPackageFromDrl(new InputStreamReader(getClass()
30: .getResourceAsStream("thread_class_test.drl")));
31: assertFalse(builder.hasErrors());
32:
33: final RuleBase rb = RuleBaseFactory.newRuleBase();
34: rb.addPackage(builder.getPackage());
35:
36: int numThreads = 100;
37: Thread[] ts = new Thread[numThreads];
38:
39: for (int i = 0; i < numThreads; i++) {
40: Runnable run = new Runnable() {
41:
42: public void run() {
43:
44: long start = 0;
45: long previous = 0;
46:
47: while (true) {
48: start = System.currentTimeMillis();
49: StatelessSession sess = rb
50: .newStatelessSession();
51: Person p = new Person();
52: p.setName("Michael");
53: Address add1 = new Address();
54: add1.setStreet("High");
55: Address add2 = new Address();
56: add2.setStreet("Low");
57: List l = new ArrayList();
58: l.add(add1);
59: l.add(add2);
60: p.setAddresses(l);
61: sess.execute(p);
62:
63: long current = System.currentTimeMillis()
64: - start;
65: if (previous != 0) {
66: float f = current / previous;
67: if (f > 1) {
68: System.err.println("SLOWDOWN");
69: }
70: }
71:
72: previous = current;
73: }
74: }
75:
76: };
77:
78: Thread t = new Thread(run);
79: t.start();
80: ts[i] = t;
81: }
82:
83: for (int i = 0; i < ts.length; i++) {
84: ts[i].join();
85: }
86:
87: }
88:
89: }
|