[rules-users] Drools Fusion Dropping Actions to Events?
Mario Fusco
mario.fusco at gmail.com
Wed Apr 23 08:21:24 EDT 2014
Hi,
I developed a test case almost identical to the one you suggested and I am
pasting it at the end of this email.
In the last months we did a few fixes on the event processing part and
indeed this test works as expected, i.e. the assertion at the end of the
test is true meaning that all the 10K inserted events get correctly
processed.
I suggest you to try this on the 6.1.0.Beta2 version that should already
contain all the fixes related to this use case. Anyway we will drop a Beta3
before the end of this week.
I hope this helps,
Mario
--------
@Test
public void testThroughput() throws Exception {
String drl = "package drools\n" +
"\n" +
"import " + TemperatureEvent.class.getCanonicalName() +
"\n" +
"global java.util.concurrent.atomic.AtomicInteger
counter\n" +
"\n" +
"declare TemperatureEvent\n" +
"@role(event)\n" +
"end\n" +
"\n" +
"rule \"RULE S1\"\n" +
"when\n" +
" $te:TemperatureEvent(measure <= 50) from
entry-point entryone\n" +
"then\n" +
" counter.incrementAndGet();\n" +
//" System.err.println(\"The temperature at location
- \"+$te.getLocation() + \" is \" + $te.getMeasure());\n" +
"end\n" +
"\n" +
"rule \"RULE S2\"\n" +
"when\n" +
" $te:TemperatureEvent(measure > 50) from
entry-point entryone\n" +
"then\n" +
" counter.incrementAndGet();\n" +
//" System.err.println(\"The temperature at location
- \"+$te.getLocation() + \" is \" + $te.getMeasure());\n" +
"end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kieModule = ks.newKieModuleModel();
kieModule.newKieBaseModel("KBase")
.setDefault(true)
.setEventProcessingMode(EventProcessingOption.STREAM)
.newKieSessionModel("KSession")
.setDefault(true);
kfs.writeKModuleXML(kieModule.toXML());
kfs.write("src/main/resources/lifecycle.drl", drl);
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
final KieSession kSession =
ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
AtomicInteger counter = new AtomicInteger(0);
kSession.setGlobal("counter", counter);
EntryPoint entryPoint1 = kSession.getEntryPoint("entryone");
new Thread() {
@Override
public void run() {
kSession.fireUntilHalt();
}
}.start();
Random measure = new Random(System.currentTimeMillis());
Random location = new Random(System.currentTimeMillis() - 1000000L);
String locations[] = { "Bangalore", "Chennai", "Delhi", "Mumbai",
"Kolkata" };
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 1000; ++j) {
TemperatureEvent te = new TemperatureEvent(
measure.nextInt(100),
locations[location.nextInt(5)],
System.currentTimeMillis());
entryPoint1.insert(te);
}
}
Thread.sleep(100L);
kSession.halt();
kSession.dispose();
assertEquals(10000, counter.get());
}
public static class TemperatureEvent {
int measure;
String location;
long timeStamp;
public TemperatureEvent(int measure, String location, long
timeStamp) {
this.measure = measure;
this.location = location;
this.timeStamp = timeStamp;
}
public int getMeasure() {
return measure;
}
public void setMeasure(int measure) {
this.measure = measure;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Fusion-Dropping-Actions-to-Events-tp4029314p4029334.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
More information about the rules-users
mailing list