Search in sources :

Example 11 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 = KieBaseUtil.getKieModuleAndBuildInstallModuleFromDrl(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 12 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 13 with KieScanner

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

the class KieRepositoryScannerTest method testKScannerStartNotDeployed.

@Test
public void testKScannerStartNotDeployed() throws Exception {
    // BZ-1200784
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-start-not-deployed-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    // starting KieScanner
    KieScanner scanner = ks.newKieScanner(kieContainer);
    // scan the maven repo to get the new kjar version before it is deployed into Maven repo
    // should not throw NPE because of uninitialized dependencies due to parsing parent pom failure
    scanner.scanNow();
    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");
}
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 14 with KieScanner

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

the class KieRepositoryScannerTest method testKScannerWithKJarContainingClassLoadedFromClassLoader.

private void testKScannerWithKJarContainingClassLoadedFromClassLoader(boolean differentKbases) throws Exception {
    // DROOLS-1231
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJarWithJavaClass(ks, releaseId, "KBase1", 7);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    Class<?> beanClass = kieContainer.getClassLoader().loadClass("org.kie.test.Bean");
    KieSession ksession = kieContainer.newKieSession("KSession1");
    Object bean = beanClass.getDeclaredConstructors()[0].newInstance(2);
    ksession.insert(bean);
    checkKSession(ksession, 14);
    InternalKieModule kJar2 = createKieJarWithJavaClass(ks, releaseId, differentKbases ? "KBase2" : "KBase1", 5);
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    ks.getRepository().removeKieModule(releaseId);
    // forces cache of old Bean class definition before updating to newer release
    Class<?> beanClass1 = Class.forName("org.kie.test.Bean", true, kieContainer.getClassLoader());
    kieContainer.updateToVersion(releaseId);
    beanClass = kieContainer.getClassLoader().loadClass("org.kie.test.Bean");
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    bean = beanClass.getDeclaredConstructors()[0].newInstance(3);
    ksession2.insert(bean);
    checkKSession(ksession2, 15);
    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)

Example 15 with KieScanner

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

the class KieRepositoryScannerTest method checkUpdateDRLInSameSession.

private void checkUpdateDRLInSameSession(String drl1, String drl2) throws IOException {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJarFromDrl(ks, releaseId, drl1);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieScanner scanner = ks.newKieScanner(kieContainer);
    KieSession ksession = kieContainer.newKieSession("KSession1");
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("111");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("XXX:111", list.get(0));
    list.clear();
    InternalKieModule kJar2 = createKieJarFromDrl(ks, releaseId, drl2);
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    scanner.scanNow();
    ksession.insert("222");
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(asList("YYY:111", "YYY:222")));
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) ArrayList(java.util.ArrayList) 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)

Aggregations

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