Java Code Examples for org.kie.api.KieBase#removeRule()

The following examples show how to use org.kie.api.KieBase#removeRule() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameBetasWith2RTNSinks() {
    String rule1 = "B(a == 15) C() A()";
    String rule2 = "B(a == 15) C() A() @watch(b, c)";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());

    ObjectTypeNode otnA = getObjectTypeNode(kbase, "A" );
    Class classType = ((ClassObjectType) otnA.getObjectType()).getClassType();
    ObjectTypeNode otnC = getObjectTypeNode(kbase, "C");
    List<String> sp = getSettableProperties(wm, otnA);

    BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA1 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA2 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[1];
    assertSame(betaNodeC.getSinkPropagator().getSinks()[0], betaNodeA1);
    assertSame(betaNodeC.getSinkPropagator().getSinks()[1], betaNodeA2);
    assertSame(betaNodeA1.getLeftTupleSource(), betaNodeC);
    assertSame(betaNodeA2.getLeftTupleSource(), betaNodeC);

    assertEquals( EmptyBitMask.get(), betaNodeC.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC.getRightInferredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), betaNodeC.getLeftInferredMask() );

    assertEquals( EmptyBitMask.get(), betaNodeA1.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeA1.getRightInferredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeA1.getLeftDeclaredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeA1.getLeftInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNodeA2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNodeA2.getRightInferredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeA2.getLeftDeclaredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeA2.getLeftInferredMask() );

    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals(1, betaNodeC.getSinkPropagator().getSinks().length);
}
 
Example 2
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testRtnSharedAlphaNoWatches() {
    String rule1 = "A( a == 10, b == 15 )";
    String rule2 = "A( a == 10, i == 20 )";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "i"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1_1.getInferredMask() );  
    
    LeftInputAdapterNode liaNode1 = ( LeftInputAdapterNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtNode1 = ( RuleTerminalNode ) liaNode1.getSinkPropagator().getSinks()[0];
    
    assertEquals( EmptyBitMask.get(), rtNode1.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), rtNode1.getInferredMask() );
    
    
    // second share
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1_2.getInferredMask() );
    
    LeftInputAdapterNode liaNode2 = ( LeftInputAdapterNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtNode2 = ( RuleTerminalNode ) liaNode2.getSinkPropagator().getSinks()[0];
    
    assertEquals( EmptyBitMask.get(), rtNode2.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i"), sp), rtNode2.getInferredMask() );
    
    // test rule removal        
    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1.getInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i"), sp), alphaNode1_2.getInferredMask() );
    
    assertEquals(  EmptyBitMask.get(), rtNode2.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i"), sp), rtNode2.getInferredMask() );
    
    // have to rebuild to remove r1
    kbase = getKnowledgeBase(rule1, rule2);
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    otn = getObjectTypeNode(kbase, "A" );
    
    alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1.getInferredMask() );   
    
    alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), alphaNode1_1.getInferredMask() );   
    
    liaNode1 = ( LeftInputAdapterNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    rtNode1 = ( RuleTerminalNode ) liaNode1.getSinkPropagator().getSinks()[0];       
    assertEquals(  EmptyBitMask.get(), rtNode1.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), rtNode1.getInferredMask() );         
}
 
Example 3
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testRtnSharedAlphaWithWatches() {
    String rule1 = "A( a == 10, b == 15 ) @watch(c, !a)";
    String rule2 = "A( a == 10, i == 20 ) @watch(s, !i)";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c", "s", "i"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );  
    
    LeftInputAdapterNode liaNode1 = ( LeftInputAdapterNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtNode1 = ( RuleTerminalNode ) liaNode1.getSinkPropagator().getSinks()[0];
    
    assertEquals( calculatePositiveMask(classType, list("c"), sp), rtNode1.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), rtNode1.getInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), rtNode1.getNegativeMask() );

    // second share
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1_2.getInferredMask() );  
    
    LeftInputAdapterNode liaNode2 = ( LeftInputAdapterNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    RuleTerminalNode rtNode2 = ( RuleTerminalNode ) liaNode2.getSinkPropagator().getSinks()[0];
    
    assertEquals( calculatePositiveMask(classType, list("s"), sp), rtNode2.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "s"), sp), rtNode2.getInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!i"), sp), rtNode2.getNegativeMask() );

    // test rule removal        
    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1.getInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1_2.getInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("s"), sp), rtNode2.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "s"), sp), rtNode2.getInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!i"), sp), rtNode2.getNegativeMask() );

    // have to rebuild to remove r1
    kbase = getKnowledgeBase(rule1, rule2);
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    otn = getObjectTypeNode(kbase, "A" );
    
    alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1.getInferredMask() );   
    
    alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );   
    
    liaNode1 = ( LeftInputAdapterNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    rtNode1 = ( RuleTerminalNode ) liaNode1.getSinkPropagator().getSinks()[0];       
    assertEquals( calculatePositiveMask(classType, list("c"), sp), rtNode1.getDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), rtNode1.getInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), rtNode1.getNegativeMask() );
}
 
Example 4
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testBetaSharedAlphaNoWatches() {
    String rule1 = "$b : B( a == 15) @watch(c, !a) A( a == 10, s == 15, b == $b.b  )";
    String rule2 = "$b : B( a == 15) @watch(j, !i) A( a == 10, i == 20, b == $b.b  )";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "s", "i"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("s"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "s", "b"), sp), alphaNode1_1.getInferredMask() );  
    
    BetaNode betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "s", "b"), sp), betaNode1.getRightInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode1.getLeftNegativeMask() );

    // second share
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b"), sp), alphaNode1_2.getInferredMask() );
    
    BetaNode betaNode2 = ( BetaNode )  alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b"), sp), betaNode2.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "j"), sp), betaNode2.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!i"), sp), betaNode2.getLeftNegativeMask() );

    // test rule removal        
    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b"), sp), alphaNode1.getInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b"), sp), alphaNode1_2.getInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b"), sp), betaNode2.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode1.getLeftNegativeMask() );

    // have to rebuild to remove r1
    kbase = getKnowledgeBase(rule1, rule2);
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    otn = getObjectTypeNode(kbase, "A" );
    
    alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "s", "b"), sp), alphaNode1.getInferredMask() );   
    
    alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("s"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "s", "b"), sp), alphaNode1_1.getInferredMask() );   
    
    betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "s", "b"), sp), betaNode1.getRightInferredMask() );   
    
    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "j"), sp), betaNode2.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!i"), sp), betaNode2.getLeftNegativeMask() );
}
 
Example 5
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testBetaSharedAlphaWithWatches() {
    String rule1 = "$b : B( a == 15) @watch(c, !a) A( a == 10, b == 15, b == $b.b  ) @watch(c, !b)";
    String rule2 = "$b : B( a == 15) @watch(j) A( a == 10, i == 20, b == $b.b ) @watch(s, !a)";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c", "s", "i"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );  
    
    BetaNode betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), betaNode1.getRightInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!b"), sp), betaNode1.getRightNegativeMask() );

    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode1.getLeftNegativeMask() );

    // second share
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "s"), sp), alphaNode1_2.getInferredMask() );  
    

    BetaNode betaNode2 = ( BetaNode )  alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b", "s"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("i", "b", "s"), sp), betaNode2.getRightInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode2.getRightNegativeMask() );

    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode1.getLeftNegativeMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "j"), sp), betaNode2.getLeftInferredMask() );
    assertEquals( EmptyBitMask.get(), betaNode2.getLeftNegativeMask() );

    // test rule removal        
    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "s"), sp), alphaNode1.getInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "s"), sp), alphaNode1_2.getInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("b", "s"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("i", "b", "s"), sp), betaNode2.getRightInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode2.getRightNegativeMask() );

    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "j"), sp), betaNode2.getLeftInferredMask() );
    assertEquals( EmptyBitMask.get(), betaNode2.getLeftNegativeMask() );

    // have to rebuild to remove r1
    kbase = getKnowledgeBase(rule1, rule2);
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    otn = getObjectTypeNode(kbase, "A" );
    
    alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1.getInferredMask() );   
    
    alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );   
    
    betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), betaNode1.getRightInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!b"), sp), betaNode1.getRightNegativeMask() );

    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "c"), sp), betaNode1.getLeftInferredMask() );
    assertEquals( calculateNegativeMask(classType, list("!a"), sp), betaNode1.getLeftNegativeMask() );
}
 
Example 6
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexBetaSharedAlphaWithWatchesRemoveR1() {
    String rule1 = "$b : B( b == 15) @watch(i) A( a == 10, b == 15 ) @watch(c)";
    String rule2 = "$b : B( b == 15) @watch(j) A( a == 10, i == 20 ) @watch(s)";
    String rule3 = "$b : B( c == 15) @watch(k) A( a == 10, i == 20, b == 10 ) @watch(j)";
    KieBase kbase = getKnowledgeBase(rule1, rule2, rule3);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "s","j"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "s", "j"), sp), alphaNode1_1.getInferredMask() );
    
    BetaNode betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("s"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), betaNode1.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode1.getLeftInferredMask() );

    // second split, third alpha
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "i", "j"), sp), alphaNode1_2.getInferredMask() );

    BetaNode betaNode3 = ( BetaNode )  alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNode3.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), betaNode3.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("k"), sp), betaNode3.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("c", "k"), sp), betaNode3.getLeftInferredMask() );
}
 
Example 7
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexBetaSharedAlphaWithWatchesRemoveR2() {
    String rule1 = "$b : B( b == 15) @watch(i) A( a == 10, b == 15 ) @watch(c)";
    String rule2 = "$b : B( b == 15) @watch(j) A( a == 10, i == 20 ) @watch(s)";
    String rule3 = "$b : B( c == 15) @watch(k) A( a == 10, i == 20, b == 10 ) @watch(j)";
    KieBase kbase = getKnowledgeBase(rule1, rule2, rule3);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c", "i", "j"), sp), alphaNode1.getInferredMask() );
            
    // first split
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );  
    
    BetaNode betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("c"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), betaNode1.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("i"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "i"), sp), betaNode1.getLeftInferredMask() );        
    
    // fist share, second alpha
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), alphaNode1_2.getInferredMask() );  
    
    AlphaNode alphaNode1_3 = ( AlphaNode ) alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_3.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), alphaNode1_3.getInferredMask() );         
    

    BetaNode betaNode2 = ( BetaNode )  alphaNode1_3.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "b", "j"), sp), betaNode2.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("k"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("c", "k"), sp), betaNode2.getLeftInferredMask() );         
       
}
 
Example 8
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testComplexBetaSharedAlphaWithWatchesRemoveR3() {
    String rule1 = "$b : B( b == 15) @watch(i) A( a == 10, b == 15 ) @watch(c)";
    String rule2 = "$b : B( b == 15) @watch(j) A( a == 10, i == 20 ) @watch(s)";
    String rule3 = "$b : B( c == 15) @watch(k) A( a == 10, i == 20, b == 10 ) @watch(j)";
    KieBase kbase = getKnowledgeBase(rule1, rule2, rule3);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());
    
    kbase.removeRule( "org.drools.compiler.integrationtests", "r2" );
    
    ObjectTypeNode otn = getObjectTypeNode(kbase, "A" );
    assertNotNull( otn );
    Class classType = ((ClassObjectType) otn.getObjectType()).getClassType();

    List<String> sp = getSettableProperties(wm, otn);        

    AlphaNode alphaNode1 = ( AlphaNode ) otn.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c", "i", "s"), sp), alphaNode1.getInferredMask() );
            
    // first share
    AlphaNode alphaNode1_1 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("b"), sp), alphaNode1_1.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode1_1.getInferredMask() );
    
    // first split
    BetaNode betaNode1 = ( BetaNode )  alphaNode1_1.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("c"), sp), betaNode1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), betaNode1.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("i"), sp), betaNode1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "i"), sp), betaNode1.getLeftInferredMask() );
    
    // second split
    AlphaNode alphaNode1_2 = ( AlphaNode ) alphaNode1.getObjectSinkPropagator().getSinks()[1];
    assertEquals( calculatePositiveMask(classType, list("i"), sp), alphaNode1_2.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), alphaNode1_2.getInferredMask() );
    

    BetaNode betaNode2 = ( BetaNode )  alphaNode1_2.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("s"), sp), betaNode2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "i", "s"), sp), betaNode2.getRightInferredMask() );
    
    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNode2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("b", "j"), sp), betaNode2.getLeftInferredMask() );
}
 
Example 9
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void test2DifferentAlphaWatchBeforeSameBeta() {
    String rule1 = "B(a == 15) @watch(b) C()";
    String rule2 = "B(a == 15) @watch(c) C()";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());

    ObjectTypeNode otnB = getObjectTypeNode(kbase, "B" );
    List<String> sp = getSettableProperties(wm, otnB);
    Class classType = ((ClassObjectType) otnB.getObjectType()).getClassType();

    AlphaNode alphaNode = ( AlphaNode ) otnB.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode.getInferredMask());

    ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" );
    BetaNode betaNodeC1 = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeC2 = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[1];

    LeftInputAdapterNode lia1 = (LeftInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[0];
    assertSame(betaNodeC1, lia1.getSinkPropagator().getSinks()[0]);
    LeftInputAdapterNode lia2 = (LeftInputAdapterNode)alphaNode.getObjectSinkPropagator().getSinks()[1];
    assertSame(betaNodeC2, lia2.getSinkPropagator().getSinks()[0]);

    assertEquals( EmptyBitMask.get(), betaNodeC1.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC1.getRightInferredMask() );
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNodeC1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), betaNodeC1.getLeftInferredMask() );

    assertEquals( EmptyBitMask.get(), betaNodeC2.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC2.getRightInferredMask() );
    assertEquals( calculatePositiveMask(classType, list("c"), sp), betaNodeC2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), betaNodeC2.getLeftInferredMask() );

    kbase.removeRule( "org.drools.compiler.integrationtests", "r0" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), alphaNode.getInferredMask());

    assertEquals( 1, lia2.getSinkPropagator().getSinks().length );
    BetaNode betaNodeC = ( BetaNode ) lia2.getSinkPropagator().getSinks()[0];

    assertEquals( EmptyBitMask.get(), betaNodeC2.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC2.getRightInferredMask() );
    assertEquals( calculatePositiveMask(classType, list("c"), sp), betaNodeC2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), betaNodeC2.getLeftInferredMask() );
}
 
Example 10
Source File: PropertySpecificTest.java    From kogito-runtimes with Apache License 2.0 4 votes vote down vote up
@Test
public void testBetaWith2BetaSinks() {
    String rule1 = "B(a == 15) @watch(b) A() @watch(i) C()";
    String rule2 = "B(a == 15) @watch(c) A() @watch(j) D()";
    KieBase kbase = getKnowledgeBase(rule1, rule2);
    InternalWorkingMemory wm = ((InternalWorkingMemory)kbase.newKieSession());

    ObjectTypeNode otnB = getObjectTypeNode(kbase, "B" );
    Class classType = ((ClassObjectType) otnB.getObjectType()).getClassType();
    List<String> sp = getSettableProperties(wm, otnB);

    AlphaNode alphaNode = ( AlphaNode ) otnB.getObjectSinkPropagator().getSinks()[0];
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b", "c"), sp), alphaNode.getInferredMask());

    ObjectTypeNode otnA = getObjectTypeNode(kbase, "A" );
    BetaNode betaNodeA1 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[0];
    BetaNode betaNodeA2 = ( BetaNode ) otnA.getObjectSinkPropagator().getSinks()[1];

    assertEquals( calculatePositiveMask(classType, list("i"), sp), betaNodeA1.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("i"), sp), betaNodeA1.getRightInferredMask() );
    assertEquals( calculatePositiveMask(classType, list("b"), sp), betaNodeA1.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), betaNodeA1.getLeftInferredMask() );

    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNodeA2.getRightDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("j"), sp), betaNodeA2.getRightInferredMask() );
    assertEquals( calculatePositiveMask(classType, list("c"), sp), betaNodeA2.getLeftDeclaredMask() );
    assertEquals( calculatePositiveMask(classType, list("a", "c"), sp), betaNodeA2.getLeftInferredMask() );

    ObjectTypeNode otnC = getObjectTypeNode(kbase, "C" );
    BetaNode betaNodeC = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0];

    assertEquals( EmptyBitMask.get(), betaNodeC.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeC.getRightInferredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeC.getLeftDeclaredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeC.getLeftInferredMask() );

    ObjectTypeNode otnD = getObjectTypeNode(kbase, "D" );
    BetaNode betaNodeD = ( BetaNode ) otnC.getObjectSinkPropagator().getSinks()[0];

    assertEquals( EmptyBitMask.get(), betaNodeD.getRightDeclaredMask() );
    assertEquals( EmptyBitMask.get(), betaNodeD.getRightInferredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeD.getLeftDeclaredMask() );
    assertEquals( AllSetBitMask.get(), betaNodeD.getLeftInferredMask() );

    kbase.removeRule( "org.drools.compiler.integrationtests", "r1" );
    assertEquals( calculatePositiveMask(classType, list("a"), sp), alphaNode.getDeclaredMask( ) );
    assertEquals( calculatePositiveMask(classType, list("a", "b"), sp), alphaNode.getInferredMask());
}