Uploaded image for project: 'JBRULES'
  2. JBRULES-2436

Inheritance of events does not work as one would expect when using working memory entry-points

This issue belongs to an archived project. You can view it, but you can't modify it. Learn more


      When using working memory entry-points, I have a different behaviour than when I use the session.
      Here is a test illustrating this:
      package org.drools.test;

      import org.drools.KnowledgeBase;
      import org.drools.KnowledgeBaseConfiguration;
      import org.drools.KnowledgeBaseFactory;
      import org.drools.builder.KnowledgeBuilder;
      import org.drools.builder.KnowledgeBuilderFactory;
      import org.drools.builder.ResourceType;
      import org.drools.conf.EventProcessingOption;
      import org.drools.io.ResourceFactory;
      import org.drools.logger.KnowledgeRuntimeLoggerFactory;
      import org.drools.runtime.StatefulKnowledgeSession;
      import org.drools.runtime.rule.WorkingMemoryEntryPoint;
      import org.junit.After;
      import org.junit.Before;
      import org.junit.Test;
      import java.io.StringReader;

      public class DroolsFusionInheritanceBugsTest {
      private StatefulKnowledgeSession session;
      private WorkingMemoryEntryPoint stream;
      private final static String drl = "package org.drools.test;\n" +
      "declare A\n" +
      " @role(event)\n" +
      "end\n" +
      "\n" +
      "rule \"myrule\"\n" +
      "when\n" +
      " $a : A() from entry-point \"mystream\"\n" +
      "then\n" +
      " System.out.println(\"fired!\");\n" +

      public void testOkWithEventsInheritance()

      { session.insert(new A()); session.insert(new B()); session.fireAllRules(); }

      public void testFailsWithEventsInheritanceThroughWorkingMemoryEntryPoint()

      { stream.insert(new A()); stream.insert(new B()); session.fireAllRules(); }

      public void setupDrools()

      { KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(); System.out.println("DRL is:\n" + drl); kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL); KnowledgeBaseConfiguration conf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration(); conf.setOption(EventProcessingOption.STREAM); KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(conf); kbase.addKnowledgePackages(kbuilder.getKnowledgePackages()); session = kbase.newStatefulKnowledgeSession(); assert session != null; KnowledgeRuntimeLoggerFactory.newConsoleLogger(session); stream = session.getWorkingMemoryEntryPoint("mystream"); assert stream != null : "Could not find working memory entry-point 'mystream'"; }

      public void releaseDroolsSession()

      { if (session != null) session.dispose(); }


      class A {}

      class B extends A { }

      When using working memory entry-points, the insert of a B instances fails with a:
      java.lang.ClassCastException: org.drools.common.DefaultFactHandle cannot be cast to org.drools.common.EventFactHandle

            etirelli@redhat.com Edson Tirelli
            jeje_jira Jerome Bernard (Inactive)
            rhn-support-ceverson Clark Everson