[jboss-jira] [JBoss JIRA] (DROOLS-2646) KieContainer#updateToVersion removing rules: logically inserted objects not removed correctly

Olga Rodionova (JIRA) issues at jboss.org
Fri Jun 22 05:23:00 EDT 2018


     [ https://issues.jboss.org/browse/DROOLS-2646?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Olga Rodionova updated DROOLS-2646:
-----------------------------------
    Steps to Reproduce: 
Consider the rule file: SimpleRuleAB.drl

declare MyIntA
    val : Integer @key
end

declare MyIntB
    val : Integer @key
end

rule "Simple rule A"
    when
    	String(this == "I'm active")
        $i : Integer(intValue > 5)
    then
        insertLogical(new MyIntA($i))        
end

rule "Simple rule B"
    when
    	String(this == "I'm active")
        $i : Integer(intValue <= 5)
    then
        insertLogical(new MyIntB($i))        
end

The test which reproduces the bug:

@Test
public void ruleRemovalTest() {

	/**
	 * Create the kie container based on a simple rule from SimpleRule.drl
	*/
	KieServices kieServices = KieServices.Factory.get();
	KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
		kieFileSystem.write(ResourceFactory.newFileResource("src/test/java/rulesengine/SimpleRuleAB.drl"));
		KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
		kieBuilder.buildAll();
		KieModule kieModule = kieBuilder.getKieModule();
		KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
		KieSession kieSession = kieContainer.newKieSession();

		/**
		 * Insert three Integer objects: 3, 7, 9
		 */
		kieSession.insert("I'm active");
		kieSession.insert(new Integer(3));
		kieSession.insert(new Integer(7));
		kieSession.insert(new Integer(9));
		Assert.assertEquals(4, kieSession.getObjects().size());

		/**
		 * Fire all rules, verify that two objects of type MyIntA and one object of type
		 * MyIntB are created
		 */
		kieSession.fireAllRules();		
		System.out.println("***************************************************");
		System.out.println("Objects in the working memory after all rules fired");
		for (Object o : kieSession.getObjects()) {
			System.out.println(o);
		}
		System.out.println("***************************************************");
		Assert.assertEquals(7, kieSession.getObjects().size());	
		
		/**
		 * Update the kie base using the kie module which no longer contains
		 * SimpleRule.drl
		 */
		kieFileSystem = kieServices.newKieFileSystem();
		kieBuilder = kieServices.newKieBuilder(kieFileSystem);
		kieBuilder.buildAll();
		kieModule = kieBuilder.getKieModule();
		kieContainer.updateToVersion(kieModule.getReleaseId());

		/**
		 * Fire all rules. Logically inserted objects of types MyIntA and MyIntB should be
		 * automatically removed from the working memory
		 */
		kieSession.fireAllRules();	
		System.out.println("***************************************************");
		System.out.println("Objects in the working memory after the SimpleRule.drl is removed");
		for (Object o : kieSession.getObjects()) {
			System.out.println(o);
		}
		System.out.println("***************************************************");
		Assert.assertEquals(4, kieSession.getObjects().size());
	}}}

Display results:

{{***************************************************
Objects in the working memory after all rules fired
I'm active
7
3
9
MyIntA( val=7 )
MyIntA( val=9 )
MyIntB( val=3 )
***************************************************

***************************************************
Objects in the working memory after the SimpleRule.drl is removed
I'm active
7
3
9
MyIntB( val=3 )
***************************************************}}

  was:
Consider the rule file: SimpleRuleAB.drl

{{declare MyIntA
    val : Integer @key
end

declare MyIntB
    val : Integer @key
end

rule "Simple rule A"
    when
    	String(this == "I'm active")
        $i : Integer(intValue > 5)
    then
        insertLogical(new MyIntA($i))        
end

rule "Simple rule B"
    when
    	String(this == "I'm active")
        $i : Integer(intValue <= 5)
    then
        insertLogical(new MyIntB($i))        
end}}

The test which reproduces the bug:
{{	@Test
	public void ruleRemovalTest() {

		/**
		 * Create the kie container based on a simple rule from SimpleRule.drl
		 */
		KieServices kieServices = KieServices.Factory.get();
		KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
		kieFileSystem.write(ResourceFactory.newFileResource("src/test/java/rulesengine/SimpleRuleAB.drl"));
		KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem);
		kieBuilder.buildAll();
		KieModule kieModule = kieBuilder.getKieModule();
		KieContainer kieContainer = kieServices.newKieContainer(kieModule.getReleaseId());
		KieSession kieSession = kieContainer.newKieSession();

		/**
		 * Insert three Integer objects: 3, 7, 9
		 */
		kieSession.insert("I'm active");
		kieSession.insert(new Integer(3));
		kieSession.insert(new Integer(7));
		kieSession.insert(new Integer(9));
		Assert.assertEquals(4, kieSession.getObjects().size());

		/**
		 * Fire all rules, verify that two objects of type MyIntA and one object of type
		 * MyIntB are created
		 */
		kieSession.fireAllRules();		
		System.out.println("***************************************************");
		System.out.println("Objects in the working memory after all rules fired");
		for (Object o : kieSession.getObjects()) {
			System.out.println(o);
		}
		System.out.println("***************************************************");
		Assert.assertEquals(7, kieSession.getObjects().size());	
		
		/**
		 * Update the kie base using the kie module which no longer contains
		 * SimpleRule.drl
		 */
		kieFileSystem = kieServices.newKieFileSystem();
		kieBuilder = kieServices.newKieBuilder(kieFileSystem);
		kieBuilder.buildAll();
		kieModule = kieBuilder.getKieModule();
		kieContainer.updateToVersion(kieModule.getReleaseId());

		/**
		 * Fire all rules. Logically inserted objects of types MyIntA and MyIntB should be
		 * automatically removed from the working memory
		 */
		kieSession.fireAllRules();	
		System.out.println("***************************************************");
		System.out.println("Objects in the working memory after the SimpleRule.drl is removed");
		for (Object o : kieSession.getObjects()) {
			System.out.println(o);
		}
		System.out.println("***************************************************");
		Assert.assertEquals(4, kieSession.getObjects().size());
	}}}

Display results:

{{***************************************************
Objects in the working memory after all rules fired
I'm active
7
3
9
MyIntA( val=7 )
MyIntA( val=9 )
MyIntB( val=3 )
***************************************************

***************************************************
Objects in the working memory after the SimpleRule.drl is removed
I'm active
7
3
9
MyIntB( val=3 )
***************************************************}}



> KieContainer#updateToVersion removing rules: logically inserted objects not removed correctly
> ---------------------------------------------------------------------------------------------
>
>                 Key: DROOLS-2646
>                 URL: https://issues.jboss.org/browse/DROOLS-2646
>             Project: Drools
>          Issue Type: Bug
>          Components: core engine
>    Affects Versions: 7.7.0.Final
>            Reporter: Olga Rodionova
>            Assignee: Mario Fusco
>
> Consider two rules which have one of the patterns in common, each of which logically inserts an object in the RHS. Build the KieModule from the KieFileSystem including these rules, create the KieContainer and the KieSession. Insert the facts. Everything works fine. 
> Create a new KieModule excluding these rules from the KieFileSystem, update the KieContainer. Expect the logically inserted facts to be retracted, as the rules which trigged their creation is no longer present. Turns out that is true for the facts inserted by the first rule, but not for the second one: the facts remain in the working memory.



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list