use of org.kie.api.command.KieCommands in project drools by kiegroup.
the class StatelessKieSessionDefaultInjectionTest method tessDefaultClassPathKBase.
@Test
public void tessDefaultClassPathKBase() throws IOException, ClassNotFoundException, InterruptedException {
assertNotNull(defaultClassPathSKSession);
KieCommands cmds = KieServices.Factory.get().getCommands();
List<String> list = new ArrayList<String>();
defaultClassPathSKSession.setGlobal("list", list);
defaultClassPathSKSession.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("2.0"));
assertTrue(list.get(1).endsWith("2.0"));
}
use of org.kie.api.command.KieCommands in project drools by kiegroup.
the class CommandsTest method testSessionTimeCommands.
@Test
public void testSessionTimeCommands() throws Exception {
String str = "";
str += "package org.drools.compiler.integrationtests \n";
str += "import " + Cheese.class.getCanonicalName() + " \n";
str += "rule StringRule \n";
str += " when \n";
str += " $c : Cheese() \n";
str += " then \n";
str += " System.out.println($c); \n";
str += "end \n";
KieServices ks = KieServices.get();
KieCommands kieCommands = ks.getCommands();
KieSessionConfiguration sessionConfig = ks.newKieSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
KieSession kSession = new KieHelper().addContent(str, ResourceType.DRL).build().newKieSession(sessionConfig, null);
assertEquals(0L, (long) kSession.execute(kieCommands.newGetSessionTime()));
assertEquals(2000L, (long) kSession.execute(kieCommands.newAdvanceSessionTime(2, TimeUnit.SECONDS)));
assertEquals(2000L, (long) kSession.execute(kieCommands.newGetSessionTime()));
kSession.dispose();
}
use of org.kie.api.command.KieCommands in project drools by kiegroup.
the class StatelessKieSessionDefaultInjectionTest method tessDefaultDynamicKBase.
@Test
public void tessDefaultDynamicKBase() throws IOException, ClassNotFoundException, InterruptedException {
assertNotNull(defaultDynamicSKSession);
KieCommands cmds = KieServices.Factory.get().getCommands();
List<String> list = new ArrayList<String>();
defaultDynamicSKSession.setGlobal("list", list);
defaultDynamicSKSession.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("1.0"));
assertTrue(list.get(1).endsWith("1.0"));
}
use of org.kie.api.command.KieCommands in project drools by kiegroup.
the class StatelessKieSessionInjectionTest method testDynamicStatelessKieSessionReleaseId.
@Test
public void testDynamicStatelessKieSessionReleaseId() throws IOException, ClassNotFoundException, InterruptedException {
assertNotNull(kbase1ksession1v10);
assertNotNull(kbase1ksession1v10);
KieCommands cmds = KieServices.Factory.get().getCommands();
List<String> list = new ArrayList<String>();
kbase1ksession1v10.setGlobal("list", list);
kbase1ksession1v10.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("1.0"));
assertTrue(list.get(1).endsWith("1.0"));
list = new ArrayList<String>();
kbase1ksession1v11.setGlobal("list", list);
kbase1ksession1v11.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("1.1"));
assertTrue(list.get(1).endsWith("1.1"));
}
use of org.kie.api.command.KieCommands in project drools by kiegroup.
the class StatelessKieSessionInjectionTest method testNamedStatelessKieSessions.
@Test
public void testNamedStatelessKieSessions() throws IOException, ClassNotFoundException, InterruptedException {
assertNotNull(kbase1ksession1sks1);
assertNotNull(kbase1ksession1sks2);
assertNotNull(kbase1ksession1sks22);
assertNotSame(kbase1ksession1sks1, kbase1ksession1sks2);
assertSame(kbase1ksession1sks2, kbase1ksession1sks22);
KieCommands cmds = KieServices.Factory.get().getCommands();
List<String> list = new ArrayList<String>();
kbase1ksession1sks1.setGlobal("list", list);
kbase1ksession1sks1.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("1.0"));
assertTrue(list.get(1).endsWith("1.0"));
list = new ArrayList<String>();
kbase1ksession1sks2.setGlobal("list", list);
kbase1ksession1sks2.execute(cmds.newFireAllRules());
assertEquals(2, list.size());
assertTrue(list.get(0).endsWith("1.0"));
assertTrue(list.get(1).endsWith("1.0"));
}
Aggregations