Search in sources :

Example 6 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalTypeDeclarationOnInterface.

@Test
public void testIncrementalTypeDeclarationOnInterface() {
    // DROOLS-861
    String drl1 = "import " + Service.class.getCanonicalName() + "\n" + "rule A when\n" + "    Service( )\n" + "then\n" + "end";
    String drl2 = "import " + Service.class.getCanonicalName() + "\n" + "declare Service @role( event ) end\n" + "rule A when\n" + "    Service( )\n" + "then\n" + "end";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl1);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession ksession = kc.newKieSession();
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    createAndDeployJar(ks, releaseId2, drl2);
    kc.updateToVersion(releaseId2);
}
Also used : CompletionService(java.util.concurrent.CompletionService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ExecutorService(java.util.concurrent.ExecutorService) Service(org.kie.api.Service) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 7 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace2_usingSingleQuote.

@Test
public void testKJarUpgradeDRLWithSpace2_usingSingleQuote() throws Exception {
    // DROOLS-1399 bis (using single quote)
    String drl_1 = "package org.drools.compiler\n" + "rule Rx when\n" + "   $m : Message( message == 'Hello World' )\n" + "then\n" + "end\n";
    String drl_2 = "package org.drools.compiler\n" + "rule Rx when\n" + // <<- notice the EXTRA SPACE is the only change in this other version.
    "   $m : Message( message == 'Hello World'  )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl_1);
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    km = createAndDeployJar(ks, releaseId2, drl_2);
    kc.updateToVersion(releaseId2);
    // rule Rx is UNchanged and should NOT fire again
    assertEquals(0, ksession.fireAllRules());
}
Also used : Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 8 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class IncrementalCompilationTest method testGlobalRemovedFromOneDrl.

@Test
public void testGlobalRemovedFromOneDrl() throws Exception {
    // RHDM-311
    String drlAWithGlobal = "package org.x.a\nglobal Boolean globalBool\n";
    String drlANoGlobal = "package org.x.a\n";
    String drlBWithGlobal = "package org.x.b\nglobal Boolean globalBool\n";
    String drlBNoGlobal = "package org.x.b\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drlAWithGlobal, drlBWithGlobal);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession ksession = kc.newKieSession();
    ksession.setGlobal("globalBool", Boolean.FALSE);
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    createAndDeployJar(ks, releaseId2, drlANoGlobal, drlBWithGlobal);
    kc.updateToVersion(releaseId2);
    ksession.setGlobal("globalBool", Boolean.TRUE);
    ReleaseId releaseId3 = ks.newReleaseId("org.kie", "test-upgrade", "1.2.0");
    createAndDeployJar(ks, releaseId3, drlANoGlobal, drlBNoGlobal);
    kc.updateToVersion(releaseId3);
    try {
        ksession.setGlobal("globalBool", Boolean.TRUE);
        fail("the global should be no longer present");
    } catch (Exception e) {
    // expected
    }
}
Also used : KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 9 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class IncrementalCompilationTest method testKJarUpgradeWithSpace_usingSingleQuote.

@Test
public void testKJarUpgradeWithSpace_usingSingleQuote() throws Exception {
    // DROOLS-1399 (using single quote)
    String drl_1 = "package org.drools.compiler\n" + "rule Rx when\n" + "   $m : Message( message == 'Hello World' )\n" + "then\n" + "end\n";
    String drl_2 = // <<- notice the EXTRA SPACE is the only change in this other version.
    "package org.drools.compiler\n " + "rule Rx when\n" + "   $m : Message( message == 'Hello World' )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl_1);
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    km = createAndDeployJar(ks, releaseId2, drl_2);
    kc.updateToVersion(releaseId2);
    // rule Rx is UNchanged and should NOT fire again
    assertEquals(0, ksession.fireAllRules());
}
Also used : Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 10 with KieModule

use of org.kie.api.builder.KieModule in project drools by kiegroup.

the class IncrementalCompilationTest method testSegmentMergeOnRuleRemovalWithNotExistingSegment.

@Test
public void testSegmentMergeOnRuleRemovalWithNotExistingSegment() throws Exception {
    // DROOLS-950
    String drl1 = "rule R1 when\n" + "    $i : Integer()\n" + "    $s : String( length == $i )\n" + "then\n" + "end\n" + "rule R2 when\n" + "    $i : Integer()\n" + "    $l : Long( this > $i )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
    KieModule km = createAndDeployJar(ks, releaseId1, drl1);
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    kc.updateToVersion(releaseId1);
    ksession.insert("Test");
    ksession.insert(4L);
    ksession.fireAllRules();
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
    km = createAndDeployJar(ks, releaseId2);
    kc.updateToVersion(releaseId2);
}
Also used : KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModule (org.kie.api.builder.KieModule)124 KieServices (org.kie.api.KieServices)104 Test (org.junit.Test)94 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)84 ReleaseId (org.kie.api.builder.ReleaseId)84 KieContainer (org.kie.api.runtime.KieContainer)75 KieSession (org.kie.api.runtime.KieSession)64 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)53 Message (org.drools.compiler.Message)25 KieFileSystem (org.kie.api.builder.KieFileSystem)23 Resource (org.kie.api.io.Resource)20 ArrayList (java.util.ArrayList)15 KieModuleModel (org.kie.api.builder.model.KieModuleModel)15 KieBuilder (org.kie.api.builder.KieBuilder)13 KieRepository (org.kie.api.builder.KieRepository)10 MemoryFileSystem (org.drools.compiler.compiler.io.memory.MemoryFileSystem)7 KieBaseModel (org.kie.api.builder.model.KieBaseModel)7 KieBase (org.kie.api.KieBase)6 List (java.util.List)5 Results (org.kie.api.builder.Results)5