Search in sources :

Example 56 with Message

use of org.drools.compiler.Message in project drools by kiegroup.

the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace5_usingSingleQuote.

@Test
public void testKJarUpgradeDRLWithSpace5_usingSingleQuote() throws Exception {
    // DROOLS-1399 quinquies (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 typo was removed
    "   $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();
    // <<- notice the ' character on this one
    ksession.insert(new Message("Hello' World"));
    assertEquals(0, 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(1, 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 57 with Message

use of org.drools.compiler.Message in project drools by kiegroup.

the class IncrementalCompilationTest method testDeletedFile.

@Test
public void testDeletedFile() throws Exception {
    String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + "   $m : Message()\n" + "then\n" + "end\n";
    String drl2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + "   $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-delete", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2);
    KieContainer kieContainer = ks.newKieContainer(releaseId1);
    KieContainer kieContainer2 = ks.newKieContainer(releaseId1);
    KieSession ksession = kieContainer.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(2, ksession.fireAllRules());
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-delete", "1.0.1");
    km = createAndDeployJar(ks, releaseId2, null, drl2);
    kieContainer.updateToVersion(releaseId2);
    // test with the old ksession ...
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    // ... and with a brand new one
    ksession = kieContainer.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    // check that the second kieContainer hasn't been affected by the update of the first one
    KieSession ksession2 = kieContainer2.newKieSession();
    ksession2.insert(new Message("Hello World"));
    assertEquals(2, ksession2.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 58 with Message

use of org.drools.compiler.Message in project drools by kiegroup.

the class IncrementalCompilationTest method testKJarUpgrade.

@Test
public void testKJarUpgrade() throws Exception {
    String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + "   $m : Message()\n" + "then\n" + "end\n";
    String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + "   $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
    String drl2_2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + "   $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2_1);
    // Create a session and fire rules
    KieContainer kc = ks.newKieContainer(km.getReleaseId());
    KieSession ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    ksession.dispose();
    // Create a new jar for version 1.1.0
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    km = createAndDeployJar(ks, releaseId2, drl1, drl2_2);
    // try to update the container to version 1.1.0
    kc.updateToVersion(releaseId2);
    // create and use a new session
    ksession = kc.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(2, 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 59 with Message

use of org.drools.compiler.Message in project drools by kiegroup.

the class IncrementalCompilationTest method testMultipleIncrementalCompilationsWithFireUntilHalt.

@Test(timeout = 10000L)
public void testMultipleIncrementalCompilationsWithFireUntilHalt() throws Exception {
    // DROOLS-1406
    KieServices ks = KieServices.Factory.get();
    // Create an in-memory jar for version 1.0.0
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-fireUntilHalt", "1.0");
    KieModule km = createAndDeployJar(ks, releaseId1, getTestRuleForFireUntilHalt(0));
    // Create a session and fire rules
    final KieContainer kc = ks.newKieContainer(km.getReleaseId());
    final KieSession kieSession = kc.newKieSession();
    DebugList<String> list = new DebugList<String>();
    kieSession.setGlobal("list", list);
    kieSession.insert(new Message("X"));
    CountDownLatch done = new CountDownLatch(1);
    list.done = done;
    try {
        new Thread(kieSession::fireUntilHalt).start();
        done.await();
        assertEquals(1, list.size());
        assertEquals("0 - X", list.get(0));
        list.clear();
        for (int i = 1; i < 10; i++) {
            done = new CountDownLatch(1);
            list.done = done;
            ReleaseId releaseIdI = ks.newReleaseId("org.kie", "test-fireUntilHalt", "1." + i);
            km = createAndDeployJar(ks, releaseIdI, getTestRuleForFireUntilHalt(i));
            kc.updateToVersion(releaseIdI);
            done.await();
            assertEquals(1, list.size());
            assertEquals(i + " - X", list.get(0));
            list.clear();
        }
    } finally {
        kieSession.halt();
    }
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) 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 60 with Message

use of org.drools.compiler.Message in project drools by kiegroup.

the class IncrementalCompilationTest method testKJarUpgradeDRLWithSpace4.

@Test
public void testKJarUpgradeDRLWithSpace4() throws Exception {
    // DROOLS-1399 quater
    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 typo was removed
    "   $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(0, 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(1, 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)

Aggregations

Message (org.drools.compiler.Message)68 Test (org.junit.Test)65 KieSession (org.kie.api.runtime.KieSession)59 KieServices (org.kie.api.KieServices)41 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)36 ReleaseId (org.kie.api.builder.ReleaseId)30 KieContainer (org.kie.api.runtime.KieContainer)25 KieModule (org.kie.api.builder.KieModule)24 KieBase (org.kie.api.KieBase)20 KieFileSystem (org.kie.api.builder.KieFileSystem)19 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)18 ArrayList (java.util.ArrayList)14 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)8 List (java.util.List)7 KieBuilder (org.kie.api.builder.KieBuilder)6 Resource (org.kie.api.io.Resource)6 File (java.io.File)5 DynamicRulesTest (org.drools.compiler.integrationtests.DynamicRulesTest)4 KieModuleModel (org.kie.api.builder.model.KieModuleModel)4 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)4