use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class AgendaRuleFlowGroupsTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession(long id, String... rules) {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
for (String rule : rules) {
kbuilder.add(new ClassPathResource(rule), ResourceType.DRL);
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
if (id == -1) {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
} else {
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, null, env);
}
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class ReloadSessionTest method testListenersAfterSessionReload.
@Test
@Ignore
public void testListenersAfterSessionReload() {
// https://bugzilla.redhat.com/show_bug.cgi?id=826952
Environment env = createEnvironment();
KieBase kbase = initializeKnowledgeBase(simpleRule);
StatefulKnowledgeSession ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
ksession.addEventListener(new DefaultAgendaEventListener());
ksession.addEventListener(new DefaultRuleRuntimeEventListener());
assertEquals(1, ksession.getRuleRuntimeEventListeners().size());
assertEquals(1, ksession.getAgendaEventListeners().size());
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(ksession.getIdentifier(), kbase, null, env);
assertEquals(1, ksession.getRuleRuntimeEventListeners().size());
assertEquals(1, ksession.getAgendaEventListeners().size());
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class ReloadSessionTest method testInsertIntoEntryPoint.
@Test
public void testInsertIntoEntryPoint() {
// RHBRMS-2815
final Environment env = createEnvironment();
final KieBase kbase = initializeKnowledgeBase(RULE_WITH_EP);
KieSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
assertTrue("There should be NO facts present in a new (empty) knowledge session.", kieSession.getFactHandles().isEmpty());
kieSession.getEntryPoint(ENTRY_POINT).insert(Integer.valueOf(10));
kieSession = reloadSession(kieSession, env);
Collection<? extends Object> objects = kieSession.getEntryPoint(ENTRY_POINT).getObjects();
assertEquals("Reloaded working memory should contain the fact in the entry point.", 1, objects.size());
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class ReloadSessionTest method testInsert.
@Test
public void testInsert() {
final Environment env = createEnvironment();
final KieBase kbase = initializeKnowledgeBase(RULE_WITH_EP);
KieSession kieSession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
assertTrue("There should be NO facts present in a new (empty) knowledge session.", kieSession.getFactHandles().isEmpty());
kieSession.insert(Integer.valueOf(10));
kieSession = reloadSession(kieSession, env);
Collection<? extends Object> objects = kieSession.getObjects();
assertEquals("Reloaded working memory should contain the fact.", 1, objects.size());
}
use of org.kie.api.runtime.Environment in project drools by kiegroup.
the class RuleFlowGroupRollbackTest method createSession.
private CommandBasedStatefulKnowledgeSession createSession() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ClassPathResource("ruleflowgroup_rollback.drl"), ResourceType.DRL);
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
kbase.addPackages(kbuilder.getKnowledgePackages());
Environment env = createEnvironment(context);
if (locking) {
env.set(EnvironmentName.USE_PESSIMISTIC_LOCKING, true);
}
return (CommandBasedStatefulKnowledgeSession) JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null, env);
}
Aggregations