Skip to content
Browse files

DROOLS-7 most of the tests for propagation logic now work

  • Loading branch information...
1 parent 5779305 commit 48c5c712b925afa251aa58e99a6c40a2278ce4cd @mdproctor mdproctor committed
Showing with 355 additions and 187 deletions.
  1. +1 −1 drools-compiler/src/test/java/org/drools/compiler/CommonTestMethodBase.java
  2. +69 −69 drools-compiler/src/test/java/org/drools/compiler/factmodel/traits/TraitTest.java
  3. +5 −2 drools-compiler/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java
  4. +2 −1 drools-compiler/src/test/java/org/drools/compiler/integrationtests/KnowledgeBuilderTest.java
  5. +24 −16 drools-compiler/src/test/java/org/drools/compiler/integrationtests/MiscTest.java
  6. +0 −1 drools-compiler/src/test/java/org/drools/compiler/integrationtests/PropertySpecificTest.java
  7. +111 −11 drools-compiler/src/test/java/org/drools/compiler/integrationtests/SegmentCreationTest.java
  8. +10 −2 drools-compiler/src/test/java/org/drools/compiler/integrationtests/SerializationHelper.java
  9. +5 −6 drools-compiler/src/test/java/org/drools/compiler/integrationtests/TruthMaintenanceTest.java
  10. +2 −3 drools-compiler/src/test/java/org/drools/compiler/lang/RuleParserTest.java
  11. +0 −7 drools-compiler/src/test/resources/org/drools/compiler/factmodel/traits/testTraitLegacyCore.drl
  12. +2 −2 drools-compiler/src/test/resources/org/drools/compiler/integrationtests/test_FromArrayIteration.drl
  13. +1 −1 drools-compiler/src/test/resources/org/drools/compiler/integrationtests/test_FromWithParams.drl
  14. +2 −4 drools-compiler/src/test/resources/org/drools/compiler/integrationtests/varargs2.drl
  15. +2 −1 drools-core/src/main/java/org/drools/core/beliefsystem/jtms/JTMSBeliefSystem.java
  16. +2 −1 drools-core/src/main/java/org/drools/core/beliefsystem/simple/SimpleBeliefSystem.java
  17. +2 −1 drools-core/src/main/java/org/drools/core/common/AbstractWorkingMemory.java
  18. +7 −1 drools-core/src/main/java/org/drools/core/common/BinaryHeapQueueAgendaGroup.java
  19. +27 −18 drools-core/src/main/java/org/drools/core/common/NamedEntryPoint.java
  20. +1 −1 drools-core/src/main/java/org/drools/core/common/PropagationContextImpl.java
  21. +6 −3 drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java
  22. +12 −11 drools-core/src/main/java/org/drools/core/phreak/SegmentUtilities.java
  23. +31 −7 drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java
  24. +5 −2 drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java
  25. +8 −4 drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java
  26. +12 −6 drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java
  27. +1 −3 drools-core/src/main/java/org/drools/core/reteoo/RiaPathMemory.java
  28. +5 −2 drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java
View
2 drools-compiler/src/test/java/org/drools/compiler/CommonTestMethodBase.java
@@ -41,7 +41,7 @@
* in drools-persistence-jpa.
*/
public class CommonTestMethodBase extends Assert {
- private static PhreakOption preak = PhreakOption.DISABLED;
+ public static PhreakOption preak = PhreakOption.DISABLED;
// ***********************************************
// METHODS TO BE REMOVED FOR 6.0.0
View
138 drools-compiler/src/test/java/org/drools/compiler/factmodel/traits/TraitTest.java
@@ -197,12 +197,12 @@ public void traitWrapGetAndSet( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapper_GetAndSetTriple() {
traitWrapGetAndSet( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapper_GetAndSetMap() {
traitWrapGetAndSet( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -246,12 +246,12 @@ public void traitShed( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitShedTriple() {
traitShed( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitShedMap() {
traitShed( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -287,12 +287,12 @@ public void traitDon( TraitFactory.VirtualPropertyMode mode ) {
System.out.println( Arrays.asList(x.getClass().getInterfaces() ));
}
- @Test
+ @Test(timeout = 10000)
public void testTraitDonTriple() {
traitDon( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitDonMap() {
traitDon( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -317,12 +317,12 @@ public void mixin( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitMixinTriple() {
mixin( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitMxinMap() {
mixin( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -353,12 +353,12 @@ public void traitMethodsWithObjects( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitObjMethodsTriple() {
traitMethodsWithObjects( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitObjMethodsMap() {
traitMethodsWithObjects( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -387,12 +387,12 @@ public void traitMethodsWithPrimitives( TraitFactory.VirtualPropertyMode mode )
}
- @Test
+ @Test(timeout = 10000)
public void testTraitPrimMethodsTriple() {
traitMethodsWithPrimitives( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitPrimMethodsMap() {
traitMethodsWithPrimitives( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -482,12 +482,12 @@ public void traitProxy( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitProxyTriple() {
traitProxy( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitProxyMap() {
traitProxy( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -626,12 +626,12 @@ public void wrapperSize( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperSizeTriple() {
wrapperSize( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperSizeMap() {
wrapperSize( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -720,12 +720,12 @@ public void wrapperEmpty( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperEmptyTriple() {
wrapperEmpty( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperEmptyMap() {
wrapperEmpty( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -860,12 +860,12 @@ public void wrapperContainsKey( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitContainskeyTriple() {
wrapperContainsKey( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitContainskeyMap() {
wrapperContainsKey( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -971,12 +971,12 @@ public int compare( Object o1, Object o2 ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperKSVTriple() {
wrapperKeySetAndValues( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperKSVMap() {
wrapperKeySetAndValues( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1106,12 +1106,12 @@ public void wrapperClearAndRemove( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperClearTriples() {
wrapperClearAndRemove( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWrapperClearMap() {
wrapperClearAndRemove( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1146,13 +1146,13 @@ public void isA( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
@Ignore("problem during phreak work")
public void testISATriple() {
isA( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
@Ignore("problem during phreak work")
public void testISAMap() {
isA( TraitFactory.VirtualPropertyMode.MAP );
@@ -1176,12 +1176,12 @@ public void overrideType( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testOverrideTriple() {
overrideType( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testOverrideMap() {
overrideType( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1217,12 +1217,12 @@ public void traitLegacy( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testLegacyTriple() {
traitLegacy( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testLegacyMap() {
traitLegacy( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1255,12 +1255,12 @@ public void traitCollections( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testCollectionsTriple() {
traitCollections( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testCollectionsMap() {
traitCollections( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1299,12 +1299,12 @@ public void traitCore( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testCoreTriple() {
traitCore( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testCoreMap() {
traitCore( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1326,12 +1326,12 @@ public void traitWithEquality( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testEqTriple() {
traitWithEquality( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testEqMap() {
traitWithEquality( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1364,12 +1364,12 @@ public void traitDeclared( TraitFactory.VirtualPropertyMode mode ) {
assertFalse( untrueTraits.contains( 1 ) );
}
- @Test
+ @Test(timeout = 10000)
public void testDeclaredTriple() {
traitDeclared( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testDeclaredMap() {
traitDeclared( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1396,12 +1396,12 @@ public void traitPojo( TraitFactory.VirtualPropertyMode mode ) {
assertFalse( untrueTraits.contains( 1 ) );
}
- @Test
+ @Test(timeout = 10000)
public void testPojoTriple() {
traitPojo( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testPojoMap() {
traitPojo( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1441,12 +1441,12 @@ public void isAOperator( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testISA2Triple() {
isAOperator( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testISA2Map() {
isAOperator( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1514,12 +1514,12 @@ protected void manyTraits( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testManyTraitsTriples() {
manyTraits( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testManyTraitsMap() {
manyTraits( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1549,12 +1549,12 @@ public void traitManyTimes( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testManyTriple() {
traitManyTimes( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testManyMap() {
traitManyTimes( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1636,12 +1636,12 @@ public void traitsInBatchExecution( TraitFactory.VirtualPropertyMode mode ) {
assertTrue( list.contains( 2 ) );
}
- @Test
+ @Test(timeout = 10000)
public void testBatchTriple() {
traitsInBatchExecution( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testBatchMap() {
traitsInBatchExecution( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1709,12 +1709,12 @@ public void manyTraitsStateless( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testManyStatelessTriple() {
manyTraitsStateless( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testManyStatelessMap() {
manyTraitsStateless( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1794,12 +1794,12 @@ public void aliasing( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testAliasingTriples() {
aliasing( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testAliasingMap() {
aliasing( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -1886,19 +1886,19 @@ public void traitLogicalRemoval( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testLogicalRemovalTriples() {
traitLogicalRemoval( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testLogicalRemovalMap() {
traitLogicalRemoval( TraitFactory.VirtualPropertyMode.MAP );
}
- @Test
+ @Test(timeout = 10000)
public void testTMSConsistencyWithNonTraitableBeans() {
String s1 = "package org.drools.compiler.test;\n" +
@@ -1995,12 +1995,12 @@ public void traitWard( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWardTriple() {
traitWard( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWardMap() {
traitWard( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -2061,18 +2061,18 @@ public void traitGrant( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitGrantTriple() {
traitGrant( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitGrantMap() {
traitGrant( TraitFactory.VirtualPropertyMode.MAP );
}
- @Test
+ @Test(timeout = 10000)
public void testInternalComponentsMap( ) {
String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl";
@@ -2125,7 +2125,7 @@ public void testInternalComponentsMap( ) {
}
- @Test
+ @Test(timeout = 10000)
public void testInternalComponentsTriple( ) {
String source = "org/drools/compiler/factmodel/traits/testTraitDon.drl";
@@ -2239,12 +2239,12 @@ public void traitWardOnHierarchy( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWardOnHierarchyTriple() {
traitWardOnHierarchy( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWardOnHierarchyMap() {
traitWardOnHierarchy( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -2332,12 +2332,12 @@ public void traitsLegacyWrapperCoherence( TraitFactory.VirtualPropertyMode mode
}
- @Test
+ @Test(timeout = 10000)
public void testTraitsBeanWrapperDataStructuresTriples() {
traitsLegacyWrapperCoherence( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitsBeanWrapperDataStructuresMap() {
traitsLegacyWrapperCoherence( TraitFactory.VirtualPropertyMode.MAP );
}
@@ -2414,12 +2414,12 @@ public void traitRedundancy( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitRedundancyTriples() {
traitRedundancy(TraitFactory.VirtualPropertyMode.TRIPLES);
}
- @Test
+ @Test(timeout = 10000)
public void testTraitRedundancyMap() {
traitRedundancy(TraitFactory.VirtualPropertyMode.MAP);
}
@@ -2465,12 +2465,12 @@ public void traitSimpleTypes( TraitFactory.VirtualPropertyMode mode ) {
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWithSimpleTypesTriples() {
traitSimpleTypes( TraitFactory.VirtualPropertyMode.TRIPLES );
}
- @Test
+ @Test(timeout = 10000)
public void testTraitWithSimpleTypesMap() {
traitSimpleTypes( TraitFactory.VirtualPropertyMode.MAP );
}
View
7 drools-compiler/src/test/java/org/drools/compiler/integrationtests/BackwardChainingTest.java
@@ -41,6 +41,7 @@
import org.kie.internal.KnowledgeBaseFactory;
import org.kie.internal.builder.KnowledgeBuilder;
import org.kie.internal.builder.KnowledgeBuilderFactory;
+import org.kie.internal.builder.conf.PhreakOption;
import org.kie.internal.definition.KnowledgePackage;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.runtime.StatefulKnowledgeSession;
@@ -1488,9 +1489,11 @@ public void testNaniSearchs() throws Exception {
l );
}
- @Test (timeout = 10000)
- @Ignore("Ingored for PhreakOption, as test is order sensitive")
+ @Test //(timeout = 10000)
public void testSubNetworksAndQueries() throws Exception {
+ if( CommonTestMethodBase.preak == PhreakOption.DISABLED ) {
+ return; //Disbaled due to phreak, as tests is order specific
+ }
String str = "" +
"package org.drools.compiler.test \n" +
View
3 drools-compiler/src/test/java/org/drools/compiler/integrationtests/KnowledgeBuilderTest.java
@@ -116,7 +116,7 @@ public void testCompositeKnowledgeBuilder() throws Exception {
}
@Test
- @Ignore("problem during phreak work")
+ @Ignore("toString recursion of type declarations breaks phreak")
public void testDifferentPackages() throws Exception {
String rule = "package org.drools.compiler.test.rule\n" +
"import org.drools.compiler.testA.FactA\n" +
@@ -151,6 +151,7 @@ public void testDifferentPackages() throws Exception {
.add( ResourceFactory.newByteArrayResource( declarationB.getBytes() ) )
.build();
+
if ( kbuilder.hasErrors() ) {
fail( kbuilder.getErrors().toString() );
}
View
40 drools-compiler/src/test/java/org/drools/compiler/integrationtests/MiscTest.java
@@ -1979,8 +1979,11 @@ public void testNullConstraint() throws Exception {
}
@Test
- @Ignore("Disbaled due to phreak, as tests is order specific")
public void testBasicFrom() throws Exception {
+ if( CommonTestMethodBase.preak == PhreakOption.DISABLED ) {
+ return; //Disbaled due to phreak, as tests is order specific
+ }
+
KnowledgeBase kbase = loadKnowledgeBase("test_From.drl" );
kbase = SerializationHelper.serializeObject( kbase );
@@ -2020,17 +2023,17 @@ public void testBasicFrom() throws Exception {
assertEquals( 2,
((List) ksession.getGlobal( "list1" )).size() );
assertEquals( cheddar,
- ((List) ksession.getGlobal( "list1" )).get( 0 ) );
- assertEquals( stilton,
((List) ksession.getGlobal( "list1" )).get( 1 ) );
+ assertEquals( stilton,
+ ((List) ksession.getGlobal( "list1" )).get( 0 ) );
// from using a declaration
assertEquals( 2,
((List) ksession.getGlobal( "list2" )).size() );
assertEquals( cheddar,
- ((List) ksession.getGlobal( "list2" )).get( 0 ) );
- assertEquals( stilton,
((List) ksession.getGlobal( "list2" )).get( 1 ) );
+ assertEquals( stilton,
+ ((List) ksession.getGlobal( "list2" )).get( 0 ) );
// from using a declaration
assertEquals( 1,
@@ -2040,8 +2043,11 @@ public void testBasicFrom() throws Exception {
}
@Test
- @Ignore("Disbaled due to phreak, as tests is order specific")
public void testFromWithParams() throws Exception {
+ if( CommonTestMethodBase.preak == PhreakOption.DISABLED ) {
+ return; //Disbaled due to phreak, as tests is order specific
+ }
+
KnowledgeBase kbase = loadKnowledgeBase( "test_FromWithParams.drl" );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
@@ -2065,7 +2071,7 @@ public void testFromWithParams() throws Exception {
((List) ksession.getGlobal( "list" )).size() );
- final List array = (List) ((List) ksession.getGlobal( "list" )).get( 0 );
+ final List array = (List) ((List) ksession.getGlobal( "list" )).get( 5 );
assertEquals( 3,
array.size() );
final Person p = (Person) array.get( 0 );
@@ -2081,7 +2087,7 @@ public void testFromWithParams() throws Exception {
assertEquals( "y",
nested.get( 1 ) );
- final Map map = (Map) ((List) ksession.getGlobal( "list" )).get( 5 );
+ final Map map = (Map) ((List) ksession.getGlobal( "list" )).get( 4 );
assertEquals( 2,
map.keySet().size() );
@@ -2098,13 +2104,13 @@ public void testFromWithParams() throws Exception {
nestedMap.get( "key2" ) );
assertEquals( new Integer( 42 ),
- ((List) ksession.getGlobal( "list" )).get( 4 ) );
- assertEquals( "literal",
((List) ksession.getGlobal( "list" )).get( 3 ) );
- assertEquals( bob,
+ assertEquals( "literal",
((List) ksession.getGlobal( "list" )).get( 2 ) );
- assertEquals( globalObject,
+ assertEquals( bob,
((List) ksession.getGlobal( "list" )).get( 1 ) );
+ assertEquals( globalObject,
+ ((List) ksession.getGlobal( "list" )).get( 0 ) );
}
@Test
@@ -5093,8 +5099,10 @@ public void testFromNestedAccessors() throws Exception {
}
@Test
- @Ignore("Disbaled due to phreak, as tests is order specific")
public void testFromArrayIteration() throws Exception {
+ if( CommonTestMethodBase.preak == PhreakOption.DISABLED ) {
+ return; //Disbaled due to phreak, as tests is order specific
+ }
KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBase( "test_FromArrayIteration.drl" ) );
StatefulKnowledgeSession session = createKnowledgeSession( kbase );
@@ -5110,11 +5118,11 @@ public void testFromArrayIteration() throws Exception {
list.size() );
assertEquals( "Message3",
- list.get( 0 ) );
- assertEquals( "Message2",
list.get( 2 ) );
- assertEquals( "Message1",
+ assertEquals( "Message2",
list.get( 1 ) );
+ assertEquals( "Message1",
+ list.get( 0 ) );
}
View
1 drools-compiler/src/test/java/org/drools/compiler/integrationtests/PropertySpecificTest.java
@@ -2366,7 +2366,6 @@ public void testDisablePropSpecWith64OrMoreFieldsAndRaiseWarning() {
}
@Test(timeout = 5000)
- @Ignore("disabled during phreak work")
public void testTypeDeclarationInitializationForPropertyReactive() {
// JBRULES-3686
String rule = "package org.drools.compiler.integrationtests\n" +
View
122 drools-compiler/src/test/java/org/drools/compiler/integrationtests/SegmentCreationTest.java
@@ -11,17 +11,8 @@
import org.drools.core.common.InternalRuleBase;
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.impl.StatefulKnowledgeSessionImpl;
-import org.drools.core.reteoo.BetaMemory;
-import org.drools.core.reteoo.InitialFactImpl;
-import org.drools.core.reteoo.JoinNode;
-import org.drools.core.reteoo.LeftInputAdapterNode;
-import org.drools.core.reteoo.RightInputAdapterNode;
-import org.drools.core.reteoo.RuleTerminalNode;
-import org.drools.core.reteoo.SegmentMemory;
+import org.drools.core.reteoo.*;
import org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory;
-import org.drools.core.reteoo.NotNode;
-import org.drools.core.reteoo.ObjectTypeNode;
-import org.drools.core.reteoo.ReteooWorkingMemoryInterface;
import org.junit.Test;
import org.kie.internal.KnowledgeBase;
import org.kie.internal.KieBaseConfiguration;
@@ -32,6 +23,8 @@
import org.kie.internal.io.ResourceFactory;
import org.kie.api.io.ResourceType;
+import org.kie.api.runtime.rule.FactHandle;
+
public class SegmentCreationTest {
@Test
@@ -333,7 +326,113 @@ public void tesShareInSubnetwork() throws Exception {
SegmentMemory notSmem = bSmem.getNext();
assertEquals( notNode, notSmem.getRootNode() );
assertEquals( rtn3, notSmem.getTipNode() );
- }
+ }
+
+ @Test
+ public void testBranchCESingleSegment() throws Exception {
+ KnowledgeBase kbase = buildKnowledgeBase( " $a : A() \n" +
+ " if ( $a != null ) do[t1] \n" +
+ " B() \n" );
+
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class );
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getSinkPropagator().getSinks()[0];
+
+ ConditionalBranchNode cen1Node = ( ConditionalBranchNode ) liaNode.getSinkPropagator().getSinks()[0];
+ JoinNode bNode = ( JoinNode ) cen1Node.getSinkPropagator().getSinks()[0];
+
+ RuleTerminalNode rtn1 = ( RuleTerminalNode ) bNode.getSinkPropagator().getSinks()[0];
+
+ FactHandle bFh = wm.insert( new LinkingTest.B() );
+ LiaNodeMemory liaMem = ( LiaNodeMemory ) wm.getNodeMemory( liaNode );
+ SegmentMemory smem = liaMem.getSegmentMemory();
+ assertEquals( 1, smem.getAllLinkedMaskTest() );
+ assertEquals( 4, smem.getLinkedNodeMask() ); // B links, but it will not trigger mask
+ assertFalse( smem.isSegmentLinked() );
+
+ PathMemory pmem = ( PathMemory ) wm.getNodeMemory(rtn1);
+ assertEquals( 1, pmem.getAllLinkedMaskTest() );
+ assertEquals( 0, pmem.getLinkedSegmentMask() );
+ assertFalse( pmem.isRuleLinked() );
+
+ wm.insert( new LinkingTest.A() );
+ assertEquals( 5, smem.getLinkedNodeMask() ); // A links in segment
+ assertTrue( smem.isSegmentLinked() );
+
+ assertEquals( 1, pmem.getLinkedSegmentMask() );
+ assertTrue( pmem.isRuleLinked() );
+
+ wm.delete(bFh); // retract B does not unlink the rule
+ assertEquals( 1, pmem.getLinkedSegmentMask() );
+ assertTrue( pmem.isRuleLinked() );
+ }
+
+ @Test
+ public void testBranchCEMultipleSegments() throws Exception {
+ KnowledgeBase kbase = buildKnowledgeBase( " $a : A() \n", // r1
+ " $a : A() \n" +
+ " if ( $a != null ) do[t1] \n" +
+ " B() \n", // r2
+ " $a : A() \n"+
+ " if ( $a != null ) do[t1] \n" +
+ " B() \n" +
+ " C() \n" // r3
+ );
+
+ ReteooWorkingMemoryInterface wm = ((StatefulKnowledgeSessionImpl)kbase.newStatefulKnowledgeSession()).session;
+
+ ObjectTypeNode aotn = getObjectTypeNode(kbase, LinkingTest.A.class );
+
+ LeftInputAdapterNode liaNode = (LeftInputAdapterNode) aotn.getSinkPropagator().getSinks()[0];
+
+ ConditionalBranchNode cen1Node = ( ConditionalBranchNode ) liaNode.getSinkPropagator().getSinks()[1];
+ JoinNode bNode = ( JoinNode ) cen1Node.getSinkPropagator().getSinks()[0];
+ RuleTerminalNode rtn2 = ( RuleTerminalNode ) bNode.getSinkPropagator().getSinks()[0];
+
+ JoinNode cNode = ( JoinNode ) bNode.getSinkPropagator().getSinks()[1];
+ RuleTerminalNode rtn3 = ( RuleTerminalNode ) cNode.getSinkPropagator().getSinks()[0];
+
+ FactHandle bFh = wm.insert( new LinkingTest.B() );
+ FactHandle cFh = wm.insert( new LinkingTest.C() );
+
+ BetaMemory bNodeBm = ( BetaMemory ) wm.getNodeMemory( bNode );
+ SegmentMemory bNodeSmem = bNodeBm.getSegmentMemory();
+ assertEquals( 0, bNodeSmem.getAllLinkedMaskTest() ); // no beta nodes before branch CE, so never unlinks
+ assertEquals( 2, bNodeSmem.getLinkedNodeMask() );
+
+ PathMemory pmemr2 = ( PathMemory ) wm.getNodeMemory(rtn2);
+ assertEquals( 1, pmemr2.getAllLinkedMaskTest() );
+ assertEquals( 2, pmemr2.getLinkedSegmentMask() );
+ assertEquals( 3, pmemr2.getSegmentMemories().length );
+ assertFalse( pmemr2.isRuleLinked() );
+
+ PathMemory pmemr3 = ( PathMemory ) wm.getNodeMemory(rtn3);
+ assertEquals( 1, pmemr3.getAllLinkedMaskTest() ); // notice only the first segment links
+ assertEquals( 3, pmemr3.getSegmentMemories().length );
+ assertFalse( pmemr3.isRuleLinked() );
+
+ BetaMemory cNodeBm = ( BetaMemory ) wm.getNodeMemory( cNode );
+ SegmentMemory cNodeSmem = cNodeBm.getSegmentMemory();
+
+ assertEquals( 1, cNodeSmem.getAllLinkedMaskTest() );
+ assertEquals( 1, cNodeSmem.getLinkedNodeMask() );
+
+ wm.insert( new LinkingTest.A() );
+
+ assertTrue( pmemr2.isRuleLinked() );
+ assertTrue( pmemr3.isRuleLinked() );
+
+ wm.delete(bFh); // retract B does not unlink the rule
+ wm.delete(cFh); // retract C does not unlink the rule
+
+ assertEquals( 3, pmemr2.getLinkedSegmentMask() ); // b segment never unlinks, as it has no impact on path unlinking anyway
+ assertTrue( pmemr2.isRuleLinked() );
+
+ assertEquals( 3, pmemr3.getLinkedSegmentMask() ); // b segment never unlinks, as it has no impact on path unlinking anyway
+ assertTrue( pmemr3.isRuleLinked() );
+ }
private KnowledgeBase buildKnowledgeBase(String... rules) {
String str = "";
@@ -348,6 +447,7 @@ private KnowledgeBase buildKnowledgeBase(String... rules) {
str += "rule rule" + (i++) +" when \n";
str += lhs;
str += "then \n";
+ str += "then[t1] \n";
str += "end \n";
}
View
12 drools-compiler/src/test/java/org/drools/compiler/integrationtests/SerializationHelper.java
@@ -9,6 +9,9 @@
import org.drools.core.RuleBase;
import org.drools.core.SessionConfiguration;
import org.drools.core.StatefulSession;
+import org.drools.core.impl.KnowledgeBaseImpl;
+import org.drools.core.impl.StatefulKnowledgeSessionImpl;
+import org.drools.core.reteoo.ReteooRuleBase;
import org.drools.core.util.DroolsStreamUtils;
import org.drools.core.marshalling.impl.ProtobufMarshaller;
import org.drools.core.reteoo.ReteooStatefulSession;
@@ -122,7 +125,10 @@ public static StatefulSession getSerialisedStatefulSession(StatefulSession sessi
public static StatefulKnowledgeSession getSerialisedStatefulKnowledgeSession(StatefulKnowledgeSession ksession,
boolean dispose) throws Exception {
- //if ( true ) return ksession;
+ if ( ((ReteooRuleBase)((KnowledgeBaseImpl) (ksession.getKieBase())).getRuleBase()).getConfiguration().isPhreakEnabled() ) {
+ return ksession;
+ }
+
return getSerialisedStatefulKnowledgeSession( ksession,
dispose,
true );
@@ -133,7 +139,9 @@ public static StatefulKnowledgeSession getSerialisedStatefulKnowledgeSession(Sta
public static StatefulKnowledgeSession getSerialisedStatefulKnowledgeSession(StatefulKnowledgeSession ksession,
boolean dispose,
boolean testRoundTrip ) throws Exception {
- //if ( true ) return ksession;
+ if ( ((ReteooRuleBase)((KnowledgeBaseImpl) (ksession.getKieBase())).getRuleBase()).getConfiguration().isPhreakEnabled() ) {
+ return ksession;
+ }
ProtobufMarshaller marshaller = (ProtobufMarshaller) MarshallerFactory.newMarshaller( ksession.getKieBase(),
(ObjectMarshallingStrategy[])ksession.getEnvironment().get(EnvironmentName.OBJECT_MARSHALLING_STRATEGIES) );
View
11 drools-compiler/src/test/java/org/drools/compiler/integrationtests/TruthMaintenanceTest.java
@@ -901,6 +901,7 @@ public void testLogicalInsertions3() throws Exception {
}
@Test
+ @Ignore( "phreak" )
public void testLogicalInsertionsAccumulatorPattern() throws Exception {
// JBRULES-449
KnowledgeBase kbase = loadKnowledgeBase( "test_LogicalInsertionsAccumulatorPattern.drl" );
@@ -934,6 +935,8 @@ public void testLogicalInsertionsAccumulatorPattern() throws Exception {
h = getFactHandle( h, ksession );
ksession.retract( h );
+ ksession.fireAllRules();
+
ksession = SerializationHelper.getSerialisedStatefulKnowledgeSession(ksession,
true);
assertEquals( "There should be only 1 CheeseEqual in Working Memory, 1 stated (the justified should have been retracted). Check TruthMaintenanceSystem justifiedMap",
@@ -1100,7 +1103,7 @@ public void testTMSwithQueries() {
//System.err.println(reportWMObjects(kSession));
}
- @Test @Ignore
+ @Test @Ignore("Should work with phreak, but actually still has error")
public void testTMSWithLateUpdate() {
// This is not actually fixable, as noted here, JBRULES-3416
// facts must be updated, before changing other facts, as they act as HEAD in buckets.
@@ -1119,11 +1122,7 @@ public void testTMSWithLateUpdate() {
" insertLogical(new YoungestFather($h));\n" +
"end";
- KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
- kbuilder.add( ResourceFactory.newByteArrayResource(str.getBytes()),
- ResourceType.DRL );
- KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
- kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
+ KnowledgeBase kbase = loadKnowledgeBaseFromString( str );
StatefulKnowledgeSession kSession = createKnowledgeSession(kbase);
Father abraham = new Father("abraham");
View
5 drools-compiler/src/test/java/org/drools/compiler/lang/RuleParserTest.java
@@ -68,7 +68,6 @@
import static org.drools.compiler.compiler.DRLFactory.buildParser;
-@Ignore("problem during phreak work")
public class RuleParserTest extends TestCase {
@@ -2903,7 +2902,7 @@ public void testSemicolon() throws Exception {
assertFalse( parser.getErrors().toString(),
parser.hasErrors() );
- assertEquals( "org.drools",
+ assertEquals( "org.drools.compiler",
pkg.getName() );
assertEquals( 1,
pkg.getGlobals().size() );
@@ -2928,7 +2927,7 @@ public void testEval() throws Exception {
final PackageDescr pkg = (PackageDescr) parseResource( "compilationUnit",
"eval_parsing.drl" );
- assertEquals( "org.drools",
+ assertEquals( "org.drools.compiler",
pkg.getName() );
assertEquals( 1,
pkg.getRules().size() );
View
7 ...-compiler/src/test/resources/org/drools/compiler/factmodel/traits/testTraitLegacyCore.drl
@@ -14,8 +14,6 @@ import org.drools.compiler.factmodel.traits.IRole;
global java.util.List list;
-
-
declare trait IRole
end
@@ -36,11 +34,6 @@ declare trait Person
age : int
end
-
-
-
-
-
rule "Init"
when
then
View
4 ...piler/src/test/resources/org/drools/compiler/integrationtests/test_FromArrayIteration.drl
@@ -1,7 +1,7 @@
package org.drools.compiler.test;
-import org.drools.DomainObject
-import org.drools.DomainObjectHolder;
+import org.drools.compiler.DomainObject
+import org.drools.compiler.DomainObjectHolder;
global java.util.List list
View
2 ...-compiler/src/test/resources/org/drools/compiler/integrationtests/test_FromWithParams.drl
@@ -1,6 +1,6 @@
package org.drools.compiler.test;
-import org.drools.FromTestClass;
+import org.drools.compiler.FromTestClass;
import org.drools.compiler.Person
global FromTestClass testObject;
View
6 drools-compiler/src/test/resources/org/drools/compiler/integrationtests/varargs2.drl
@@ -10,8 +10,7 @@ then
System.out.println( $ms.toString() );
end
-rule "addSet"
-no-loop true
+rule "addSet" no-loop true
when
$ms: MySet()
then
@@ -19,8 +18,7 @@ then
insert( new MySet( "x", "y" ) );
end
-rule "xySet"
-no-loop true
+rule "xySet" no-loop true salience 1000
when
$ms: MySet()
then
View
3 drools-core/src/main/java/org/drools/core/beliefsystem/jtms/JTMSBeliefSystem.java
@@ -106,7 +106,8 @@ private void insertBelief(LogicalDependency node,
node.getObject(),
node.getJustifier().getRule(),
node.getJustifier(),
- typeConf );
+ typeConf,
+ null );
}
}
View
3 drools-core/src/main/java/org/drools/core/beliefsystem/simple/SimpleBeliefSystem.java
@@ -50,7 +50,8 @@ public void insert(LogicalDependency node,
handle.getObject(),
node.getJustifier().getRule(),
node.getJustifier(),
- typeConf );
+ typeConf,
+ null );
}
}
View
3 drools-core/src/main/java/org/drools/core/common/AbstractWorkingMemory.java
@@ -839,7 +839,8 @@ public void insert(final InternalFactHandle handle,
object,
rule,
activation,
- typeConf );
+ typeConf,
+ null );
}
public void retract(final org.kie.api.runtime.rule.FactHandle handle) throws FactException {
View
8 drools-core/src/main/java/org/drools/core/common/BinaryHeapQueueAgendaGroup.java
@@ -18,6 +18,7 @@
import java.util.PriorityQueue;
+import org.drools.core.conflict.PhreakConflictResolver;
import org.drools.core.util.BinaryHeapQueue;
import org.drools.core.util.Queueable;
import org.drools.core.spi.Activation;
@@ -62,7 +63,12 @@ public BinaryHeapQueueAgendaGroup() {
public BinaryHeapQueueAgendaGroup(final String name,
final InternalRuleBase ruleBase) {
this.name = name;
- this.queue = new BinaryHeapQueue( ruleBase.getConfiguration().getConflictResolver() );
+ if ( ruleBase.getConfiguration().isPhreakEnabled() ) {
+ this.queue = new BinaryHeapQueue( new PhreakConflictResolver());
+ } else {
+ this.queue = new BinaryHeapQueue( ruleBase.getConfiguration().getConflictResolver() );
+ }
+
this.clearedForRecency = -1;
}
View
45 drools-core/src/main/java/org/drools/core/common/NamedEntryPoint.java
@@ -164,24 +164,26 @@ protected FactHandle insert(final Object object,
InternalFactHandle handle = null;
+ final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
+ PropagationContext.INSERTION,
+ rule,
+ (activation == null) ? null : activation.getTuple(),
+ handle,
+ entryPoint );
+
if ( this.wm.isSequential() ) {
handle = createHandle( object,
typeConf );
+ propagationContext.setFactHandle(handle);
insert( handle,
object,
rule,
activation,
- typeConf );
+ typeConf,
+ propagationContext );
return handle;
}
-
- final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
- PropagationContext.INSERTION,
- rule,
- (activation == null) ? null : activation.getTuple(),
- handle,
- entryPoint );
-
+
try {
this.lock.lock();
@@ -193,6 +195,7 @@ protected FactHandle insert(final Object object,
TruthMaintenanceSystem tms = getTruthMaintenanceSystem();
if ( handle != null ) {
+ propagationContext.setFactHandle(handle);
insertWhenHandleExists( object, tmsValue, logical, rule, activation, typeConf, handle, tms, propagationContext );
return handle;
}
@@ -253,7 +256,7 @@ protected FactHandle insert(final Object object,
handle = createHandle( object,
typeConf ); // we know the handle is null
handle.setEqualityKey( key );
- key.addFactHandle( handle );
+ key.addFactHandle( handle );
}
key.setStatus( EqualityKey.STATED ); // KEY is always stated
}
@@ -265,6 +268,7 @@ protected FactHandle insert(final Object object,
handle = createHandle( object,
typeConf );
}
+ propagationContext.setFactHandle(handle);
// if the dynamic parameter is true or if the user declared the fact type with the meta tag:
// @propertyChangeSupport
@@ -276,7 +280,8 @@ protected FactHandle insert(final Object object,
object,
rule,
activation,
- typeConf );
+ typeConf,
+ propagationContext );
} finally {
this.ruleBase.readUnlock();
@@ -328,7 +333,8 @@ public void insert(final InternalFactHandle handle,
final Object object,
final Rule rule,
final Activation activation,
- ObjectTypeConf typeConf) {
+ ObjectTypeConf typeConf,
+ PropagationContext pctx) {
this.ruleBase.executeQueuedActions();
this.wm.executeQueuedActions();
@@ -337,12 +343,15 @@ public void insert(final InternalFactHandle handle,
// release resources so that they can be GC'ed
activation.getPropagationContext().releaseResources();
}
- final PropagationContext propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
- PropagationContext.INSERTION,
- rule,
- (activation == null) ? null : activation.getTuple(),
- handle,
- entryPoint );
+ PropagationContext propagationContext = pctx;
+ if ( pctx == null ) {
+ propagationContext = new PropagationContextImpl( this.wm.getNextPropagationIdCounter(),
+ PropagationContext.INSERTION,
+ rule,
+ (activation == null) ? null : activation.getTuple(),
+ handle,
+ entryPoint );
+ }
this.entryPointNode.assertObject( handle,
propagationContext,
View
2 drools-core/src/main/java/org/drools/core/common/PropagationContextImpl.java
@@ -224,7 +224,7 @@ public int getType() {
public void releaseResources() {
this.leftTuple = null;
- this.rule = null;
+ //this.rule = null;
}
/**
View
9 drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java
@@ -542,16 +542,19 @@ private void doRiaNode2(InternalWorkingMemory wm,
for (LeftTuple leftTuple = srcTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
- InternalFactHandle handle = riaNode.createFactHandle(leftTuple, leftTuple.getPropagationContext(), wm);
+ PropagationContext pctx = leftTuple.getPropagationContext();
+ InternalFactHandle handle = riaNode.createFactHandle(leftTuple, pctx, wm);
RightTuple rightTuple = new RightTuple(handle, betaNode);
leftTuple.setObject(rightTuple);
+ rightTuple.setPropagationContext(pctx);
bm.getStagedRightTuples().addInsert(rightTuple);
if (bns != null) {
// Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref
for (int i = 0; i < length; i++) {
rightTuple = new RightTuple(handle, bns[i]);
+ rightTuple.setPropagationContext(pctx);
bms[i].getStagedRightTuples().addInsert(rightTuple);
}
}
@@ -3605,7 +3608,7 @@ public void doLeftInserts(FromNode fromNode,
propagationContext,
fm.providerContext); it.hasNext(); ) {
final Object object = it.next();
- if (!resultClass.isAssignableFrom(object.getClass())) {
+ if ( (object == null) || !resultClass.isAssignableFrom( object.getClass() ) ) {
continue; // skip anything if it not assignable
}
@@ -3675,7 +3678,7 @@ public void doLeftUpdates(FromNode fromNode,
propagationContext,
fm.providerContext); it.hasNext(); ) {
final Object object = it.next();
- if (!resultClass.isAssignableFrom(object.getClass())) {
+ if ( (object == null) || !resultClass.isAssignableFrom( object.getClass() ) ) {
continue; // skip anything if it not assignable
}
View
23 drools-core/src/main/java/org/drools/core/phreak/SegmentUtilities.java
@@ -61,6 +61,7 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
// allLinkedTestMask is the resulting mask used to test if all nodes are linked in
long nodePosMask = 1;
long allLinkedTestMask = 0;
+ boolean updateNodeBit = true; // nodes after a branch CE can notify, but they cannot impact linking
while ( true ) {
if ( NodeTypeEnums.isBetaNode( tupleSource ) ) {
@@ -96,12 +97,13 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
RiaNodeMemory riaMem = ( RiaNodeMemory ) wm.getNodeMemory( (MemoryFactory) riaNode );
bm.setRiaRuleMemory(riaMem.getRiaPathMemory());
- if ( riaMem.getRiaPathMemory().getAllLinkedMaskTest() > 0 ) {
+ if ( updateNodeBit && riaMem.getRiaPathMemory().getAllLinkedMaskTest() > 0 ) {
// only ria's with reactive subnetworks can be disabled and thus need checking
allLinkedTestMask = allLinkedTestMask | nodePosMask;
}
- } else if ( ( !(NodeTypeEnums.NotNode == tupleSource.getType() && !((NotNode)tupleSource).isEmptyBetaConstraints()) &&
- NodeTypeEnums.AccumulateNode != tupleSource.getType()) ) {
+ } else if ( updateNodeBit &&
+ ( !(NodeTypeEnums.NotNode == tupleSource.getType() && !((NotNode)tupleSource).isEmptyBetaConstraints()) &&
+ NodeTypeEnums.AccumulateNode != tupleSource.getType()) ) {
// non empty not nodes and accumulates can never be disabled and thus don't need checking
allLinkedTestMask = allLinkedTestMask | nodePosMask;
@@ -111,20 +113,18 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
// not nodes start up linked in
smem.linkNodeWithoutRuleNotify(bm.getNodePosMaskBit());
}
- nodePosMask = nodePosMask << 1;
} else if ( tupleSource.getType() == NodeTypeEnums.LeftInputAdapterNode ) {
LiaNodeMemory liaMemory = ( LiaNodeMemory ) smem.createNodeMemory( ( LeftInputAdapterNode ) tupleSource, wm );
liaMemory.setSegmentMemory( smem );
liaMemory.setNodePosMaskBit( nodePosMask );
allLinkedTestMask = allLinkedTestMask | nodePosMask;
-
- nodePosMask = nodePosMask << 1;
} else if ( tupleSource.getType() == NodeTypeEnums.EvalConditionNode ) {
- EvalMemory evalMemory = ( EvalMemory ) smem.createNodeMemory( ( EvalConditionNode ) tupleSource, wm );
- evalMemory.setSegmentMemory( smem );
+ EvalMemory evalMem = ( EvalMemory ) smem.createNodeMemory( ( EvalConditionNode ) tupleSource, wm );
+ evalMem.setSegmentMemory( smem );
} else if ( tupleSource.getType() == NodeTypeEnums.ConditionalBranchNode ) {
- ConditionalBranchMemory evalMemory = ( ConditionalBranchMemory ) smem.createNodeMemory( ( ConditionalBranchNode ) tupleSource, wm );
- evalMemory.setSegmentMemory( smem );
+ ConditionalBranchMemory branchMem = ( ConditionalBranchMemory ) smem.createNodeMemory( ( ConditionalBranchNode ) tupleSource, wm );
+ branchMem.setSegmentMemory( smem );
+ updateNodeBit = false; // nodes after a branch CE can notify, but they cannot impact linking
} else if ( tupleSource.getType() == NodeTypeEnums.FromNode ) {
FromMemory fromMemory = ( FromMemory ) smem.createNodeMemory( ( FromNode ) tupleSource, wm );
fromMemory.getBetaMemory().setSegmentMemory( smem );
@@ -139,8 +139,9 @@ public static SegmentMemory createSegmentMemory(LeftTupleSource tupleSource ,
}
QueryElementNodeMemory queryNodeMem = ( QueryElementNodeMemory ) smem.createNodeMemory( queryNode, wm );
queryNodeMem.setQuerySegmentMemory( querySmem );
- queryNodeMem.setSegmentMemory( smem );
+ queryNodeMem.setSegmentMemory( smem );
}
+ nodePosMask = nodePosMask << 1;
if ( tupleSource.getSinkPropagator().size() == 1 ) {
LeftTupleSinkNode sink = (LeftTupleSinkNode) tupleSource.getSinkPropagator().getFirstLeftTupleSink() ;
View
38 drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java
@@ -131,28 +131,39 @@ public static void initPathMemory(PathMemory pmem, LeftTupleSource tupleSource,
// it's shared, RTN is in it's own segment, so increase segmentCount
counter++;
}
- boolean updateBitInNewSegment = true; // avoids more than one isBetaNode check per segment
- boolean updateAllLinkedTest = true;
+
+ ConditionalBranchNode cen = getConditionalBranchNode(tupleSource); // segments after a branch CE can notify, but they cannot impact linking
+ // @TODO optimization would be to split path's into two, to avoid wasted rule evaluation for segments after the first branch CE
+
+ boolean updateBitInNewSegment = true; // Avoids more than one isBetaNode check per segment
+ boolean updateAllLinkedTest = ( cen == null ) ? true : false; // if there is a CEN, do not set bit until it's reached
+ boolean subnetworkBoundaryCrossed = false;
while ( tupleSource.getType() != NodeTypeEnums.LeftInputAdapterNode ) {
+ if ( !subnetworkBoundaryCrossed && tupleSource.getType() == NodeTypeEnums.ConditionalBranchNode ) {
+ // start recording now we are after the BranchCE, but only if we are not outside the target
+ // subnetwork
+ updateAllLinkedTest = true;
+ }
+
if ( updateAllLinkedTest && updateBitInNewSegment && NodeTypeEnums.isBetaNode( tupleSource )) {
updateBitInNewSegment = false;
BetaNode bn = ( BetaNode) tupleSource;
if ( bn.isRightInputIsRiaNode() ) {
// only ria's without reactive subnetworks can be disabled and thus need checking
- // The getNodeMemory will call this method recursive for sub networks it reaches
+ // The getNodeMemory will7 call this method recursive for sub networks it reaches
RiaNodeMemory rnmem = ( RiaNodeMemory ) wm.getNodeMemory((MemoryFactory) bn.getRightInput());
if ( rnmem.getRiaPathMemory().getAllLinkedMaskTest() != 0 ) {
allLinkedTestMask = allLinkedTestMask | 1;
}
} else if ( ( !(NodeTypeEnums.NotNode == bn.getType() && !((NotNode)bn).isEmptyBetaConstraints()) &&
- NodeTypeEnums.AccumulateNode != bn.getType()) ) {
+ NodeTypeEnums.AccumulateNode != bn.getType()) ) {
// non empty not nodes and accumulates can never be disabled and thus don't need checking
allLinkedTestMask = allLinkedTestMask | 1;
}
}
if ( !SegmentUtilities.parentInSameSegment( tupleSource ) ) {
- updateBitInNewSegment = true;
+ updateBitInNewSegment = true; // allow bit to be set for segment
allLinkedTestMask = allLinkedTestMask << 1;
counter++;
}
@@ -160,18 +171,31 @@ public static void initPathMemory(PathMemory pmem, LeftTupleSource tupleSource,
tupleSource = tupleSource.getLeftTupleSource();
if ( tupleSource == startTupleSource ) {
// stop tracking if we move outside of a subnetwork boundary (if one is set)
+ subnetworkBoundaryCrossed = true;
updateAllLinkedTest = false;
}
}
- if ( updateAllLinkedTest && tupleSource.getSinkPropagator().size() > 1 ) {
- // tupleSource == LeftInputAdapterNode
+ if ( !subnetworkBoundaryCrossed ) {
allLinkedTestMask = allLinkedTestMask | 1;
}
+
pmem.setAllLinkedMaskTest( allLinkedTestMask );
pmem.setSegmentMemories( new SegmentMemory[counter + 1] ); // +1 as arras are zero based.
}
+ private static ConditionalBranchNode getConditionalBranchNode(LeftTupleSource tupleSource) {
+ ConditionalBranchNode cen = null;
+ while ( tupleSource.getType() != NodeTypeEnums.LeftInputAdapterNode ) {
+ // find the first ConditionalBranch, if one exists
+ if ( tupleSource.getType() == NodeTypeEnums.ConditionalBranchNode ) {
+ cen = ( ConditionalBranchNode ) tupleSource;
+ }
+ tupleSource = tupleSource.getLeftTupleSource();
+ }
+ return cen;
+ }
+
public LeftTuple createPeer(LeftTuple original) {
RuleTerminalNodeLeftTuple peer = new RuleTerminalNodeLeftTuple();
peer.initPeer( (BaseLeftTuple) original, this );
View
7 drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java
@@ -632,7 +632,7 @@ public void modifyObject(InternalFactHandle factHandle,
modifyPreviousTuples.removeRightTuple();
// we skipped this node, due to alpha hashing, so retract now
- //rightTuple.setPropagationContext( context ); pctx is no longer updated, as it conflcits with no-loop, leaving commented code for future reference
+ rightTuple.setPropagationContext( context );
if ( isUnlinkingEnabled() ) {
BetaMemory bm = getBetaMemory( (BetaNode) rightTuple.getRightTupleSink(), wm );
doDeleteRightTuple( rightTuple, wm, bm );
@@ -647,7 +647,10 @@ public void modifyObject(InternalFactHandle factHandle,
if ( rightTuple != null && rightTuple.getRightTupleSink().getRightInputOtnId().equals(getRightInputOtnId()) ) {
modifyPreviousTuples.removeRightTuple();
rightTuple.reAdd();
- //rightTuple.setPropagationContext( context ); pctx is no longer updated, as it conflcits with no-loop, leaving commented code for future reference
+ if ( rightTuple.getStagedType() != LeftTuple.INSERT ) {
+ // things staged as inserts, are left as inserts and use the pctx associated from the time of insertion
+ rightTuple.setPropagationContext( context );
+ }
if ( intersect( context.getModificationMask(), rightInferredMask ) ) {
// RightTuple previously existed, so continue as modify
if ( isUnlinkingEnabled() ) {
View
12 drools-core/src/main/java/org/drools/core/reteoo/ConditionalBranchNode.java
@@ -256,7 +256,7 @@ public boolean equals(final Object object) {
return true;
}
- if ( object == null || object.getClass() != EvalConditionNode.class ) {
+ if ( object == null || object.getClass() != ConditionalBranchNode.class ) {
return false;
}
@@ -268,10 +268,14 @@ public boolean equals(final Object object) {
public Memory createMemory(final RuleBaseConfiguration config, InternalWorkingMemory wm) {
return new ConditionalBranchMemory( branchEvaluator.createContext() );
}
-
+
+ @Override
public LeftTuple createPeer(LeftTuple original) {
- return null;
- }
+ EvalNodeLeftTuple peer = new EvalNodeLeftTuple();
+ peer.initPeer( (BaseLeftTuple) original, this );
+ original.setPeer( peer );
+ return peer;
+ }
public void updateSink(final LeftTupleSink sink,
final PropagationContext context,
View
18 drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java
@@ -267,7 +267,7 @@ public static void doInsertObject(final InternalFactHandle factHandle,
linkOrNotify = false; // we don't need to do any more notifcations
}
- LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink() ;
+ LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink();
LeftTuple leftTuple = sink.createLeftTuple( factHandle, sink, useLeftMemory );
leftTuple.setPropagationContext( context );
long mask = sink.getLeftInferredMask();
@@ -288,8 +288,7 @@ public static void doInsertObject(final InternalFactHandle factHandle,
for ( sm = sm.getNext(); sm != null; sm = sm.getNext() ) {
sink = sm.getSinkFactory();
- leftTuple = sink.createPeer( leftTuple );
- leftTuple.setPropagationContext( context );
+ leftTuple = sink.createPeer( leftTuple ); // pctx is set during peer cloning
mask = ((LeftTupleSink)sm.getRootNode()).getLeftInferredMask();
if ( context.getType() == PropagationContext.INSERTION ||
mask == Long.MAX_VALUE ||
@@ -391,8 +390,12 @@ public static void doUpdateObject(LeftTuple leftTuple,
LeftTupleSets leftTuples = sm.getStagedLeftTuples();
- LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink() ;
- //leftTuple.setPropagationContext( context ); pctx is no longer updated, as it conflcits with no-loop, leaving commented code for future reference
+ LeftTupleSink sink = liaNode.getSinkPropagator().getFirstLeftTupleSink() ;
+
+ if ( leftTuple.getStagedType() != LeftTuple.INSERT ) {
+ // things staged as inserts, are left as inserts and use the pctx associated from the time of insertion
+ leftTuple.setPropagationContext( context );
+ }
if ( leftTuple.getStagedType() == LeftTuple.NONE ) {
// if LeftTuple is already staged, leave it there
long mask = sink.getLeftInferredMask();
@@ -417,7 +420,10 @@ public static void doUpdateObject(LeftTuple leftTuple,
leftTuple = leftTuple.getPeer();
leftTuples = sm.getStagedLeftTuples();
- //leftTuple.setPropagationContext( context ); pctx is no longer updated, as it conflcits with no-loop, leaving commented code for future reference
+ if ( leftTuple.getStagedType() != LeftTuple.INSERT ) {
+ // things staged as inserts, are left as inserts and use the pctx associated from the time of insertion
+ leftTuple.setPropagationContext( context );
+ }
if ( leftTuple.getStagedType() == LeftTuple.NONE ) {
// if LeftTuple is already staged, leave it there
long mask = ((LeftTupleSink) sm.getRootNode()).getLeftInferredMask();
View
4 drools-core/src/main/java/org/drools/core/reteoo/RiaPathMemory.java
@@ -58,9 +58,7 @@ public void findAndAddTN( LeftTupleSink ltsink, List<String> terminalNodeNames)
if ( NodeTypeEnums.isTerminalNode(ltsink)) {
terminalNodeNames.add( ((TerminalNode)ltsink).getRule().getName() );
} else if ( ltsink.getType() == NodeTypeEnums.RightInputAdaterNode ) {
- for ( Object childSink : ((RightInputAdapterNode)ltsink).getSinkPropagator().getSinks() ) {
- findAndAddTN( ( LeftTupleSink ) childSink, terminalNodeNames);
- }
+ // Do not traverse here, as we'll the other side of the target node anyway.
} else {
for ( LeftTupleSink childLtSink : ((LeftTupleSource)ltsink).getSinkPropagator().getSinks() ) {
findAndAddTN(childLtSink, terminalNodeNames);
View
7 drools-core/src/main/java/org/drools/core/reteoo/SegmentMemory.java
@@ -137,14 +137,17 @@ public void unlinkNode(long mask,
if (log.isTraceEnabled()) {
log.trace("UnlinkNode notify=true nmask={} smask={} spos={} rules={}", mask, linkedNodeMask, pos, getRuleNames());
}
- if (isSegmentLinked()) {
+
+ // some node unlinking does not unlink the segment, such as nodes after a Branch CE
+ boolean linked = isSegmentLinked();
+ linkedNodeMask = linkedNodeMask ^ mask;
+ if (linked && !isSegmentLinked()) {
for (int i = 0, length = pathMemories.size(); i < length; i++) {
// do not use foreach, don't want Iterator object creation
pathMemories.get(i).unlinkedSegment(segmentPosMaskBit,
wm);
}
}
- linkedNodeMask = linkedNodeMask ^ mask;
}
public void unlinkNodeWithoutRuleNotify(long mask) {

0 comments on commit 48c5c71

Please sign in to comment.
Something went wrong with that request. Please try again.