use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class KieProjectRuntimeModulesTest method createMultipleJarAndFileResources.
@Test
public void createMultipleJarAndFileResources() throws IOException, ClassNotFoundException, InterruptedException {
KieModuleModel kProjModel1 = createKieModule("jar1", true);
KieModuleModel kProjModel2 = createKieModule("jar2", true);
KieModuleModel kProjModel3 = createKieModule("jar3", true);
KieModuleModel kProjModel4 = createKieModule("fol4", false);
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("jar1", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId("jar2", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId3 = KieServices.Factory.get().newReleaseId("jar3", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId4 = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT");
java.io.File file1 = fileManager.newFile("jar1-1.0-SNAPSHOT.jar");
java.io.File file2 = fileManager.newFile("jar2-1.0-SNAPSHOT.jar");
java.io.File file3 = fileManager.newFile("jar3-1.0-SNAPSHOT.jar");
java.io.File fol4 = fileManager.newFile("fol4-1.0-SNAPSHOT");
ZipKieModule mod1 = new ZipKieModule(releaseId1, kProjModel1, file1);
ZipKieModule mod2 = new ZipKieModule(releaseId2, kProjModel2, file2);
ZipKieModule mod3 = new ZipKieModule(releaseId3, kProjModel3, file3);
FileKieModule mod4 = new FileKieModule(releaseId4, kProjModel4, fol4);
mod1.addKieDependency(mod2);
mod1.addKieDependency(mod3);
mod1.addKieDependency(mod4);
KieModuleKieProject kProject = new KieModuleKieProject(mod1);
KieContainer kContainer = new KieContainerImpl(kProject, null);
KieBase kBase = kContainer.getKieBase("jar1.KBase1");
ClassLoader cl = ((RuleBase) kBase).getRootClassLoader();
Class cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar1");
assertNotNull(cls);
cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar2");
assertNotNull(cls);
cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar3");
assertNotNull(cls);
testEntry(new KProjectTestClassImpl("jar1", kContainer), "jar1");
testEntry(new KProjectTestClassImpl("jar2", kContainer), "jar2");
testEntry(new KProjectTestClassImpl("jar3", kContainer), "jar3");
testEntry(new KProjectTestClassImpl("fol4", kContainer), "fol4");
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class DeclaredTypesTest method testFactType.
@Test
public void testFactType() throws Exception {
// DROOLS-4784
String str = "package org.test;\n" + "import " + Person.class.getCanonicalName() + ";" + "declare Name\n" + " VALUE : String\n" + "end\n" + "rule R when\n" + " Name($v : VALUE == \"Mario\")\n" + "then\n" + " insert($v);" + "end";
KieSession ksession = getKieSession(str);
FactType nameType = ksession.getKieBase().getFactType("org.test", "Name");
Object name = nameType.newInstance();
nameType.set(name, "VALUE", "Mario");
ksession.insert(name);
ksession.fireAllRules();
assertEquals("Mario", nameType.get(name, "VALUE"));
Collection<String> results = getObjectsIntoList(ksession, String.class);
assertEquals(1, results.size());
assertEquals("Mario", results.iterator().next());
EntryPointNode epn = ((RuleBase) ksession.getKieBase()).getRete().getEntryPointNodes().values().iterator().next();
Iterator<ObjectTypeNode> otns = epn.getObjectTypeNodes().values().iterator();
ObjectTypeNode otn = otns.next();
if (otn.toString().contains("InitialFact")) {
otn = otns.next();
}
AlphaNode alpha = (AlphaNode) otn.getSinks()[0];
AlphaNodeFieldConstraint constraint = alpha.getConstraint();
int index = ((IndexableConstraint) constraint).getFieldExtractor().getIndex();
assertTrue(index >= 0);
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class CepEspTest method testEventExpiration.
@Test(timeout = 10000)
public void testEventExpiration() {
final String drl = "package org.drools.compiler\n" + "import " + StockTick.class.getCanonicalName() + ";\n" + "global java.util.List results;\n" + "\n" + "declare StockTick \n" + " @role( event )\n" + " @timestamp( dateTimestamp )\n" + " @expires( 1h30m )\n" + "end\n" + "\n" + "rule \"Check event\"\n" + "when\n" + " $st : StockTick( company == \"ACME\" )\n" + "then\n" + " results.add( $st );\n" + "end\n";
final KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("cep-esp-test", kieBaseTestConfiguration, drl);
// read in the source
final TypeDeclaration factType = ((RuleBase) kbase).getTypeDeclaration(StockTick.class);
assertEquals(TimeIntervalParser.parse("1h30m")[0], factType.getExpirationOffset());
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class MemoryLeakTest method testStagedLeftTupleLeak.
@Test
public void testStagedLeftTupleLeak() throws Exception {
// BZ-1058874
String str = "rule R1 when\n" + " String( this == \"this\" )\n" + " String( this == \"that\" )\n" + "then\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
KieSession ksession = kbase.newKieSession();
ksession.fireAllRules();
for (int i = 0; i < 10; i++) {
FactHandle fh = ksession.insert("this");
ksession.fireAllRules();
ksession.delete(fh);
ksession.fireAllRules();
}
Rete rete = ((RuleBase) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
if (String.class == otn.getObjectType().getValueType().getClassType()) {
AlphaNode alphaNode = (AlphaNode) otn.getObjectSinkPropagator().getSinks()[0];
liaNode = (LeftInputAdapterNode) alphaNode.getObjectSinkPropagator().getSinks()[0];
break;
}
}
assertNotNull(liaNode);
InternalWorkingMemory wm = (InternalWorkingMemory) ksession;
LeftInputAdapterNode.LiaNodeMemory memory = (LeftInputAdapterNode.LiaNodeMemory) wm.getNodeMemory(liaNode);
TupleSets<LeftTuple> stagedLeftTuples = memory.getSegmentMemory().getStagedLeftTuples();
assertNull(stagedLeftTuples.getDeleteFirst());
assertNull(stagedLeftTuples.getInsertFirst());
}
use of org.drools.core.impl.RuleBase in project drools by kiegroup.
the class Misc2Test method testFromEPDontRequireLeftInput.
@Test
public void testFromEPDontRequireLeftInput() {
// DROOLS-1014
String drl = "rule R when\n" + " $s1 : String() from entry-point \"xxx\"\n" + "then\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
Rete rete = ((RuleBase) kbase).getRete();
LeftInputAdapterNode liaNode = null;
for (ObjectTypeNode otn : rete.getObjectTypeNodes()) {
Class<?> otnType = ((ClassObjectType) otn.getObjectType()).getClassType();
if (String.class == otnType) {
assertEquals(1, otn.getObjectSinkPropagator().size());
} else if (InitialFact.class.isAssignableFrom(otnType)) {
assertEquals(0, otn.getObjectSinkPropagator().size());
} else {
fail("There shouldn't be other OTNs");
}
}
}
Aggregations