use of org.kie.internal.builder.KnowledgeBuilderConfiguration in project drools by kiegroup.
the class Misc2Test method testBindingComplexExpression.
@Test
public void testBindingComplexExpression() {
// DROOLS-43
String drl = "package org.drools.test;\n" + "\n" + "global java.util.List list;\n" + "\n" + "declare Foo \n" + " a : int \n" + " b : int \n" + "end \n" + "" + "rule Init when then insert( new Foo( 3, 4 ) ); end \n" + "" + "rule \"Expr\"\n" + "when\n" + " $c := Integer() from new Integer( 4 ) \n" + " Foo( $a : a + b == 7 && a == 3 && $b : b > 0, $c := b - a == 1 ) \n" + "then\n" + " list.add( $a );\n" + " list.add( $b );\n" + " list.add( $c );\n" + "end\n" + "\n";
KnowledgeBuilderConfiguration kbConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
kbConf.setOption(LanguageLevelOption.DRL6);
KieBase kbase = loadKnowledgeBaseFromString(kbConf, drl);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertTrue(!list.isEmpty());
assertEquals(3, list.size());
assertEquals(3, list.get(0));
assertEquals(4, list.get(1));
assertEquals(4, list.get(2));
}
use of org.kie.internal.builder.KnowledgeBuilderConfiguration in project drools by kiegroup.
the class Misc2Test method testInitialFactLeaking.
@Test
public void testInitialFactLeaking() {
// DROOLS-239
String drl = "global java.util.List list;\n" + "rule R when\n" + " $o : Object()\n" + "then\n" + " list.add(1);\n" + "end\n";
KnowledgeBuilderConfiguration kbConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
KieBase kbase = loadKnowledgeBaseFromString(kbConf, drl);
KieSession ksession = kbase.newKieSession();
List list = new ArrayList();
ksession.setGlobal("list", list);
ksession.fireAllRules();
assertEquals(0, list.size());
ksession.insert("1");
ksession.fireAllRules();
assertEquals(1, list.size());
ksession.insert(1);
ksession.fireAllRules();
assertEquals(2, list.size());
ksession.dispose();
}
use of org.kie.internal.builder.KnowledgeBuilderConfiguration in project drools by kiegroup.
the class ChangeSetTest method testCustomClassLoader.
@Test(timeout = 10000)
public void testCustomClassLoader() throws Exception {
// JBRULES-3630
String absolutePath = new File("file").getAbsolutePath();
URL url = ChangeSetTest.class.getResource(ChangeSetTest.class.getSimpleName() + ".class");
File file = new File(url.toURI());
File jar = null;
while (true) {
file = file.getParentFile();
jar = new File(file, "/src/test/resources/org/drools/compiler/compiler/xml/changeset/changeset.jar");
if (jar.exists()) {
break;
}
}
ClassLoader classLoader = URLClassLoader.newInstance(new URL[] { jar.toURI().toURL() }, getClass().getClassLoader());
Resource changeSet = ResourceFactory.newClassPathResource("changeset1.xml", classLoader);
KnowledgeBuilderConfiguration conf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, classLoader);
KnowledgeBuilder builder = KnowledgeBuilderFactory.newKnowledgeBuilder(conf);
builder.add(changeSet, ResourceType.CHANGE_SET);
}
use of org.kie.internal.builder.KnowledgeBuilderConfiguration in project drools by kiegroup.
the class MannersBenchmark method main.
public static void main(final String[] args) {
KnowledgeBuilderConfiguration kbuilderConfig = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(kbuilderConfig);
kbuilder.add(ResourceFactory.newClassPathResource("manners.drl", MannersBenchmark.class), ResourceType.DRL);
Collection<KiePackage> pkgs = kbuilder.getKnowledgePackages();
// add the package to a rulebase
final InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(pkgs);
long totalTime = 0;
for (int i = 0; i < 5; i++) {
KieSession ksession = kbase.newKieSession();
String filename;
if (args.length != 0) {
String arg = args[0];
filename = arg;
} else {
filename = "manners5.dat";
}
InputStream is = MannersBenchmark.class.getResourceAsStream("data/" + filename);
List<Object> list = getInputObjects(is);
for (Iterator<Object> it = list.iterator(); it.hasNext(); ) {
Object object = it.next();
ksession.insert(object);
}
ksession.insert(new Count(1));
long start = System.currentTimeMillis();
ksession.fireAllRules();
long time = System.currentTimeMillis() - start;
System.err.println(time);
totalTime += time;
ksession.dispose();
}
System.out.println("average : " + totalTime / 5);
}
use of org.kie.internal.builder.KnowledgeBuilderConfiguration in project drools by kiegroup.
the class KBuilderSetPropertyCommand method execute.
public Void execute(Context context) {
KnowledgeBuilderConfiguration kconf = (KnowledgeBuilderConfiguration) context.get(kbuilderConfId);
kconf.setProperty(this.name, this.value);
return null;
}
Aggregations