use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class KieSessionUtil method getKieSessionConfigurationWithClock.
public static KieSessionConfiguration getKieSessionConfigurationWithClock(final ClockTypeOption clockType, final Properties sessionProperties) {
final KieSessionConfiguration conf = KieServices.Factory.get().newKieSessionConfiguration(sessionProperties);
conf.setOption(clockType);
return conf;
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class EventDeserializationInPastTest method testSerializationWithEventInPastBZ1205666.
@Test
public void testSerializationWithEventInPastBZ1205666() {
// DROOLS-749
final String drl = "import " + Event1.class.getCanonicalName() + "\n" + "declare Event1\n" + " @role( event )\n" + " @timestamp( timestamp )\n" + " @expires( 3h )\n" + "end\n" + "\n" + "rule R\n" + " when\n" + " $evt: Event1()\n" + " not Event1(this != $evt, this after[0, 1h] $evt)\n" + " then\n" + " System.out.println($evt.getCode());\n" + "end\n";
final KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
final KieHelper helper = new KieHelper();
helper.addContent(drl, ResourceType.DRL);
final KieBase kbase = helper.build(EventProcessingOption.STREAM);
KieSession ksession = kbase.newKieSession(sessionConfig, null);
ksession.insert(new Event1("id1", 0));
final PseudoClockScheduler clock = ksession.getSessionClock();
clock.advanceTime(2, TimeUnit.HOURS);
ksession.fireAllRules();
ksession = marshallAndUnmarshall(KieServices.Factory.get(), kbase, ksession, sessionConfig);
ksession.insert(new Event1("id2", 0));
ksession.fireAllRules();
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class FusionAfterBeforeTest method testAfterBeforeOperators.
@Test
public void testAfterBeforeOperators() {
final Resource drlResource = KieServices.Factory.get().getResources().newClassPathResource("fusionAfterBeforeTest.drl", getClass());
final KieBase kieBase = KieBaseUtil.getKieBaseAndBuildInstallModule(TestConstants.PACKAGE_REGRESSION, kieBaseTestConfiguration, drlResource);
final KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
ksconf.setOption(ClockTypeOption.get("pseudo"));
final KieSession ksession = kieBase.newKieSession(ksconf, null);
final TrackingAgendaEventListener listener = new TrackingAgendaEventListener();
ksession.addEventListener(listener);
final EntryPoint stream = ksession.getEntryPoint("EventStream");
SessionPseudoClock clock = ksession.getSessionClock();
try {
for (int i = 0; i < 3; i++) {
final MessageEvent tc = new MessageEvent(MessageEvent.Type.received, new Message());
stream.insert(tc);
ksession.fireAllRules();
clock.advanceTime(8, TimeUnit.SECONDS);
}
ksession.fireAllRules();
} finally {
ksession.dispose();
}
Assertions.assertThat(listener.isRuleFired("AfterMessageEvent")).as("Rule 'AfterMessageEvent' was no fired!").isTrue();
Assertions.assertThat(listener.isRuleFired("BeforeMessageEvent")).as("Rule 'BeforeMessageEvent' was no fired!").isTrue();
// each rules should be fired 2 times
int firedCount = 2;
int actuallyFired = listener.ruleFiredCount("AfterMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'AfterMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
firedCount = listener.ruleFiredCount("BeforeMessageEvent");
Assertions.assertThat(firedCount).as("Rule 'BeforeMessageEvent' should be fired 2 times, but was fired " + firedCount + " time(s)!").isEqualTo(actuallyFired);
}
use of org.kie.api.runtime.KieSessionConfiguration in project drools by kiegroup.
the class KnowledgeStoreServiceImpl method mergeConfig.
private KieSessionConfiguration mergeConfig(KieSessionConfiguration configuration) {
KieSessionConfiguration merged = ((SessionConfiguration) configuration).addDefaultProperties(configProps);
merged.setOption(TimerJobFactoryOption.get("jpa"));
return merged;
}
use of org.kie.api.runtime.KieSessionConfiguration in project ff4j by ff4j.
the class FF4jDroolsService method initFromRulesFiles.
/**
* Initialisation of Drools stateful session without convention and kodmule files.
*
* @param ruleFiles
* DRL files
*/
public static synchronized void initFromRulesFiles(Set<String> ruleFiles) {
if (isInitialized()) {
throw new IllegalStateException("This Factory has already be initialized once");
}
_instance = new FF4jDroolsService();
_instance.ruleFiles = ruleFiles;
KieHelper helper = new KieHelper();
KieSessionConfiguration sessionConfig = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
sessionConfig.setOption(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
// ruleFiles.stream().forEach(drlFile -> helper.addContent(loadResourceAsString(drlFile), ResourceType.determineResourceType(drlFile)));
for (String drlFile : ruleFiles) {
String fileContent = loadResourceAsString(drlFile);
ResourceType typeFile = ResourceType.determineResourceType(drlFile);
helper.addContent(fileContent, typeFile);
}
_instance.ksession = helper.build(EventProcessingOption.STREAM).newKieSession(sessionConfig, null);
}
Aggregations