Search in sources :

Example 1 with KieScanner

use of org.kie.api.builder.KieScanner in project jbpm by kiegroup.

the class KieScannerTest method testKScanner.

@Test
public void testKScanner() throws Exception {
    List<String> results = new ArrayList<String>();
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("results", results);
    InternalKieModule kJar1 = createJbpmKieJar("Hello");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.deployArtifact(releaseId, kJar1, kPom);
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    ProcessInstance processInstance = ksession.startProcess("Minimal", params);
    assertTrue(processInstance.getState() == ProcessInstance.STATE_COMPLETED);
    assertEquals(1, results.size());
    assertEquals("Hello", results.get(0));
    results.clear();
    InternalKieModule kJar2 = createJbpmKieJar("Morning");
    repository.deployArtifact(releaseId, kJar2, kPom);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    scanner.scanNow();
    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    ProcessInstance processInstance2 = ksession2.startProcess("Minimal", params);
    assertTrue(processInstance2.getState() == ProcessInstance.STATE_COMPLETED);
    assertEquals(1, results.size());
    assertEquals("Morning", results.get(0));
    results.clear();
    ks.getRepository().removeKieModule(releaseId);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) 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 2 with KieScanner

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

the class KieScannerMemoryTest method testScannerMemoryFootprint.

@Test
public void testScannerMemoryFootprint() throws IOException {
    final KieServices kieServices = KieServices.Factory.get();
    final KieMavenRepository repository = KieMavenRepository.getKieMavenRepository();
    final KieModule kieModule = KieUtil.getKieModuleFromDrls(TestConstants.PACKAGE_FUNCTIONAL, KieBaseTestConfiguration.CLOUD_IDENTITY, "rule R when then end");
    final ReleaseId releaseId = kieModule.getReleaseId();
    repository.installArtifact(releaseId, (InternalKieModule) kieModule, MavenUtil.createPomXml(fileManager, releaseId));
    final KieContainer kieContainer = kieServices.newKieContainer(releaseId);
    final KieScanner kieScanner = kieServices.newKieScanner(kieContainer);
    kieScanner.start(20);
    try {
        measureMemoryFootprint(1000, 100, 6, 30);
    } finally {
        kieScanner.stop();
    }
}
Also used : KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieScanner(org.kie.api.builder.KieScanner) 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 3 with KieScanner

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

the class KieRepositoryScannerTest method testScanIncludedAndIncludingDependency.

@Test
@Ignore
public void testScanIncludedAndIncludingDependency() throws Exception {
    KieMavenRepository repository = getKieMavenRepository();
    KieServices ks = KieServices.Factory.get();
    ReleaseId containerReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-container", "1.0.0-SNAPSHOT");
    ReleaseId includedReleaseId = KieServices.Factory.get().newReleaseId("org.kie", "test-project", "1.0.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, includedReleaseId, "rule1");
    repository.installArtifact(includedReleaseId, kJar1, createKPom(fileManager, includedReleaseId));
    resetFileManager();
    InternalKieModule containerKJar = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleX");
    repository.installArtifact(containerReleaseId, containerKJar, createKPom(fileManager, containerReleaseId, includedReleaseId));
    KieContainer kieContainer = ks.newKieContainer(containerReleaseId);
    KieSession ksession = kieContainer.newKieSession("KSession2");
    checkKSession(ksession, "rule1", "ruleX");
    resetFileManager();
    KieScanner scanner = ks.newKieScanner(kieContainer);
    InternalKieModule kJar2 = createKieJar(ks, includedReleaseId, "rule2");
    repository.installArtifact(includedReleaseId, kJar2, createKPom(fileManager, includedReleaseId));
    resetFileManager();
    InternalKieModule containerKJar2 = createIncludingKJar(containerReleaseId, includedReleaseId, "ruleY");
    repository.installArtifact(containerReleaseId, containerKJar2, createKPom(fileManager, containerReleaseId, includedReleaseId));
    resetFileManager();
    scanner.scanNow();
    KieSession ksession2 = kieContainer.newKieSession("KSession2");
    checkKSession(ksession2, "rule2", "ruleY");
    ks.getRepository().removeKieModule(containerReleaseId);
    ks.getRepository().removeKieModule(includedReleaseId);
}
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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with KieScanner

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

the class KieScannerIncrementalCompilationTest method checkIncrementalCompilation.

private void checkIncrementalCompilation(boolean useJavaInDrl) throws IOException {
    KieServices ks = KieServices.Factory.get();
    KieMavenRepository repository = getKieMavenRepository();
    InternalKieModule kJar1 = createKieJarWithClass(ks, releaseId, FIRST_VALUE, useJavaInDrl);
    repository.installArtifact(releaseId, kJar1, createKPom(releaseId));
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    checkValue(kieContainer, FIRST_VALUE);
    InternalKieModule kJar2 = createKieJarWithClass(ks, releaseId, SECOND_VALUE, useJavaInDrl);
    repository.installArtifact(releaseId, kJar2, createKPom(releaseId));
    scanner.scanNow();
    checkValue(kieContainer, SECOND_VALUE);
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieServices(org.kie.api.KieServices) KieScanner(org.kie.api.builder.KieScanner) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer)

Example 5 with KieScanner

use of org.kie.api.builder.KieScanner 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.kie.maven.integration.MavenRepository.getMavenRepository) MavenRepository(org.kie.maven.integration.MavenRepository) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) 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)

Aggregations

KieScanner (org.kie.api.builder.KieScanner)24 KieContainer (org.kie.api.runtime.KieContainer)24 KieServices (org.kie.api.KieServices)23 ReleaseId (org.kie.api.builder.ReleaseId)21 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)20 Test (org.junit.Test)20 KieSession (org.kie.api.runtime.KieSession)19 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)19 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)16 Path (java.nio.file.Path)5 KieMavenRepository (org.kie.scanner.KieMavenRepository)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 AbstractKieCiTest (org.kie.scanner.AbstractKieCiTest)2 HashMap (java.util.HashMap)1 Dependency (org.apache.maven.model.Dependency)1 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)1 Ignore (org.junit.Ignore)1 KieBuilder (org.kie.api.builder.KieBuilder)1 KieFileSystem (org.kie.api.builder.KieFileSystem)1