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