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();
}
}
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);
}
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");
}
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);
}
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);
}
Aggregations