Permalink
Browse files

[DROOLS-1024] rule engine parallelization (#983)

  • Loading branch information...
1 parent 76ea146 commit 63ea870c89591dfeae1276f582d825670fe7ec3a @mariofusco mariofusco committed on GitHub Oct 26, 2016
Showing with 4,961 additions and 2,294 deletions.
  1. +1 −0 drools-compiler/src/main/java/org/drools/compiler/rule/builder/RuleBuilder.java
  2. +12 −7 ...ls-compiler/src/main/java/org/drools/compiler/rule/builder/dialect/java/KnowledgeHelperFixer.java
  3. +26 −34 drools-compiler/src/test/java/org/drools/compiler/conf/KnowledgeBaseConfigurationTest.java
  4. +0 −2 drools-compiler/src/test/java/org/drools/compiler/factmodel/traits/TraitTest.java
  5. +149 −0 drools-compiler/src/test/java/org/drools/compiler/integrationtests/CompositeAgendaTest.java
  6. +8 −1 drools-compiler/src/test/java/org/drools/compiler/integrationtests/DeclarativeAgendaTest.java
  7. +3 −3 drools-compiler/src/test/java/org/drools/compiler/integrationtests/ExecutionFlowControlTest.java
  8. +5 −1 drools-compiler/src/test/java/org/drools/compiler/integrationtests/LinkingTest.java
  9. +169 −0 drools-compiler/src/test/java/org/drools/compiler/integrationtests/NodesPartitioningTest.java
  10. +689 −0 drools-compiler/src/test/java/org/drools/compiler/integrationtests/ParallelEvaluationTest.java
  11. +75 −0 drools-compiler/src/test/java/org/drools/compiler/integrationtests/facts/A.java
  12. +0 −3 ...src/test/java/org/drools/compiler/integrationtests/incrementalcompilation/AddRemoveRulesTest.java
  13. +1 −1 ...ler/src/test/java/org/drools/compiler/integrationtests/marshalling/FactHandleMarshallingTest.java
  14. +0 −2 drools-compiler/src/test/java/org/drools/compiler/phreak/RemoveRuleTest.java
  15. +0 −4 drools-compiler/src/test/java/org/drools/compiler/phreak/RightBuilder.java
  16. +0 −4 drools-compiler/src/test/java/org/drools/compiler/reteoo/MockLeftTupleSink.java
  17. +2 −1 ...piler/src/test/java/org/drools/compiler/rule/builder/dialect/mvel/MVELConsequenceBuilderTest.java
  18. +4 −6 drools-core/src/main/java/org/drools/core/RuleBaseConfiguration.java
  19. +1 −1 drools-core/src/main/java/org/drools/core/audit/WorkingMemoryLogger.java
  20. +4 −12 drools-core/src/main/java/org/drools/core/base/DefaultKnowledgeHelper.java
  21. +14 −15 drools-core/src/main/java/org/drools/core/base/InternalViewChangedEventListener.java
  22. +2 −2 drools-core/src/main/java/org/drools/core/base/KnowledgeHelperFactory.java
  23. +6 −4 drools-core/src/main/java/org/drools/core/base/SequentialKnowledgeHelper.java
  24. +2 −10 drools-core/src/main/java/org/drools/core/base/TraitHelper.java
  25. +10 −32 drools-core/src/main/java/org/drools/core/base/WrappedStatefulKnowledgeSessionForRHS.java
  26. +11 −17 drools-core/src/main/java/org/drools/core/beliefsystem/jtms/JTMSBeliefSystem.java
  27. +5 −7 drools-core/src/main/java/org/drools/core/beliefsystem/simple/SimpleBeliefSystem.java
  28. +0 −6 drools-core/src/main/java/org/drools/core/common/ActivationsFilter.java
  29. +2 −2 drools-core/src/main/java/org/drools/core/common/AgendaFactory.java
  30. +4 −0 drools-core/src/main/java/org/drools/core/common/AgendaItemImpl.java
  31. +1 −1 drools-core/src/main/java/org/drools/core/common/BaseNode.java
  32. +632 −0 drools-core/src/main/java/org/drools/core/common/CompositeDefaultAgenda.java
  33. +372 −359 drools-core/src/main/java/org/drools/core/common/DefaultAgenda.java
  34. +6 −2 drools-core/src/main/java/org/drools/core/common/DefaultAgendaFactory.java
  35. +481 −237 drools-core/src/main/java/org/drools/core/common/DefaultFactHandle.java
  36. +32 −0 drools-core/src/main/java/org/drools/core/common/DisconnectedFactHandle.java
  37. +1 −1 drools-core/src/main/java/org/drools/core/common/DisconnectedWorkingMemoryEntryPoint.java
  38. +19 −6 drools-core/src/main/java/org/drools/core/common/EventFactHandle.java
  39. +13 −30 drools-core/src/main/java/org/drools/core/common/InternalAgenda.java
  40. +50 −12 drools-core/src/main/java/org/drools/core/common/InternalFactHandle.java
  41. +0 −15 drools-core/src/main/java/org/drools/core/common/InternalWorkingMemory.java
  42. +14 −13 drools-core/src/main/java/org/drools/core/common/InternalWorkingMemoryActions.java
  43. +6 −8 drools-core/src/main/java/org/drools/core/common/LeftTupleIterator.java
  44. +40 −21 drools-core/src/main/java/org/drools/core/common/NamedEntryPoint.java
  45. +49 −0 drools-core/src/main/java/org/drools/core/common/PartitionedDefaultAgenda.java
  46. +4 −6 drools-core/src/main/java/org/drools/core/common/PhreakActivationIterator.java
  47. +18 −43 drools-core/src/main/java/org/drools/core/common/PhreakPropagationContext.java
  48. +6 −6 drools-core/src/main/java/org/drools/core/common/PhreakPropagationContextFactory.java
  49. +5 −5 drools-core/src/main/java/org/drools/core/common/PropagationContextFactory.java
  50. +32 −0 drools-core/src/main/java/org/drools/core/common/QueryElementFactHandle.java
  51. +22 −26 drools-core/src/main/java/org/drools/core/common/RuleBasePartitionId.java
  52. +2 −2 drools-core/src/main/java/org/drools/core/common/TruthMaintenanceSystem.java
  53. +8 −8 drools-core/src/main/java/org/drools/core/common/WorkingMemoryAction.java
  54. +44 −0 drools-core/src/main/java/org/drools/core/concurrent/AbstractRuleEvaluator.java
  55. +130 −0 drools-core/src/main/java/org/drools/core/concurrent/ParallelRuleEvaluator.java
  56. +30 −0 drools-core/src/main/java/org/drools/core/concurrent/RuleEvaluator.java
  57. +49 −0 drools-core/src/main/java/org/drools/core/concurrent/SequentialRuleEvaluator.java
  58. +1 −1 drools-core/src/main/java/org/drools/core/definitions/rule/impl/RuleImpl.java
  59. +4 −6 drools-core/src/main/java/org/drools/core/event/rule/impl/RuleRuntimeEventImpl.java
  60. +1 −1 drools-core/src/main/java/org/drools/core/event/rule/impl/SerializableActivation.java
  61. +0 −85 drools-core/src/main/java/org/drools/core/event/rule/impl/SerializablePropagationContext.java
  62. +41 −53 drools-core/src/main/java/org/drools/core/impl/KnowledgeBaseImpl.java
  63. +84 −144 drools-core/src/main/java/org/drools/core/impl/StatefulKnowledgeSessionImpl.java
  64. +1 −1 drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufInputMarshaller.java
  65. +11 −10 drools-core/src/main/java/org/drools/core/marshalling/impl/ProtobufOutputMarshaller.java
  66. +14 −31 drools-core/src/main/java/org/drools/core/phreak/AddRemoveRule.java
  67. +20 −20 drools-core/src/main/java/org/drools/core/phreak/PhreakBranchNode.java
  68. +16 −16 drools-core/src/main/java/org/drools/core/phreak/PhreakQueryTerminalNode.java
  69. +27 −28 drools-core/src/main/java/org/drools/core/phreak/PhreakRuleTerminalNode.java
  70. +30 −27 drools-core/src/main/java/org/drools/core/phreak/PhreakTimerNode.java
  71. +144 −37 drools-core/src/main/java/org/drools/core/phreak/PropagationEntry.java
  72. +2 −0 drools-core/src/main/java/org/drools/core/phreak/PropagationList.java
  73. +1 −1 drools-core/src/main/java/org/drools/core/phreak/ReactiveObjectUtil.java
  74. +124 −17 drools-core/src/main/java/org/drools/core/phreak/RuleExecutor.java
  75. +63 −29 drools-core/src/main/java/org/drools/core/phreak/RuleNetworkEvaluator.java
  76. +13 −5 drools-core/src/main/java/org/drools/core/phreak/SynchronizedPropagationList.java
  77. +0 −61 drools-core/src/main/java/org/drools/core/reteoo/AbstractObjectSinkAdapter.java
  78. +5 −0 drools-core/src/main/java/org/drools/core/reteoo/AbstractTerminalNode.java
  79. +0 −5 drools-core/src/main/java/org/drools/core/reteoo/AlphaNode.java
  80. +0 −11 drools-core/src/main/java/org/drools/core/reteoo/BaseLeftTuple.java
  81. +8 −1 drools-core/src/main/java/org/drools/core/reteoo/BaseTuple.java
  82. +12 −4 drools-core/src/main/java/org/drools/core/reteoo/BetaNode.java
  83. +60 −66 drools-core/src/main/java/org/drools/core/reteoo/CompositeObjectSinkAdapter.java
  84. +263 −0 drools-core/src/main/java/org/drools/core/reteoo/CompositePartitionAwareObjectSinkAdapter.java
  85. +13 −16 drools-core/src/main/java/org/drools/core/reteoo/EmptyObjectSinkAdapter.java
  86. +52 −63 drools-core/src/main/java/org/drools/core/reteoo/EntryPointNode.java
  87. +0 −10 drools-core/src/main/java/org/drools/core/reteoo/EvalConditionNode.java
  88. +0 −4 drools-core/src/main/java/org/drools/core/reteoo/FromNode.java
  89. +12 −0 drools-core/src/main/java/org/drools/core/reteoo/LeftInputAdapterNode.java
  90. +0 −2 drools-core/src/main/java/org/drools/core/reteoo/LeftTuple.java
  91. +3 −0 drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSink.java
  92. +24 −1 drools-core/src/main/java/org/drools/core/reteoo/LeftTupleSource.java
  93. +22 −33 drools-core/src/main/java/org/drools/core/reteoo/ModifyPreviousTuples.java
  94. +7 −4 drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkNode.java
  95. +5 −1 drools-core/src/main/java/org/drools/core/reteoo/ObjectSinkPropagator.java
  96. +37 −27 drools-core/src/main/java/org/drools/core/reteoo/ObjectSource.java
  97. +67 −18 drools-core/src/main/java/org/drools/core/reteoo/ObjectTypeNode.java
  98. +33 −17 drools-core/src/main/java/org/drools/core/reteoo/PathMemory.java
  99. +2 −7 drools-core/src/main/java/org/drools/core/reteoo/PropagationQueuingNode.java
  100. +0 −4 drools-core/src/main/java/org/drools/core/reteoo/QueryElementNode.java
  101. +1 −5 drools-core/src/main/java/org/drools/core/reteoo/QueryRiaFixerNode.java
  102. +1 −2 drools-core/src/main/java/org/drools/core/reteoo/Rete.java
  103. +1 −1 drools-core/src/main/java/org/drools/core/reteoo/ReteObjectTypeNode.java
  104. +4 −6 drools-core/src/main/java/org/drools/core/reteoo/ReteooFactHandleFactory.java
  105. +11 −2 drools-core/src/main/java/org/drools/core/reteoo/RiaPathMemory.java
  106. +1 −1 drools-core/src/main/java/org/drools/core/reteoo/RightInputAdapterNode.java
  107. +1 −1 drools-core/src/main/java/org/drools/core/reteoo/RightTupleImpl.java
  108. +4 −3 drools-core/src/main/java/org/drools/core/reteoo/RuleTerminalNode.java
  109. +21 −14 drools-core/src/main/java/org/drools/core/reteoo/SingleObjectSinkAdapter.java
  110. +0 −5 drools-core/src/main/java/org/drools/core/reteoo/TimerNode.java
  111. +1 −2 drools-core/src/main/java/org/drools/core/reteoo/TraitObjectTypeNode.java
  112. +2 −9 drools-core/src/main/java/org/drools/core/reteoo/WindowNode.java
  113. +6 −1 drools-core/src/main/java/org/drools/core/reteoo/builder/BuildUtils.java
  114. +1 −1 drools-core/src/main/java/org/drools/core/rule/SlidingLengthWindow.java
  115. +1 −1 drools-core/src/main/java/org/drools/core/rule/SlidingTimeWindow.java
  116. +3 −3 drools-core/src/main/java/org/drools/core/spi/AgendaGroup.java
  117. +11 −10 drools-core/src/main/java/org/drools/core/spi/KnowledgeHelper.java
  118. +4 −6 drools-core/src/main/java/org/drools/core/spi/ProcessContext.java
  119. +17 −10 drools-core/src/main/java/org/drools/core/spi/PropagationContext.java
  120. +1 −0 drools-core/src/main/java/org/drools/core/spi/Tuple.java
  121. +67 −2 drools-core/src/main/java/org/drools/core/util/BinaryHeapQueue.java
  122. +57 −0 drools-core/src/main/java/org/drools/core/util/CompositeIterator.java
  123. +3 −3 drools-core/src/test/java/org/drools/core/reteoo/AccumulateNodeTest.java
  124. +3 −3 drools-core/src/test/java/org/drools/core/reteoo/AlphaNodeTest.java
  125. +1 −1 drools-core/src/test/java/org/drools/core/reteoo/LeftInputAdapterNodeTest.java
  126. +2 −0 drools-core/src/test/java/org/drools/core/reteoo/MockObjectSink.java
  127. +1 −7 drools-core/src/test/java/org/drools/core/reteoo/NodeSegmentUnlinkingTest.java
  128. +11 −4 drools-core/src/test/java/org/drools/core/reteoo/NotNodeTest.java
  129. +4 −26 drools-core/src/test/java/org/drools/core/reteoo/QueryElementNodeTest.java
  130. +5 −4 drools-core/src/test/java/org/drools/core/reteoo/ReteDumper.java
  131. +9 −9 drools-core/src/test/java/org/drools/core/reteoo/ReteTest.java
  132. +1 −1 drools-core/src/test/java/org/drools/core/reteoo/RuleUnlinkingTest.java
  133. +1 −1 drools-core/src/test/java/org/drools/core/reteoo/RuleUnlinkingWithSegmentMemoryTest.java
  134. +9 −18 drools-core/src/test/java/org/drools/core/reteoo/test/ReteDslTestEngine.java
  135. +1 −1 drools-core/src/test/java/org/drools/core/reteoo/test/ReteDslTestEngineTest.java
  136. +8 −8 drools-core/src/test/java/org/drools/core/spi/ProcessContextTest.java
  137. +2 −3 drools-reteoo/src/main/java/org/drools/reteoo/beliefsystem/simple/ReteSimpleBeliefSystem.java
  138. +42 −17 drools-reteoo/src/main/java/org/drools/reteoo/common/ReteAgenda.java
  139. +2 −70 drools-reteoo/src/main/java/org/drools/reteoo/common/ReteAgendaGroupQueueImpl.java
  140. +19 −33 drools-reteoo/src/main/java/org/drools/reteoo/common/RetePropagationContext.java
  141. +5 −6 drools-reteoo/src/main/java/org/drools/reteoo/common/RetePropagationContextFactory.java
  142. +3 −0 drools-reteoo/src/main/java/org/drools/reteoo/common/RetePropagationList.java
  143. +3 −26 drools-reteoo/src/main/java/org/drools/reteoo/common/ReteWorkingMemory.java
  144. +4 −5 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteAccumulateNode.java
  145. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteAlphaNode.java
  146. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteBetaNodeUtils.java
  147. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteConditionalBranchNode.java
  148. +49 −13 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteEntryPointNode.java
  149. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteEvalConditionNode.java
  150. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteFromNode.java
  151. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteQueryElementNode.java
  152. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteQueryTerminalNode.java
  153. +3 −9 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteRightInputAdapterNode.java
  154. +1 −2 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteRuleTerminalNode.java
  155. +1 −1 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteSlidingTimeWindow.java
  156. +2 −4 drools-reteoo/src/main/java/org/drools/reteoo/nodes/ReteWindowNode.java
  157. +24 −24 drools-reteoo/src/test/java/org/drools/reteoo/common/AgendaTest.java
  158. +8 −38 drools-reteoo/src/test/java/org/drools/reteoo/common/LogicalAssertionTest.java
  159. +5 −6 drools-reteoo/src/test/java/org/drools/reteoo/common/SchedulerTest.java
  160. +1 −1 ...eteoo/src/test/java/org/drools/reteoo/integrationtests/marshalling/FactHandleMarshallingTest.java
  161. +1 −1 drools-reteoo/src/test/java/org/drools/reteoo/nodes/EvalConditionNodeTest.java
  162. +4 −4 drools-reteoo/src/test/java/org/drools/reteoo/nodes/FromNodeTest.java
  163. +7 −8 drools-reteoo/src/test/java/org/drools/reteoo/nodes/JoinNodeTest.java
@@ -275,6 +275,7 @@ private void parseAnnotation(RuleBuildContext context, RuleImpl rule, RuleDescr
}
rule.setAllMatches(ruleDescr.hasAnnotation(All.class));
+
} catch (Exception e) {
DroolsError err = new RuleBuildError( rule, context.getParentDescr(), null,
e.getMessage() );
@@ -16,18 +16,16 @@
package org.drools.compiler.rule.builder.dialect.java;
-import java.util.HashMap;
-import java.util.Map;
-
import org.mvel2.Macro;
import org.mvel2.MacroProcessor;
+import java.util.HashMap;
+import java.util.Map;
+
public class KnowledgeHelperFixer {
- private static final Map<String, Macro> macros;
+ private static final Map<String, Macro> macros = new HashMap<String, Macro>();
static {
- macros = new HashMap<String, Macro>(5);
-
macros.put( "insert",
new Macro() {
public String doMacro() {
@@ -41,7 +39,14 @@ public String doMacro() {
return "drools.insertLogical";
}
} );
-
+
+ macros.put( "insertAsync",
+ new Macro() {
+ public String doMacro() {
+ return "drools.insertAsync";
+ }
+ } );
+
macros.put( "bolster",
new Macro() {
public String doMacro() {
@@ -15,9 +15,6 @@
*/
package org.drools.compiler.conf;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
import org.drools.core.RuleBaseConfiguration;
import org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler;
import org.drools.core.util.MemoryUtil;
@@ -26,24 +23,25 @@
import org.junit.Test;
import org.kie.api.KieBaseConfiguration;
import org.kie.api.KieServices;
-import org.kie.internal.KnowledgeBaseFactory;
-import org.kie.internal.conf.AlphaThresholdOption;
import org.kie.api.conf.EqualityBehaviorOption;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.conf.RemoveIdentitiesOption;
+import org.kie.api.runtime.rule.ConsequenceExceptionHandler;
+import org.kie.internal.conf.AlphaThresholdOption;
import org.kie.internal.conf.CompositeKeyDepthOption;
import org.kie.internal.conf.ConsequenceExceptionHandlerOption;
-import org.kie.api.conf.EventProcessingOption;
import org.kie.internal.conf.IndexLeftBetaMemoryOption;
import org.kie.internal.conf.IndexPrecedenceOption;
import org.kie.internal.conf.IndexRightBetaMemoryOption;
import org.kie.internal.conf.MaxThreadsOption;
import org.kie.internal.conf.MultithreadEvaluationOption;
import org.kie.internal.conf.PermGenThresholdOption;
-import org.kie.api.conf.RemoveIdentitiesOption;
import org.kie.internal.conf.SequentialAgendaOption;
import org.kie.internal.conf.SequentialOption;
import org.kie.internal.conf.ShareAlphaNodesOption;
import org.kie.internal.conf.ShareBetaNodesOption;
-import org.kie.api.runtime.rule.ConsequenceExceptionHandler;
+
+import static org.junit.Assert.assertEquals;
public class KnowledgeBaseConfigurationTest {
@@ -423,32 +421,26 @@ public void testMaxThreadsConfiguration() {
@Test
public void testMultithreadEvaluationConfiguration() {
- try {
- // setting the option using the type safe method
- config.setOption( MultithreadEvaluationOption.YES );
-
- fail( "An exception should have been raised as this configuration option is no longer supported. ");
-
- // checking the type safe getOption() method
- assertEquals( MultithreadEvaluationOption.YES,
- config.getOption( MultithreadEvaluationOption.class ) );
- // checking the string based getProperty() method
- assertEquals( "true",
- config.getProperty( MultithreadEvaluationOption.PROPERTY_NAME ) );
-
- // setting the options using the string based setProperty() method
- config.setProperty( MultithreadEvaluationOption.PROPERTY_NAME,
- "false" );
-
- // checking the type safe getOption() method
- assertEquals( MultithreadEvaluationOption.NO,
- config.getOption( MultithreadEvaluationOption.class ) );
- // checking the string based getProperty() method
- assertEquals( "false",
- config.getProperty( MultithreadEvaluationOption.PROPERTY_NAME ) );
- } catch( Exception ex ) {
- // succeed, as this configuration option is not currently supported
- }
+ // setting the option using the type safe method
+ config.setOption( MultithreadEvaluationOption.YES );
+
+ // checking the type safe getOption() method
+ assertEquals( MultithreadEvaluationOption.YES,
+ config.getOption( MultithreadEvaluationOption.class ) );
+ // checking the string based getProperty() method
+ assertEquals( "true",
+ config.getProperty( MultithreadEvaluationOption.PROPERTY_NAME ) );
+
+ // setting the options using the string based setProperty() method
+ config.setProperty( MultithreadEvaluationOption.PROPERTY_NAME,
+ "false" );
+
+ // checking the type safe getOption() method
+ assertEquals( MultithreadEvaluationOption.NO,
+ config.getOption( MultithreadEvaluationOption.class ) );
+ // checking the string based getProperty() method
+ assertEquals( "false",
+ config.getProperty( MultithreadEvaluationOption.PROPERTY_NAME ) );
}
@Test
@@ -5663,8 +5663,6 @@ public boolean accept( Object object ) {
} ) ) {
InternalFactHandle handle = (InternalFactHandle) ksession.getFactHandle( o );
LeftTuple first = handle.getFirstLeftTuple();
- LeftTuple last = handle.getLastLeftTuple();
- assertSame( first, last );
assertTrue( first instanceof RuleTerminalNodeLeftTuple );
assertEquals( "Check", ((RuleTerminalNodeLeftTuple) first).getRule().getName() );
}
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2016 Red Hat, Inc. and/or its affiliates.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.compiler.integrationtests;
+
+import org.drools.compiler.integrationtests.facts.A;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.kie.api.KieBase;
+import org.kie.api.KieBaseConfiguration;
+import org.kie.api.conf.EventProcessingOption;
+import org.kie.api.io.ResourceType;
+import org.kie.api.runtime.KieSession;
+import org.kie.internal.KnowledgeBaseFactory;
+import org.kie.internal.conf.MultithreadEvaluationOption;
+import org.kie.internal.utils.KieHelper;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.LongAdder;
+
+public class CompositeAgendaTest {
+
+ @Test @Ignore
+ public void testInALoop() {
+ for (int i = 0; i < 100; i++) {
+ testCreateHaltDisposeAgenda();
+ System.out.println("Done: " + i);
+ }
+ }
+
+ @Test @Ignore
+ public void testCreateHaltDisposeAgenda() {
+ final String drl = " import org.drools.compiler.integrationtests.facts.*;\n" +
+ " declare A @role( event ) end\n" +
+ " global java.util.concurrent.atomic.LongAdder firings;\n" +
+ " rule R0 when\n" +
+ " A( value > 0,$Aid: id )\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R1 when\n" +
+ " A(value > 1)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R2 when\n" +
+ " A(value > 2)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R3 when\n" +
+ " A(value > 3)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R4 when\n" +
+ " A(value > 4)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R5 when\n" +
+ " A(value > 5)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R6 when\n" +
+ " A(value > 6)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end\n" +
+ " rule R7 when\n" +
+ " A(value > 7)\n" +
+ " then\n" +
+ " firings.add(1);\n" +
+ " end";
+
+ final KieBaseConfiguration kieBaseConfiguration = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
+ kieBaseConfiguration.setOption(MultithreadEvaluationOption.YES);
+ kieBaseConfiguration.setOption(EventProcessingOption.STREAM);
+ final KieBase kieBase = new KieHelper().addContent(drl, ResourceType.DRL).build(kieBaseConfiguration);
+ final KieSession kieSession = kieBase.newKieSession();
+
+ final LongAdder firingCounter = new LongAdder();
+ kieSession.setGlobal("firings", firingCounter);
+
+ final ExecutorService executor = Executors.newFixedThreadPool(2);
+ executor.submit(() -> kieSession.fireUntilHalt());
+
+ final EventInsertThread eventInsertThread = new EventInsertThread(kieSession);
+ executor.submit(eventInsertThread);
+
+ try {
+ Thread.sleep(5000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ kieSession.halt();
+ eventInsertThread.setActive(false);
+ kieSession.dispose();
+
+ executor.shutdown();
+ try {
+ if (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
+ executor.shutdownNow();
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ Assert.fail(e.getMessage());
+ }
+ }
+
+ public static class EventInsertThread implements Runnable {
+
+ private boolean active = true;
+ private KieSession kieSession;
+
+ public EventInsertThread(final KieSession kieSession) {
+ this.kieSession = kieSession;
+ }
+
+ public void setActive(final boolean active) {
+ this.active = active;
+ }
+
+ @Override
+ public void run() {
+ while (active) {
+ kieSession.insert(new A(100));
+ }
+ }
+ }
+}
@@ -933,7 +933,7 @@ public void testFiredRuleDoNotRefireAfterUnblock() {
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
- List<String> list = new ArrayList<String>();
+ List<String> list = new DebugList<String>();
ksession.setGlobal("list", list);
@@ -959,6 +959,13 @@ public void testFiredRuleDoNotRefireAfterUnblock() {
list.clear();
}
+ public static class DebugList<T> extends ArrayList<T> {
+ @Override
+ public boolean add( T t ) {
+ return super.add( t );
+ }
+ }
+
@Test
public void testExplicitUndercutWithDeclarativeAgenda() {
@@ -476,7 +476,7 @@ public void testLockOnActiveWithModify() throws Exception {
agenda.setFocus( group1 );
assertEquals( 1, group1.size() );
RuleAgendaItem ruleItem1 = (RuleAgendaItem) group1.getActivations()[0];
- ruleItem1.getRuleExecutor().evaluateNetwork(wm);
+ ruleItem1.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(3, ruleItem1.getRuleExecutor().getLeftTupleList().size());
agenda.fireNextItem( null, 0, 0 );
@@ -485,14 +485,14 @@ public void testLockOnActiveWithModify() throws Exception {
ksession.update( brieHandle, brie );
assertEquals( 1, group1.size() );
- ruleItem1.getRuleExecutor().evaluateNetwork(wm);
+ ruleItem1.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(2, ruleItem1.getRuleExecutor().getLeftTupleList().size());
AgendaGroup group2 = agenda.getAgendaGroup( "group2" );
agenda.setFocus( group2);
assertEquals( 1, group2.size() );
RuleAgendaItem ruleItem2 = (RuleAgendaItem) group2.getActivations()[0];
- ruleItem2.getRuleExecutor().evaluateNetwork(wm);
+ ruleItem2.getRuleExecutor().evaluateNetwork(wm.getAgenda());
assertEquals(3, ruleItem2.getRuleExecutor().getLeftTupleList().size());
agenda.fireNextItem( null, 0, 0 );
@@ -16,6 +16,7 @@
package org.drools.compiler.integrationtests;
import org.drools.core.base.ClassObjectType;
+import org.drools.core.base.DefaultKnowledgeHelper;
import org.drools.core.common.AgendaItem;
import org.drools.core.common.InternalAgenda;
import org.drools.core.common.InternalAgendaGroup;
@@ -24,6 +25,7 @@
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.impl.StatefulKnowledgeSessionImpl;
import org.drools.core.phreak.RuleAgendaItem;
+import org.drools.core.phreak.RuleExecutor;
import org.drools.core.phreak.SegmentUtilities;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.EvalConditionNode;
@@ -1731,7 +1733,9 @@ public void testSubnetwork() throws Exception {
InternalAgenda agenda = ( InternalAgenda ) wm.getAgenda();
InternalAgendaGroup group = (InternalAgendaGroup) agenda.getNextFocus();
AgendaItem item = (AgendaItem) group.remove();
- int count = ((RuleAgendaItem)item).getRuleExecutor().evaluateNetworkAndFire(wm, null, 0, -1);
+ RuleExecutor ruleExecutor = ((RuleAgendaItem)item).getRuleExecutor();
+ ruleExecutor.setKnowledgeHelper( new DefaultKnowledgeHelper() );
+ int count = ruleExecutor.evaluateNetworkAndFire(wm, null, 0, -1);
//assertEquals(3, count );
wm.fireAllRules();
Oops, something went wrong.

0 comments on commit 63ea870

Please sign in to comment.