Search in sources :

Example 31 with KieServices

use of org.kie.api.KieServices 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 32 with KieServices

use of org.kie.api.KieServices 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 33 with KieServices

use of org.kie.api.KieServices 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 34 with KieServices

use of org.kie.api.KieServices 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 35 with KieServices

use of org.kie.api.KieServices 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

KieServices (org.kie.api.KieServices)479 Test (org.junit.Test)385 KieContainer (org.kie.api.runtime.KieContainer)249 KieFileSystem (org.kie.api.builder.KieFileSystem)242 KieSession (org.kie.api.runtime.KieSession)239 ReleaseId (org.kie.api.builder.ReleaseId)214 KieBuilder (org.kie.api.builder.KieBuilder)146 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)119 KieModule (org.kie.api.builder.KieModule)104 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)99 KieModuleModel (org.kie.api.builder.model.KieModuleModel)78 ArrayList (java.util.ArrayList)76 Results (org.kie.api.builder.Results)73 KieBase (org.kie.api.KieBase)59 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)49 KieBaseModel (org.kie.api.builder.model.KieBaseModel)45 IncrementalResults (org.kie.internal.builder.IncrementalResults)44 Message (org.drools.compiler.Message)43 Resource (org.kie.api.io.Resource)42 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)28