Search in sources :

Example 56 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class IncrementalCompilationTest method testRuleRemovalWithSubnetworkAndOR.

@Test
public void testRuleRemovalWithSubnetworkAndOR() throws Exception {
    // DROOLS-1025
    String drl1 = "global java.util.concurrent.atomic.AtomicInteger globalInt\n" + "rule R1 when\n" + "    $s : String()\n" + "	 (or exists Integer(this == 1)\n" + "	     exists Integer(this == 2) )\n" + "	 exists Integer() from globalInt.get()\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();
    ksession.setGlobal("globalInt", new AtomicInteger(0));
    ksession.insert(1);
    ksession.insert("1");
    ksession.fireAllRules();
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
    km = createAndDeployJar(ks, releaseId2);
    try {
        kc.updateToVersion(releaseId2);
    } catch (Exception e) {
        e.printStackTrace();
        fail("Incremental update should succeed, but failed with " + e.getLocalizedMessage());
    }
    ksession.fireAllRules();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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 57 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class IncrementalCompilationTest method testRuleRemovalWithOR.

@Test
public void testRuleRemovalWithOR() throws Exception {
    // DROOLS-1007
    String drl1 = "rule R1 when\n" + "    $s : String()\n" + "	 (Integer(this == $s.length) or Long(this == $s.length))\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();
    ksession.fireAllRules();
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
    km = createAndDeployJar(ks, releaseId2);
    try {
        kc.updateToVersion(releaseId2);
    } catch (Exception e) {
        fail("Incremental update should succeed, but failed with " + e.getLocalizedMessage());
    }
    ksession.fireAllRules();
}
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 58 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class IncrementalCompilationTest method testDeclaredTypeInDifferentPackage.

@Test
public void testDeclaredTypeInDifferentPackage() {
    // DROOLS-1707
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, DECLARES_DRL, RULES1_DRL);
    KieContainer kContainer = ks.newKieContainer(km.getReleaseId());
    doFire(kContainer.getKieBase(), "reply 1");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    km = createAndDeployJar(ks, releaseId2, DECLARES_DRL, RULES2_DRL);
    kContainer.updateToVersion(releaseId2);
    doFire(kContainer.getKieBase(), "reply 2");
}
Also used : KieServices(org.kie.api.KieServices) 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 59 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class IncrementalCompilationTest method testRemoveRuleWithRia.

@Test
public void testRemoveRuleWithRia() throws Exception {
    // DROOLS-954
    String drl1 = "import " + List.class.getCanonicalName() + "\n" + "rule R when\n" + "    $list : List()\n" + "    exists Integer( this == 1 ) from $list\n" + "    exists Integer( this == 2 ) from $list\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();
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
    km = createAndDeployJar(ks, releaseId2);
    kc.updateToVersion(releaseId2);
    Rete rete = ((InternalKnowledgeBase) (InternalKnowledgeBase) ksession.getKieBase()).getRete();
    EntryPointNode entryPointNode = rete.getEntryPointNodes().values().iterator().next();
    for (ObjectTypeNode otns : entryPointNode.getObjectTypeNodes().values()) {
        assertEquals(0, otns.getObjectSinkPropagator().getSinks().length);
    }
}
Also used : EntryPointNode(org.drools.core.reteoo.EntryPointNode) Rete(org.drools.core.reteoo.Rete) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) 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) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 60 with KieContainer

use of org.kie.api.runtime.KieContainer in project drools by kiegroup.

the class IncrementalCompilationTest method testDeclaredTypeInIncludedKieBase.

@Test
public void testDeclaredTypeInIncludedKieBase() {
    // DROOLS-1707
    KieServices ks = KieServices.Factory.get();
    KieModule kModule = buildKieModule("0.0.1", DECLARES_DRL, RULES1_DRL);
    KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId());
    doFire(kContainer.getKieBase("kiemodulemodel"), "reply 1");
    KieModule kModule2 = buildKieModule("0.0.2", DECLARES_DRL, RULES2_DRL);
    kContainer.updateToVersion(kModule2.getReleaseId());
    doFire(kContainer.getKieBase("kiemodulemodel"), "reply 2");
}
Also used : KieServices(org.kie.api.KieServices) 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

KieContainer (org.kie.api.runtime.KieContainer)357 KieServices (org.kie.api.KieServices)271 Test (org.junit.Test)246 KieSession (org.kie.api.runtime.KieSession)191 ReleaseId (org.kie.api.builder.ReleaseId)185 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)108 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)90 KieFileSystem (org.kie.api.builder.KieFileSystem)81 KieModule (org.kie.api.builder.KieModule)75 KieBuilder (org.kie.api.builder.KieBuilder)56 KieModuleModel (org.kie.api.builder.model.KieModuleModel)54 KieBase (org.kie.api.KieBase)49 ArrayList (java.util.ArrayList)44 Results (org.kie.api.builder.Results)40 Resource (org.kie.api.io.Resource)29 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)29 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)27 Message (org.drools.compiler.Message)26 KieBaseModel (org.kie.api.builder.model.KieBaseModel)26 InternalKieContainer (org.drools.core.impl.InternalKieContainer)25