use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class NewLineAtEoFTest method testNoNewlineAtTheEnd.
@Test
public void testNoNewlineAtTheEnd() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl + "//test")), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class NewLineAtEoFTest method testNewlineAtTheEnd.
@Test
public void testNewlineAtTheEnd() {
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
assertFalse(kbuilder.hasErrors());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class OutOfMemoryTest method testMemoryLeak.
@Test
@Ignore
public void testMemoryLeak() {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newClassPathResource("test_MemoryLeak.drl", OutOfMemoryTest.class), ResourceType.DRL);
assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
final KieSession ksession = createKnowledgeSession(kbase);
final int pcount = 5;
Person[] persons = new Person[pcount];
FactHandle[] pHandles = new FactHandle[pcount];
for (int i = 0; i < persons.length; i++) {
persons[i] = new Person("person-0-" + i);
pHandles[i] = ksession.insert(persons[i]);
}
Cheese[] cheeses = new Cheese[pcount];
FactHandle[] cHandles = new FactHandle[pcount];
for (int i = 0; i < cheeses.length; i++) {
cheeses[i] = new Cheese("cheese-0-" + i);
cHandles[i] = ksession.insert(cheeses[i]);
}
ksession.fireAllRules();
for (int j = 1; j <= 5; j++) {
for (int i = 0; i < pcount; i++) {
cheeses[i].setType("cheese-" + j + "-" + i);
ksession.update(cHandles[i], cheeses[i]);
persons[i].setName("person-" + j + "-" + i);
ksession.update(pHandles[i], persons[i]);
}
ksession.fireAllRules();
logger.info("DONE");
}
SessionInspector inspector = new SessionInspector(ksession);
SessionReporter.addNamedTemplate("dump_tuples", getClass().getResourceAsStream("/org/drools/core/util/debug/dump_tuples.mvel"));
String report = SessionReporter.generateReport("dump_tuples", inspector.getSessionInfo(), new HashMap<String, Object>());
try {
FileWriter out = new FileWriter("tupleDump.txt");
out.write(report);
out.close();
logger.info(report);
} catch (Exception e) {
e.printStackTrace();
}
// logicals = getLogicallyInserted( ksession );
// assertEquals( pcount, logicals.size() );
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class PropertySpecificTest method testWrongPropertyNameInWatchAnnotation.
@Test
public void testWrongPropertyNameInWatchAnnotation() throws Exception {
String rule = "package org.drools.compiler.integrationtests\n" + "dialect \"mvel\"\n" + "declare A\n" + " s : String\n" + "end\n" + "declare B\n" + " @propertyReactive\n" + " on : boolean\n" + " s : String\n" + "end\n" + "rule R1\n" + "when\n" + " A($s : s)\n" + " $b : B(s != $s) @watch( !s1, on )\n" + "then\n" + " modify($b) { setS($s) }\n" + "end\n" + "rule R2\n" + "when\n" + " $b : B(on == false)\n" + "then\n" + " modify($b) { setOn(true) }\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(rule.getBytes()), ResourceType.DRL);
assertEquals(1, kbuilder.getErrors().size());
}
use of org.kie.internal.builder.KnowledgeBuilder in project drools by kiegroup.
the class PropertySpecificTest method testDuplicatePropertyNamesInWatchAnnotation.
@Test
public void testDuplicatePropertyNamesInWatchAnnotation() throws Exception {
String rule = "package org.drools.compiler.integrationtests\n" + "dialect \"mvel\"\n" + "declare A\n" + " s : String\n" + "end\n" + "declare B\n" + " @propertyReactive\n" + " on : boolean\n" + " s : String\n" + "end\n" + "rule R1\n" + "when\n" + " A($s : s)\n" + " $b : B(s != $s) @watch( s, !s )\n" + "then\n" + " modify($b) { setS($s) }\n" + "end\n" + "rule R2\n" + "when\n" + " $b : B(on == false)\n" + "then\n" + " modify($b) { setOn(true) }\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(rule.getBytes()), ResourceType.DRL);
assertEquals(1, kbuilder.getErrors().size());
}
Aggregations