Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-6060

Rewrite DynamicRulesTest.testDynamicFunction

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 7.50.0.Final
    • core engine
    • None
    • Undefined
    • NEW
    • NEW
    • ---
    • ---

    Description

      When I rewrite DynamicRulesTest.testDynamicFunction() with new APIs, I get an assertion failure even with standard-drl. It's likely caused by function classloading. Currently I set it as @Ignore.
      Note: Check if this use case is still supported.

          @Ignore("Fails with standard-drl after changing to new API")
          @Test(timeout=10000)
          public void testDynamicFunction() throws Exception {
              // TODO: Fails with standard-drl after changing to new API. File a JIRA
      
              //JBRULES-1258 serialising a package breaks function removal -- left the serialisation commented out for now
      //        Collection<KiePackage> kpkgs = SerializationHelper.serializeObject( loadKnowledgePackages(  "test_DynamicFunction1.drl" ) );
              Collection<KiePackage> kpkgs = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicFunction1.drl").getKiePackages();
             
      //        InternalKnowledgeBase kbase = (InternalKnowledgeBase) loadKnowledgeBase( );
              InternalKnowledgeBase kbase = (InternalKnowledgeBase)KieBaseUtil.getKieBaseFromClasspathResources("test", getClass(), kieBaseTestConfiguration);
      
              kbase.addPackages( kpkgs );
      //        kbase = SerializationHelper.serializeObject( kbase );
             
      //        final KieSession workingMemory = createKnowledgeSession( kbase );
              KieSession workingMemory = kbase.newKieSession();
      
              final List<?> list = new ArrayList<Object>();
              workingMemory.setGlobal( "list",
                                       list );
      
              final Cheese stilton = new Cheese( "stilton",
                                                 5 );
              workingMemory.insert( stilton );
      
              workingMemory.fireAllRules();
      
              assertEquals( new Integer( 5 ),
                            list.get( 0 ) );
      
              // Check a function can be removed from a package.
              // Once removed any efforts to use it should throw an Exception
              kbase.removeFunction( "org.drools.mvel.compiler.test",
                                    "addFive" );
      
              final Cheese cheddar = new Cheese( "cheddar",
                                                 5 );
              workingMemory.insert( cheddar );
      
              try {
                  workingMemory.fireAllRules();
                  fail( "Function should have been removed and NoClassDefFoundError thrown from the Consequence" );
              } catch ( final Throwable e ) {
              }
      
              // Check a new function can be added to replace an old function
      //        Collection<KiePackage> kpkgs2 = SerializationHelper.serializeObject( loadKnowledgePackages( "test_DynamicFunction2.drl" ) );
              Collection<KiePackage> kpkgs2 = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicFunction2.drl").getKiePackages();
              kbase.addPackages( kpkgs2 );
      
              final Cheese brie = new Cheese( "brie",
                                              5 );
              workingMemory.insert( brie );
      
              workingMemory.fireAllRules();
      
              assertEquals( new Integer( 6 ),
                            list.get( 1 ) );
      
      //        Collection<KiePackage> kpkgs3 = SerializationHelper.serializeObject( loadKnowledgePackages( "test_DynamicFunction3.drl" ) );
              Collection<KiePackage> kpkgs3 = KieBaseUtil.getKieBaseFromClasspathResources("tmp", getClass(), kieBaseTestConfiguration, "test_DynamicFunction3.drl").getKiePackages();
      
              kbase.addPackages( kpkgs3 );
      
              final Cheese feta = new Cheese( "feta",
                                              5 );
              workingMemory.insert( feta );
      
              workingMemory.fireAllRules();
      
              assertEquals( new Integer( 5 ),
                            list.get( 2 ) );
          }
      

      Attachments

        Issue Links

          Activity

            People

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: