use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class MavenDeployTest method testKScannerWithDeployUsingDistributionManagement.
@Test
public void testKScannerWithDeployUsingDistributionManagement() throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy-dist", "1.0-SNAPSHOT");
Path m2Folder = Files.createTempDirectory("temp-m2-dist");
Path settingsXmlPath = generateSettingsXml(m2Folder);
String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
try {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
MavenSettings.reinitSettings();
InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
repository.deployArtifact(releaseId, kJar1, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
// 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.deployArtifact(releaseId, kJar2, createKPomWithDistributionManagement(m2Folder, releaseId).toFile());
// 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);
} finally {
if (oldSettingsXmlPath == null) {
System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
} else {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
}
MavenSettings.reinitSettings();
}
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class MavenDeployTest method testDeploy.
@Test
public void testDeploy() throws IOException {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-test-deploy", "1.0-SNAPSHOT");
Path m2Folder = Files.createTempDirectory("temp-m2");
Path settingsXmlPath = generateSettingsXml(m2Folder);
String oldSettingsXmlPath = System.getProperty(CUSTOM_SETTINGS_PROPERTY);
try {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, settingsXmlPath.toString());
MavenSettings.reinitSettings();
InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
KieContainer kieContainer = ks.newKieContainer(releaseId);
KieMavenRepository repository = getKieMavenRepository();
RemoteRepository remote = createRemoteRepository(m2Folder);
repository.deployArtifact(remote, releaseId, kJar1, createKPom(m2Folder, releaseId).toFile());
// 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.deployArtifact(remote, releaseId, kJar2, createKPom(m2Folder, releaseId).toFile());
// 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);
} finally {
if (oldSettingsXmlPath == null) {
System.clearProperty(CUSTOM_SETTINGS_PROPERTY);
} else {
System.setProperty(CUSTOM_SETTINGS_PROPERTY, oldSettingsXmlPath);
}
MavenSettings.reinitSettings();
}
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class KieScannerMBeanTest method testKScannerMBean.
@Test
public void testKScannerMBean() throws Exception {
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-mbean-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");
KieRepositoryScannerImpl scanner = (KieRepositoryScannerImpl) ks.newKieScanner(kieContainer);
KieScannerMBeanImpl mBean = (KieScannerMBeanImpl) scanner.getMBean();
ObjectName mbeanName = mBean.getMBeanName();
// we want to check that the mbean is register in the server and exposing the correct attribute values
// so we fetch the attributes from the server
Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "ScannerReleaseId"));
Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "CurrentReleaseId"));
Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
MBeanUtils.invoke(mbeanName, "start", new Object[] { Long.valueOf(10000) }, new String[] { "long" });
Assert.assertEquals(InternalKieScanner.Status.RUNNING.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
MBeanUtils.invoke(mbeanName, "stop", new Object[] {}, new String[] {});
Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
// create a new kjar
InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
// deploy it on maven
repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
MBeanUtils.invoke(mbeanName, "scanNow", new Object[] {}, new String[] {});
// create a ksesion and check it works as expected
KieSession ksession2 = kieContainer.newKieSession("KSession1");
checkKSession(ksession2, "rule2", "rule3");
MBeanUtils.invoke(mbeanName, "shutdown", new Object[] {}, new String[] {});
Assert.assertEquals(InternalKieScanner.Status.SHUTDOWN.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
ks.getRepository().removeKieModule(releaseId);
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class XSDResourceTest method testXSDResourceNotBreakingCompilation.
@Test
public void testXSDResourceNotBreakingCompilation() {
final KieContainer kcontainer = KieServices.Factory.get().getKieClasspathContainer();
final KieBase kieBase = kcontainer.getKieBase("xsdKieBase");
Assertions.assertThat(kieBase).as("Created KieBase with XSD should not be null").isNotNull();
}
use of org.kie.api.runtime.KieContainer in project drools by kiegroup.
the class IncrementalCompilationTest method testEventDeclarationInSeparatedDRL.
@Test
public void testEventDeclarationInSeparatedDRL() throws Exception {
// DROOLS-1241
String drl1 = "import " + SimpleEvent.class.getCanonicalName() + ";\n" + "declare SimpleEvent\n" + " @role( event )\n" + " @timestamp( timestamp )\n" + " @expires( 2d )\n" + "end\n";
String drl2 = "import " + SimpleEvent.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R1 when\n" + " $s:SimpleEvent(code==\"MY_CODE\") over window:time( 1s )\n" + "then\n" + " list.add(\"MY_CODE\");\n" + "end\n";
String drl3 = "import " + SimpleEvent.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R2 when\n" + " $s:SimpleEvent(code==\"YOUR_CODE\") over window:time( 1s )\n" + "then\n" + " list.add(\"YOUR_CODE\");\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("KSession1").setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get(ClockType.PSEUDO_CLOCK.getId()));
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-cep-upgrade", "1.1.1");
KieModule km = deployJar(ks, createKJar(ks, kproj, releaseId1, null, drl1, drl2));
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(new SimpleEvent("1", "MY_CODE", 0));
ksession.insert(new SimpleEvent("2", "YOUR_CODE", 0));
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("MY_CODE", list.get(0));
list.clear();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-cep-upgrade", "1.1.2");
// the null drl placeholder is used to have the same drl with a different file name
// this causes the removal and readdition of both rules
km = deployJar(ks, createKJar(ks, kproj, releaseId2, null, drl1, drl2, drl3));
Results results = kc.updateToVersion(releaseId2);
assertEquals(0, results.getMessages().size());
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("YOUR_CODE", list.get(0));
}
Aggregations