Search in sources :

Example 16 with KieContainer

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

the class KieRepositoryScannerTest method testKieScannerScopesNotRequired.

@Test
public void testKieScannerScopesNotRequired() throws Exception {
    MavenRepository repository = getMavenRepository();
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseIdWithDep = ks.newReleaseId("org.kie", "test-with-dep", "1.0-SNAPSHOT");
    Dependency dep1 = dependencyWithScope("org.kie", "test-dep1-in-test-scope", "1.0-SNAPSHOT", "test");
    Dependency dep2 = dependencyWithScope("org.kie", "test-dep2-in-provided-scope", "1.0-SNAPSHOT", "provided");
    Dependency dep3 = dependencyWithScope("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT", "system");
    dep3.setSystemPath(fileManager.getRootDirectory().getAbsolutePath());
    // to ensure KieBuilder is able to build correctly:
    repository.installArtifact(ks.newReleaseId("org.kie", "test-dep3-in-system-scope", "1.0-SNAPSHOT"), new byte[] {}, new byte[] {});
    InternalKieModule kJar2 = createKieJarWithDependencies(ks, releaseIdWithDep, false, "rule1", dep1, dep2, dep3);
    KieContainer kieContainer = ks.newKieContainer(releaseIdWithDep);
    // DROOLS-1051 following should not throw NPE because dependencies are not in scope of scanner
    KieScanner scanner = ks.newKieScanner(kieContainer);
    assertNotNull(scanner);
}
Also used : MavenRepository.getMavenRepository(org.appformer.maven.integration.MavenRepository.getMavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) MavenRepository(org.appformer.maven.integration.MavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Dependency(org.apache.maven.model.Dependency) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 17 with KieContainer

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

the class KieRepositoryScannerTest method testKScanner.

@Test
public void testKScanner() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");
    // create a new kjar
    InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
    // deploy it on maven
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    // since I am not calling start() on the scanner it means it won't have automatic scheduled scanning
    KieScanner scanner = ks.newKieScanner(kieContainer);
    // scan the maven repo to get the new kjar version and deploy it on the kcontainer
    scanner.scanNow();
    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 18 with KieContainer

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

the class KieRepositoryScannerTest method testTypeAndRuleInDifferentKieModules.

@Test
public void testTypeAndRuleInDifferentKieModules() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId depId = ks.newReleaseId("org.kie", "test-types", "1.0");
    InternalKieModule kJar1 = createKieJarWithType(ks, depId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(depId, kJar1, createKPom(fileManager, depId));
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-rules", "1.0");
    InternalKieModule kieModule = createKieJarWithRules(ks, releaseId, depId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, 15);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 19 with KieContainer

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

the class KieRepositoryScannerTest method testScannerOnPomRuleProject.

@Test
public void testScannerOnPomRuleProject() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "scanner-test", "1.0");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "scanner-test", "2.0");
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployPomArtifact("org.kie", "scanner-master-test", "1.0", createMasterKPom("scanner-test"));
    resetFileManager();
    InternalKieModule kJar1 = createKieJar(ks, releaseId1, "rule1");
    repository.installArtifact(releaseId1, kJar1, createKPom(fileManager, releaseId1));
    KieContainer kieContainer = ks.newKieContainer(ks.newReleaseId("org.kie", "scanner-master-test", "LATEST"));
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1");
    KieScanner scanner = ks.newKieScanner(kieContainer);
    InternalKieModule kJar2 = createKieJar(ks, releaseId2, "rule2");
    repository.installArtifact(releaseId2, kJar2, createKPom(fileManager, releaseId2));
    scanner.scanNow();
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    checkKSession(ksession2, "rule2");
    ks.getRepository().removeKieModule(releaseId1);
    ks.getRepository().removeKieModule(releaseId2);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 20 with KieContainer

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

the class KieRepositoryScannerTest method testKScannerStartScanNow.

@Test
public void testKScannerStartScanNow() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");
    KieScanner scanner = ks.newKieScanner(kieContainer);
    // Starting scanner with 200ms interval.
    scanner.start(100);
    try {
        // Manual scan, should continue interval scanning afterwards.
        scanner.scanNow();
        InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
        repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
        // Check each 100ms until scanner finds the new kjar (or timeout is reached)
        long timeSpent = 0;
        while (timeSpent <= 5000) {
            // create a ksession and check the ksession produces the expected results
            KieSession ksession2 = kieContainer.newKieSession("KSession1");
            if (producesResults(ksession2, "rule2", "rule3")) {
                break;
            }
            Thread.sleep(100);
            timeSpent += 100;
        }
    } finally {
        scanner.stop();
        ks.getRepository().removeKieModule(releaseId);
    }
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieScanner(org.drools.compiler.kie.builder.impl.InternalKieScanner) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) 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