Search in sources :

Example 1 with SessionInspector

use of org.drools.core.util.debug.SessionInspector in project drools by kiegroup.

the class SessionInspectorTest method testGetSessionInfoWithCustomTemplate.

@Test
public void testGetSessionInfoWithCustomTemplate() {
    if (System.getProperty("java.vendor").toUpperCase().contains("IBM")) {
        // Does not work in the IBM JDK due to a bug in MVEL
        return;
    }
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
    assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.setGlobal("results", new ArrayList<Object>());
    ksession.insert(new Dimension(100, 50));
    ksession.insert(new Dimension(130, 80));
    ksession.insert(new Dimension(50, 40));
    ksession.insert(new Dimension(50, 40));
    Cheesery cheesery = new Cheesery();
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    ksession.insert(cheesery);
    ksession.insert(new Person("Bob", "muzzarella"));
    ksession.insert(new Person("Mark", "brie"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Double(10));
    ksession.insert(new Double(11));
    ksession.insert(new Double(12));
    ksession.insert(new Double(13));
    ksession.insert(new Double(14));
    ksession.insert(new Integer(15));
    ksession.insert(new Integer(16));
    ksession.insert(new Integer(17));
    ksession.insert(new Integer(18));
    FactHandle handle = ksession.insert(new Worker());
    ksession.retract(handle);
    SessionInspector inspector = new SessionInspector(ksession);
    StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
    SessionReporter.addNamedTemplate("topten", getClass().getResourceAsStream("customreports.mvel"));
    String report = SessionReporter.generateReport("topten", info, null);
    assertNotNull(report);
}
Also used : StatefulKnowledgeSessionInfo(org.drools.core.util.debug.StatefulKnowledgeSessionInfo) FactHandle(org.kie.api.runtime.rule.FactHandle) Cheese(org.drools.compiler.Cheese) Dimension(java.awt.Dimension) Cheesery(org.drools.compiler.Cheesery) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Worker(org.drools.compiler.Worker) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) SessionInspector(org.drools.core.util.debug.SessionInspector) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 2 with SessionInspector

use of org.drools.core.util.debug.SessionInspector in project drools by kiegroup.

the class SessionInspectorTest method testGetSessionInfo.

@Test
public void testGetSessionInfo() {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_SubNetworks.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_AccumulateWithFromChaining.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_CollectResultsBetaConstraint.drl"), ResourceType.DRL);
    kbuilder.add(ResourceFactory.newClassPathResource("org/drools/compiler/integrationtests/test_QueryMemoryLeak.drl"), ResourceType.DRL);
    assertFalse(kbuilder.getErrors().toString(), kbuilder.hasErrors());
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    KieSession ksession = createKnowledgeSession(kbase);
    ksession.setGlobal("results", new ArrayList<Object>());
    ksession.insert(new Dimension(100, 50));
    ksession.insert(new Dimension(130, 80));
    ksession.insert(new Dimension(50, 40));
    ksession.insert(new Dimension(50, 40));
    Cheesery cheesery = new Cheesery();
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("brie", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("muzzarella", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    cheesery.addCheese(new Cheese("stilton", 10));
    ksession.insert(cheesery);
    ksession.insert(new Person("Bob", "muzzarella"));
    ksession.insert(new Person("Mark", "brie"));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("brie", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("muzzarella", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Cheese("Stilton", 10));
    ksession.insert(new Double(10));
    ksession.insert(new Double(11));
    ksession.insert(new Double(12));
    ksession.insert(new Double(13));
    ksession.insert(new Double(14));
    ksession.insert(new Integer(15));
    ksession.insert(new Integer(16));
    ksession.insert(new Integer(17));
    ksession.insert(new Integer(18));
    FactHandle handle = ksession.insert(new Worker());
    ksession.retract(handle);
    SessionInspector inspector = new SessionInspector(ksession);
    StatefulKnowledgeSessionInfo info = inspector.getSessionInfo();
    String report = SessionReporter.generateReport("simple", info, null);
    assertNotNull(report);
}
Also used : StatefulKnowledgeSessionInfo(org.drools.core.util.debug.StatefulKnowledgeSessionInfo) FactHandle(org.kie.api.runtime.rule.FactHandle) Cheese(org.drools.compiler.Cheese) Dimension(java.awt.Dimension) Cheesery(org.drools.compiler.Cheesery) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) Worker(org.drools.compiler.Worker) KieSession(org.kie.api.runtime.KieSession) Person(org.drools.compiler.Person) SessionInspector(org.drools.core.util.debug.SessionInspector) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 3 with SessionInspector

use of org.drools.core.util.debug.SessionInspector 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)

Aggregations

Cheese (org.drools.compiler.Cheese)3 Person (org.drools.compiler.Person)3 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)3 SessionInspector (org.drools.core.util.debug.SessionInspector)3 Test (org.junit.Test)3 KieSession (org.kie.api.runtime.KieSession)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 KnowledgeBuilder (org.kie.internal.builder.KnowledgeBuilder)3 Dimension (java.awt.Dimension)2 Cheesery (org.drools.compiler.Cheesery)2 Worker (org.drools.compiler.Worker)2 StatefulKnowledgeSessionInfo (org.drools.core.util.debug.StatefulKnowledgeSessionInfo)2 FileWriter (java.io.FileWriter)1 Ignore (org.junit.Ignore)1