use of org.drools.core.command.impl.FireAllRulesInterceptor in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method interceptor.
private void interceptor(final boolean withOOPath) {
final String str = getSimpleRule(withOOPath);
final KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
final KieSession ksession = KieServices.get().getStoreServices().newKieSession(kbase, null, env);
final PersistableRunner sscs = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
sscs.addInterceptor(new LoggingInterceptor());
sscs.addInterceptor(new FireAllRulesInterceptor());
sscs.addInterceptor(new LoggingInterceptor());
final List<Integer> list = new ArrayList<>();
ksession.setGlobal("list", list);
insertIntRange(ksession, 1, 3);
ksession.getWorkItemManager().completeWorkItem(0, null);
assertThat(list).hasSize(3);
}
use of org.drools.core.command.impl.FireAllRulesInterceptor in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method interceptorOnRollback.
private void interceptorOnRollback(final boolean withOOPath) throws Exception {
final String str = getSimpleRule(withOOPath);
final KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
final KieSession ksession = KieServices.get().getStoreServices().newKieSession(kbase, null, env);
final PersistableRunner sscs = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
sscs.addInterceptor(new LoggingInterceptor());
sscs.addInterceptor(new FireAllRulesInterceptor());
sscs.addInterceptor(new LoggingInterceptor());
ChainableRunner runner = sscs.getChainableRunner();
assertThat(runner.getClass()).isEqualTo(LoggingInterceptor.class);
runner = (ChainableRunner) runner.getNext();
assertThat(runner.getClass()).isEqualTo(FireAllRulesInterceptor.class);
runner = (ChainableRunner) runner.getNext();
assertThat(runner.getClass()).isEqualTo(LoggingInterceptor.class);
final UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
final List<?> list = new ArrayList<>();
ksession.setGlobal("list", list);
ksession.insert(1);
ut.rollback();
ksession.insert(3);
runner = sscs.getChainableRunner();
assertThat(runner.getClass()).isEqualTo(LoggingInterceptor.class);
runner = (ChainableRunner) runner.getNext();
assertThat(runner.getClass()).isEqualTo(FireAllRulesInterceptor.class);
runner = (ChainableRunner) runner.getNext();
assertThat(runner.getClass()).isEqualTo(LoggingInterceptor.class);
}
use of org.drools.core.command.impl.FireAllRulesInterceptor in project drools by kiegroup.
the class JpaPersistentStatefulSessionTest method testInterceptor.
@Test
public void testInterceptor() {
String str = "";
str += "package org.kie.test\n";
str += "global java.util.List list\n";
str += "rule rule1\n";
str += "when\n";
str += " Integer(intValue > 0)\n";
str += "then\n";
str += " list.add( 1 );\n";
str += "end\n";
str += "\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieBase kbase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
KieSession ksession = ks.getStoreServices().newKieSession(kbase, null, env);
PersistableRunner sscs = (PersistableRunner) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner();
sscs.addInterceptor(new LoggingInterceptor());
sscs.addInterceptor(new FireAllRulesInterceptor());
sscs.addInterceptor(new LoggingInterceptor());
List<?> list = new ArrayList<Object>();
ksession.setGlobal("list", list);
ksession.insert(1);
ksession.insert(2);
ksession.insert(3);
ksession.getWorkItemManager().completeWorkItem(0, null);
assertEquals(3, list.size());
}
Aggregations