Search in sources :

Example 56 with KnowledgeBuilder

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());
    }
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 57 with KnowledgeBuilder

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());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 58 with KnowledgeBuilder

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() );
}
Also used : FactHandle(org.kie.api.runtime.rule.FactHandle) FileWriter(java.io.FileWriter) Cheese(org.drools.compiler.Cheese) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) SessionInspector(org.drools.core.util.debug.SessionInspector) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 59 with KnowledgeBuilder

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());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Example 60 with KnowledgeBuilder

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());
}
Also used : KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Test(org.junit.Test)

Aggregations

KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)376 Test (org.junit.Test)302 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)231 KieSession (org.kie.api.runtime.KieSession)149 ArrayList (java.util.ArrayList)112 List (java.util.List)65 ByteArrayResource (org.drools.core.io.impl.ByteArrayResource)52 KiePackage (org.kie.api.definition.KiePackage)39 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)38 FactHandle (org.kie.api.runtime.rule.FactHandle)36 FactType (org.kie.api.definition.type.FactType)27 KieBaseConfiguration (org.kie.api.KieBaseConfiguration)24 Person (org.drools.compiler.Person)23 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)23 KieSessionConfiguration (org.kie.api.runtime.KieSessionConfiguration)22 InternalFactHandle (org.drools.core.common.InternalFactHandle)19 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)17 TraitableBean (org.drools.core.factmodel.traits.TraitableBean)17 StringReader (java.io.StringReader)15 Resource (org.kie.api.io.Resource)15