use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieRepositoryTest method createKieModule.
/**
* Helper method creating simple KieModule with given ReleaseId.
*/
private void createKieModule(final ReleaseId releaseId) {
final KieModuleModel kmodule = kieServices.newKieModuleModel();
kmodule.newKieBaseModel("defaultKBase").setDefault(true);
final KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
kfs.writeKModuleXML(kmodule.toXML());
kfs.write("src/main/resources/defaultKBase/test.drl", kieServices.getResources().newByteArrayResource(DRL.getBytes()));
final KieBuilder kbuilder = kieServices.newKieBuilder(kfs);
kbuilder.buildAll();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class BuildtimeUtil method getDefaultKieModuleModel.
public static KieModuleModel getDefaultKieModuleModel(final KieServices ks) {
final KieModuleModel kproj = ks.newKieModuleModel();
final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
return kproj;
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class DroolsGcCausesNPETest method beforeClass.
@BeforeClass
public static void beforeClass() throws Exception {
final KieModuleModel module = SERVICES.newKieModuleModel();
final KieBaseModel base = module.newKieBaseModel(KIE_BASE_NAME);
base.setEventProcessingMode(EventProcessingOption.STREAM);
final KieFileSystem fs = SERVICES.newKieFileSystem();
fs.generateAndWritePomXML(RELEASE_ID);
fs.write(SERVICES.getResources().newClassPathResource(DRL_FILE_NAME, DroolsGcCausesNPETest.class));
fs.writeKModuleXML(module.toXML());
final KieBuilder builder = SERVICES.newKieBuilder(fs);
final List<Message> errors = builder.buildAll().getResults().getMessages(Message.Level.ERROR);
Assertions.assertThat(errors).as("Unexpected errors building drl: " + errors).isEmpty();
SERVICES.getRepository().addKieModule(builder.getKieModule());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class IncrementalCompilationTest method createAndDeployJarInStreamMode.
public static KieModule createAndDeployJarInStreamMode(KieServices ks, ReleaseId releaseId, String... drls) {
KieFileSystem kfs = ks.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
KieModuleModel module = ks.newKieModuleModel();
KieBaseModel defaultBase = module.newKieBaseModel("kBase1");
defaultBase.setEventProcessingMode(EventProcessingOption.STREAM).setDefault(true);
defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
kfs.writeKModuleXML(module.toXML());
for (int i = 0; i < drls.length; i++) {
kfs.write("src/main/resources/rules" + i + ".drl", drls[i]);
}
KieBuilder kb = ks.newKieBuilder(kfs);
kb.buildAll();
if (kb.getResults().hasMessages(org.kie.api.builder.Message.Level.ERROR)) {
System.out.println(kb.getResults().toString());
}
return kb.getKieModule();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class IncrementalCompilationTest method testChangeWindowTime.
@Test
public void testChangeWindowTime() {
// DROOLS-853
String drl1 = "import " + MyEvent.class.getCanonicalName() + "\n" + "global java.util.concurrent.atomic.AtomicInteger result\n" + "declare MyEvent @expires(5m) @role( event ) end\n" + "rule A when\n" + " accumulate( $e : MyEvent() over window:time(10s), $result : count($e) )\n" + "then" + " System.out.println(\"Result-1: \" + $result);\n" + " result.set( $result.intValue() );\n" + "end";
String drl2 = "import " + MyEvent.class.getCanonicalName() + "\n" + "global java.util.concurrent.atomic.AtomicInteger result\n" + "declare MyEvent @expires(5m) @role( event ) end\n" + "rule A when\n" + " accumulate( $e : MyEvent() over window:time(5s), $result : count($e) )\n" + "then" + " System.out.println(\"Result-2: \" + $result);\n" + " result.set( $result.intValue() );\n" + "end";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("KSession1").setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
deployJar(ks, createKJar(ks, kproj, releaseId1, null, drl1));
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession ksession = kc.newKieSession();
PseudoClockScheduler clock = ksession.getSessionClock();
AtomicInteger result = new AtomicInteger(0);
ksession.setGlobal("result", result);
ksession.insert(new MyEvent(1));
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new MyEvent(2));
clock.advanceTime(4, TimeUnit.SECONDS);
ksession.insert(new MyEvent(3));
ksession.fireAllRules();
assertEquals(3, result.get());
// expires 1
clock.advanceTime(3, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(2, result.get());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
deployJar(ks, createKJar(ks, kproj, releaseId2, null, drl2));
kc.updateToVersion(releaseId2);
// shorter window: 2 is out
ksession.fireAllRules();
assertEquals(1, result.get());
ksession.insert(new MyEvent(4));
ksession.insert(new MyEvent(5));
ksession.fireAllRules();
assertEquals(3, result.get());
// expires 3
clock.advanceTime(3, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(2, result.get());
// expires 4 & 5
clock.advanceTime(3, TimeUnit.SECONDS);
ksession.fireAllRules();
assertEquals(0, result.get());
}
Aggregations