From 7cfaef25c65756ca463ffafbcff8c3c02d9f05c1 Mon Sep 17 00:00:00 2001 From: Mark Proctor Date: Thu, 15 Aug 2024 18:12:34 +0100 Subject: [PATCH] -Sequencing now has Rule AST for adding a Sequence. Now tests builds it's node from a Rule. --- ...bstractPhreakSequencerSubsequenceTest.java | 89 ++++++++++- .../phreak/sequencing/AlphaConstraint.java | 55 +++++++ .../sequencing/MultiInputNodeBuilder.java | 151 ------------------ .../sequencing/PhreakSequencerActionTest.java | 45 +----- ...akSequencerActivateDeactivateStepTest.java | 73 +-------- .../PhreakSequencerAggregatorTest.java | 46 +----- .../PhreakSequencerEventsMemoryTest.java | 48 +----- .../PhreakSequencerLogicGateTest.java | 83 ++-------- .../PhreakSequencerSequenceLoopTest.java | 54 +------ .../PhreakSequencerSequenceTimerTest.java | 52 +----- ...akSequencerSignalProcessorCounterTest.java | 99 +++--------- ...reakSequencerSignalProcessorTimerTest.java | 89 +++-------- .../PhreakSequencerSubsequenceLoopTest.java | 56 +------ .../PhreakSequencerSubsequenceTest.java | 44 +---- .../PhreakSequencerSubsequenceTimerTest.java | 53 +----- .../phreak/sequencing/Predicate1.java | 5 + .../phreak/sequencing/SequenceInRuleTest.java | 12 -- .../phreak/sequencing/TestMemories.java | 89 +++++++++++ 18 files changed, 345 insertions(+), 798 deletions(-) create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java delete mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java create mode 100644 drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java index 2f633470025..13f7910fb2f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AbstractPhreakSequencerSubsequenceTest.java @@ -1,7 +1,11 @@ package org.drools.mvel.integrationtests.phreak.sequencing; +import org.drools.base.base.ClassObjectType; +import org.drools.base.base.ObjectType; import org.drools.base.definitions.InternalKnowledgePackage; import org.drools.base.definitions.rule.impl.RuleImpl; +import org.drools.base.rule.EntryPointId; +import org.drools.base.rule.Pattern; import org.drools.core.ClockType; import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; @@ -10,6 +14,7 @@ import org.drools.core.reteoo.CoreComponentFactory; import org.drools.core.reteoo.LeftTuple; import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.ObjectTypeNode; import org.drools.core.reteoo.SequenceNode; import org.drools.base.reteoo.DynamicFilterProto; import org.drools.core.reteoo.SequenceNode.SequenceNodeMemory; @@ -20,6 +25,11 @@ import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; import org.drools.mvel.integrationtests.phreak.A; +import org.drools.mvel.integrationtests.phreak.B; +import org.drools.mvel.integrationtests.phreak.C; +import org.drools.mvel.integrationtests.phreak.D; +import org.drools.mvel.integrationtests.phreak.E; +import org.kie.api.conf.EventProcessingOption; import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.internal.conf.CompositeBaseConfiguration; @@ -32,14 +42,58 @@ public class AbstractPhreakSequencerSubsequenceTest { BuildContext buildContext; Sequence seq0; Sequence seq1; - Sequence seq2; - SequenceNode mnode; + Sequence seq2; + SequenceNode snode; + + Pattern bpattern; + Pattern cpattern; + Pattern dpattern; + Pattern epattern; + + RuleImpl rule; + InternalKnowledgePackage pkg; + SessionsAwareKnowledgeBase kbase; DynamicFilterProto bfilter; DynamicFilterProto cfilter; DynamicFilterProto dfilter; DynamicFilterProto efilter; + public void initKBaseWithEmptyRule() { + CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); + conf.setOption(EventProcessingOption.STREAM); + + KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf ); + + kbase = new SessionsAwareKnowledgeBase(rbase); + + rule = new RuleImpl("rule1").setPackage("org.pkg1"); + pkg = CoreComponentFactory.get().createKnowledgePackage("org.pkg1"); + pkg.getDialectRuntimeRegistry().setDialectData( "java", new JavaDialectRuntimeData()); + pkg.addRule( rule ); + + final ObjectType aObjectType = new ClassObjectType(A.class); + final ObjectType bObjectType = new ClassObjectType(B.class); + final ObjectType cObjectType = new ClassObjectType(C.class); + final ObjectType dObjectType = new ClassObjectType(D.class); + final ObjectType eObjectType = new ClassObjectType(E.class); + + Pattern aPattern = new Pattern(0, aObjectType); + rule.addPattern(aPattern); + + bpattern = new Pattern(0, bObjectType, "b" ); + bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); + + cpattern = new Pattern(0, cObjectType, "c" ); + cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); + + dpattern = new Pattern(0, dObjectType, "d" ); + dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); + + epattern = new Pattern(0, eObjectType, "e" ); + epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); + } + public static BuildContext createContext() { CompositeBaseConfiguration conf = (CompositeBaseConfiguration) RuleBaseFactory.newKnowledgeBaseConfiguration(); @@ -74,10 +128,35 @@ void createSession() { session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); - nodeMemory = session.getNodeMemory(mnode); - LeftTuple lt = new LeftTuple(fhA0, mnode, true); - lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory = session.getNodeMemory(snode); + LeftTuple lt = new LeftTuple(fhA0, snode, true); + lt.setContextObject(snode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); nodeMemory.getLeftTupleMemory().add(lt); sequencerMemory = (SequencerMemory) lt.getContextObject(); } + + void createSession2() { + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + sessionConf.setClockType(ClockType.PSEUDO_CLOCK); + + if (snode == null) { + ObjectTypeNode aNode = kbase.getRete().getEntryPointNode(EntryPointId.DEFAULT).getObjectTypeNodes().get(new ClassObjectType(A.class)); + snode = (SequenceNode) aNode.getSinks()[0].getSinks()[0]; + } + + if (session != null) { + nodeMemory = null; + sequencerMemory = null; + session.dispose(); + session = null; + } + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + session.fireAllRules(); + nodeMemory = session.getNodeMemory(snode); + sequencerMemory = (SequencerMemory) fhA0.getFirstLeftTuple().getContextObject(); + } } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java new file mode 100644 index 00000000000..6832fe6d744 --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/AlphaConstraint.java @@ -0,0 +1,55 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ValueResolver; +import org.drools.base.reteoo.BaseTuple; +import org.drools.base.rule.Declaration; +import org.drools.base.rule.MutableTypeConstraint; +import org.kie.api.runtime.rule.FactHandle; + +public class AlphaConstraint extends MutableTypeConstraint { + private Predicate1 predicate1; + + public AlphaConstraint(Predicate1 predicate1) { + this.predicate1 = predicate1; + } + + @Override + public Declaration[] getRequiredDeclarations() { + return new Declaration[0]; + } + + @Override + public void replaceDeclaration(Declaration oldDecl, Declaration newDecl) { + + } + + @Override + public MutableTypeConstraint clone() { + return null; + } + + @Override + public boolean isTemporal() { + return false; + } + + @Override + public boolean isAllowed(FactHandle handle, ValueResolver valueResolver) { + return predicate1.test(handle.getObject()); + } + + @Override + public boolean isAllowedCachedLeft(Object context, FactHandle handle) { + return false; + } + + @Override + public boolean isAllowedCachedRight(BaseTuple tuple, Object context) { + return false; + } + + @Override + public Object createContext() { + return null; + } +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java deleted file mode 100644 index 81cd629e211..00000000000 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/MultiInputNodeBuilder.java +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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.mvel.integrationtests.phreak.sequencing; - -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ValueResolver; -import org.drools.base.common.RuleBasePartitionId; -import org.drools.base.reteoo.BaseTuple; -import org.drools.base.rule.Declaration; -import org.drools.base.rule.EntryPointId; -import org.drools.base.rule.MutableTypeConstraint; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.reteoo.CoreComponentFactory; -import org.drools.core.reteoo.EntryPointNode; -import org.drools.core.reteoo.LeftTupleSource; -import org.drools.core.reteoo.SequenceNode; -import org.drools.core.reteoo.SequenceNode.AlphaAdapter; -import org.drools.core.reteoo.ObjectSource; -import org.drools.core.reteoo.ObjectTypeNode; -import org.drools.core.reteoo.builder.BuildContext; -import org.drools.core.reteoo.builder.NodeFactory; -import org.kie.api.runtime.rule.FactHandle; - -public class MultiInputNodeBuilder { - BuildContext buildContext; - - public MultiInputNodeBuilder(BuildContext buildContext) { - this.buildContext = buildContext; - } - - public static MultiInputNodeBuilder create(BuildContext buildContext) { - return new MultiInputNodeBuilder(buildContext); - } - - public SequenceNode buildNode(Class leftType, Class[] rightTypes) { - NodeFactory nFactory = CoreComponentFactory.get().getNodeFactoryService(); - - EntryPointNode epn = buildContext.getRuleBase().getRete().getEntryPointNodes().get(EntryPointId.DEFAULT); - - buildContext.setCurrentEntryPoint(epn.getEntryPoint()); - buildContext.setTupleMemoryEnabled(true); - buildContext.setPartitionId(RuleBasePartitionId.MAIN_PARTITION); - - ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), - epn, - new ClassObjectType(leftType), - buildContext); - LeftTupleSource leftTs = nFactory.buildLeftInputAdapterNode(buildContext.getNextNodeId(), otn, - buildContext, false); - - ObjectSource[] otns = new ObjectSource[rightTypes.length]; - for ( int i = 0; i < rightTypes.length; i++ ) { - otns[i] = nFactory.buildObjectTypeNode(buildContext.getNextNodeId(), epn, - new ClassObjectType(rightTypes[i]), - buildContext); - - otns[i].attach(buildContext); - } - - - SequenceNode mn = new SequenceNode(buildContext.getNextNodeId(), - leftTs, buildContext); - - AlphaAdapter[] adapters = new AlphaAdapter[rightTypes.length]; - for ( int i = 0; i < rightTypes.length; i++ ) { - adapters[i] = new AlphaAdapter(buildContext.getNextNodeId(), otns[i], - buildContext.getPartitionId(), mn, i); - - adapters[i].attach(buildContext); - } - - mn.setAlphaAdapters(adapters); - - mn.attach(buildContext); - - return mn; - } - - public AlphaNodeFieldConstraint buildConstraint(Predicate1 predicate1) { - return new AlphaConstraint(predicate1); - } - - public static class AlphaConstraint extends MutableTypeConstraint { - private Predicate1 predicate1; - - public AlphaConstraint(Predicate1 predicate1) { - this.predicate1 = predicate1; - } - - @Override - public Declaration[] getRequiredDeclarations() { - return new Declaration[0]; - } - - @Override - public void replaceDeclaration(Declaration oldDecl, Declaration newDecl) { - - } - - @Override - public MutableTypeConstraint clone() { - return null; - } - - @Override - public boolean isTemporal() { - return false; - } - - @Override - public boolean isAllowed(FactHandle handle, ValueResolver valueResolver) { - return predicate1.test(handle.getObject()); - } - - @Override - public boolean isAllowedCachedLeft(Object context, FactHandle handle) { - return false; - } - - @Override - public boolean isAllowedCachedRight(BaseTuple tuple, Object context) { - return false; - } - - @Override - public Object createContext() { - return null; - } - } - - interface Predicate1 { - boolean test(A a); - } - -} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java index 11086c269e6..b9a6ead02e3 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActionTest.java @@ -18,31 +18,18 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; import java.util.ArrayList; @@ -56,24 +43,9 @@ public class PhreakSequencerActionTest extends AbstractPhreakSequencerSubsequenc @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); + initKBaseWithEmptyRule(); recorder.clear(); - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -84,14 +56,12 @@ public void setup() { Step.of(circuit2), Step.of( m -> recorder.add("spacer")), Step.of( m -> recorder.add(((FactHandle)m.getSequencerMemory().getEvents().getHead()).getObject()))); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -111,11 +81,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testAction() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java index 3bea1266335..2a23ca84cac 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerActivateDeactivateStepTest.java @@ -18,35 +18,22 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; import org.drools.base.reteoo.DynamicFilter; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.SignalAdapter; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.base.util.LinkedList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import static org.assertj.core.api.Assertions.assertThat; @@ -56,36 +43,7 @@ public class PhreakSequencerActivateDeactivateStepTest extends AbstractPhreakSeq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("d"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - DynamicFilterProto dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0, 1}, // B and C @@ -104,34 +62,17 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); sequenceMemory = sequencerMemory.getSequenceMemory(seq0); } - @Test - public void testInitialisedMemories() { - // make sure these are empty - assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[3]); - assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); - assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); - assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); - assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // sequence not yet started - } - @Test public void testActivateAfterFirstCircuitStep() { // activate LogicCircuit1 and check filters are adapters are created and made active - mnode.getSequencer().start(sequencerMemory, session); - DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C // [2] D is null @@ -155,8 +96,6 @@ public void testActivateAfterFirstCircuitStep() { @Test public void testDeactivateAndActivateAfterSecondCircuitStep() { - mnode.getSequencer().start(sequencerMemory, session); - DynamicFilter filter0 = nodeMemory.getFilters()[0]; // B DynamicFilter filter1 = nodeMemory.getFilters()[1]; // C @@ -193,8 +132,6 @@ public void testDeactivateAndActivateAfterSecondCircuitStep() { @Test public void testDeactivateAfterEndStep() { - mnode.getSequencer().start(sequencerMemory, session); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java index 58d38624c25..0e8e8cc1b30 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerAggregatorTest.java @@ -18,32 +18,20 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; import java.util.ArrayList; @@ -58,23 +46,7 @@ public class PhreakSequencerAggregatorTest extends AbstractPhreakSequencerSubseq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - recorder.clear(); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -102,14 +74,11 @@ public void setup() { seq1.setOutputSize(1); seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1, aggregator), Step.of(circuit4)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -129,11 +98,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSequenceEventsMemory() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(b(0)); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java index 4ee671f5bc3..b2d4be072a7 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerEventsMemoryTest.java @@ -18,58 +18,27 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.util.CircularArrayList; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import org.kie.api.runtime.rule.FactHandle; -import java.util.ArrayList; - import static org.assertj.core.api.Assertions.assertThat; public class PhreakSequencerEventsMemoryTest extends AbstractPhreakSequencerSubsequenceTest { - @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicCircuit circuit1 = getLogicCircuit(); LogicCircuit circuit2 = getLogicCircuit(); @@ -82,14 +51,12 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit4), Step.of(circuit5)); seq0 = new Sequence(0, Step.of(circuit1), Step.of(seq1), Step.of(circuit3), Step.of(seq2), Step.of(circuit6)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - createSession(); + createSession2(); } private LogicCircuit getLogicCircuit() { @@ -109,11 +76,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSequenceEventsMemory() { - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - CircularArrayList events = sequencerMemory.getEvents(); assertThat(events.size()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java index 27368aa4c40..794118999a7 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerLogicGateTest.java @@ -18,31 +18,21 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import static org.assertj.core.api.Assertions.assertThat; @@ -50,43 +40,7 @@ public class PhreakSequencerLogicGateTest extends AbstractPhreakSequencerSubsequ @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -101,12 +55,11 @@ public void testAnd() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -114,8 +67,7 @@ public void testAnd() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -136,20 +88,18 @@ public void testOr() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // reverse B and C - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -176,12 +126,12 @@ public void testComposite() { LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); // D last - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 @@ -193,8 +143,7 @@ public void testComposite() { assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated // change order, D first - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java index 2ac325c48e3..9e3e834cdc1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceLoopTest.java @@ -18,32 +18,20 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -53,29 +41,7 @@ public class PhreakSequencerSequenceLoopTest extends AbstractPhreakSequencerSubs @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -92,25 +58,18 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern, epattern}); } @Test public void testSequenceLoopConstraint() { seq0.setController(new LoopController(m -> m.getCount() < 2)); + rule.addSequence(seq0); + kbase.addPackage(pkg); - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); + ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0); @@ -132,7 +91,6 @@ public void testSequenceLoopConstraint() { InternalFactHandle fhC4 = (InternalFactHandle) session.insert(new C(0, "c")); assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(3); - assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated } diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java index e07e932dfce..a165a0d232d 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSequenceTimerTest.java @@ -18,31 +18,21 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.Sequence.TimoutController; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -53,29 +43,7 @@ public class PhreakSequencerSequenceTimerTest extends AbstractPhreakSequencerSu @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b"); - bpattern.addConstraint(new AlphaConstraint((Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c"); - cpattern.addConstraint(new AlphaConstraint((Predicate1) c -> c.getText().equals("c"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - DynamicFilterProto cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, new int[]{0}, // B @@ -92,20 +60,17 @@ public void setup() { LogicCircuit circuit2 = new LogicCircuit(gate2); seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters(new DynamicFilterProto[]{bfilter, cfilter}); + seq0.setFilters(new Pattern[]{bpattern, cpattern}); } @Test public void testSequenceTimeout() { seq0.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); - InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); @@ -118,12 +83,11 @@ public void testSequenceTimeout() { @Test public void testSequenceComplete() { seq0.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + rule.addSequence(seq0); + kbase.addPackage(pkg); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java index 6f8ce666420..881572c5ea1 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorCounterTest.java @@ -18,33 +18,23 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGateOutputSignalProcessor; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.signalprocessors.SignalIndex; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import static org.assertj.core.api.Assertions.assertThat; @@ -52,43 +42,7 @@ public class PhreakSequencerSignalProcessorCounterTest extends AbstractPhreakSeq @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -107,12 +61,11 @@ public void testEventCountEqual() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); - - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -138,12 +91,11 @@ public void testEventCountLessThan() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -153,9 +105,7 @@ public void testEventCountLessThan() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession(); // fail - mnode.getSequencer().start(sequencerMemory, session); - + createSession2(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -181,11 +131,11 @@ public void testEventCountBetween() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); // pass assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -196,9 +146,7 @@ public void testEventCountBetween() { InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b")); - createSession(); // fail - mnode.getSequencer().start(sequencerMemory, session); - + createSession2(); // fail assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -221,11 +169,12 @@ public void testSingleOutputCounter() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); + + createSession2(); // pass - createSession(); // pass - mnode.getSequencer().start(sequencerMemory, session); SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -275,12 +224,12 @@ public void testCompositeInputAndOutputCounters() { LogicCircuit circuit1 = new LogicCircuit(gate1, gate2); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter, dfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); // D First - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq); InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d")); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java index 48e3d35d92c..374d273458a 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSignalProcessorTimerTest.java @@ -18,12 +18,8 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.ConditionalSignalCounter; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; @@ -32,21 +28,14 @@ import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.DelayFromMatchTimer; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate.TimeoutTimer; import org.drools.base.reteoo.sequencing.Sequence; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import java.util.concurrent.TimeUnit; @@ -54,45 +43,10 @@ public class PhreakSequencerSignalProcessorTimerTest extends AbstractPhreakSequencerSubsequenceTest { + @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class, C.class, D.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - final ObjectType cObjectType = new ClassObjectType(C.class); - final ObjectType dObjectType = new ClassObjectType(D.class); - final ObjectType eObjectType = new ClassObjectType(E.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - final Pattern cpattern = new Pattern(0, - cObjectType, - "c" ); - cpattern.addConstraint(new AlphaConstraint( (Predicate1) c -> c.getText().equals("c"))); - - final Pattern dpattern = new Pattern(0, - dObjectType, - "d" ); - dpattern.addConstraint(new AlphaConstraint( (Predicate1) d -> d.getText().equals("d"))); - - final Pattern epattern = new Pattern(0, - eObjectType, - "e" ); - epattern.addConstraint(new AlphaConstraint( (Predicate1) e -> e.getText().equals("e"))); - - bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); - cfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) cpattern.getConstraints().get(0), 1); - dfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) dpattern.getConstraints().get(0), 2); - efilter = new DynamicFilterProto((AlphaNodeFieldConstraint) epattern.getConstraints().get(0), 3); + initKBaseWithEmptyRule(); } @Test @@ -109,12 +63,11 @@ public void testTimeout() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); - - createSession(); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -122,9 +75,8 @@ public void testTimeout() { pseudo.advanceTime(2000, TimeUnit.MILLISECONDS); session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession(); - mnode.getSequencer().start(sequencerMemory, session); + createSession2(); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -154,12 +106,12 @@ public void testTimeoutWithCountFailure() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + seq.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhB1 = (InternalFactHandle) session.insert(new B(0, "b")); @@ -198,12 +150,12 @@ public void testDelayFromActivation() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c")); @@ -213,9 +165,8 @@ public void testDelayFromActivation() { session.fireAllRules(); // if the rest of the system is immediate, why isn't this? assertThat(pseudo.getQueue().size()).isEqualTo(0); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); pseudo = (PseudoClockScheduler) session.getTimerService(); @@ -239,12 +190,12 @@ public void testDelayFromMatch() { LogicCircuit circuit1 = new LogicCircuit(gate1); Sequence seq = new Sequence(0, Step.of(circuit1)); - mnode.setSequencer(new Sequencer(seq)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter, cfilter}); + seq.setFilters(new Pattern[]{bpattern, cpattern}); + rule.addSequence(seq); + kbase.addPackage(pkg); - createSession(); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0 InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b")); PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService(); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java index 7599860cace..e93c914a47f 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceLoopTest.java @@ -18,35 +18,19 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.core.reteoo.LeftTuple; -import org.drools.core.reteoo.MockLeftTupleSink; -import org.drools.base.reteoo.DynamicFilterProto; -import org.drools.base.reteoo.sequencing.SequencerMemory; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.LoopController; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -56,22 +40,7 @@ public class PhreakSequencerSubsequenceLoopTest extends AbstractPhreakSequencerS @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -105,32 +74,19 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); - - session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); - - InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); - nodeMemory = session.getNodeMemory(mnode); - LeftTuple lt = new LeftTuple(fhA0, mnode, true); - lt.setContextObject(mnode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); - nodeMemory.getLeftTupleMemory().add(lt); - sequencerMemory = (SequencerMemory) lt.getContextObject(); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); } @Test public void testSubSequence() { seq1.setController(new LoopController(m -> m.getCount() < 2)); seq2.setController(new LoopController(m -> m.getCount() < 2)); + kbase.addPackage(pkg); - ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); + createSession2(); - mnode.getSequencer().start(sequencerMemory, session); + ArrayList stack = sequencerMemory.getSequenceStack(); assertThat(stack.size()).isEqualTo(2); assertThat(stack.get(0).getSequence()).isSameAs(seq0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java index b32d3174797..3a497de2a57 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTest.java @@ -18,30 +18,18 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.steps.Step; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; @@ -49,25 +37,9 @@ public class PhreakSequencerSubsequenceTest extends AbstractPhreakSequencerSubsequenceTest { - @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = get1InputLogicGate(); gate1.setOutput(TerminatingSignalProcessor.get()); @@ -89,14 +61,11 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.YES); - - createSession(); + createSession2(); } private static LogicGate get1InputLogicGate() { @@ -110,9 +79,6 @@ private static LogicGate get1InputLogicGate() { @Test public void testSubSequence() { ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(stack.get(0).getSequence()).isSameAs(seq0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java index 8264ab97a8d..3a31220ab60 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/PhreakSequencerSubsequenceTimerTest.java @@ -18,34 +18,22 @@ */ package org.drools.mvel.integrationtests.phreak.sequencing; -import org.drools.base.base.ClassObjectType; -import org.drools.base.base.ObjectType; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.base.time.JobHandle; -import org.drools.core.SessionConfiguration; import org.drools.core.common.InternalFactHandle; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; import org.drools.base.reteoo.sequencing.Sequence.TimoutController; -import org.drools.base.reteoo.sequencing.Sequencer; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.core.time.impl.DurationTimer; import org.drools.core.time.impl.PseudoClockScheduler; -import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; -import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; -import org.kie.api.runtime.conf.ThreadSafeOption; import java.util.ArrayList; import java.util.concurrent.TimeUnit; @@ -56,22 +44,7 @@ public class PhreakSequencerSubsequenceTimerTest extends AbstractPhreakSequencer @Before public void setup() { - buildContext = createContext(); - buildContext.getRuleBase().getRuleBaseConfiguration().setOption(EventProcessingOption.STREAM); - - MultiInputNodeBuilder builder = MultiInputNodeBuilder.create(buildContext); - - mnode = builder.buildNode(A.class, new Class[]{B.class}); - - final ObjectType aObjectType = new ClassObjectType(A.class); - final ObjectType bObjectType = new ClassObjectType(B.class); - - final Pattern bpattern = new Pattern(0, - bObjectType, - "b" ); - bpattern.addConstraint(new AlphaConstraint( (Predicate1) b -> b.getText().equals("b"))); - - DynamicFilterProto bfilter = new DynamicFilterProto((AlphaNodeFieldConstraint) bpattern.getConstraints().get(0), 0); + initKBaseWithEmptyRule(); LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),0, new int[] {0}, // B @@ -105,23 +78,17 @@ public void setup() { seq2 = new Sequence(2, Step.of(circuit3), Step.of(circuit4)); seq0 = new Sequence(0, Step.of(seq1), Step.of(seq2)); - mnode.setSequencer(new Sequencer(seq0)); - mnode.setDynamicFilters( new DynamicFilterProto[] {bfilter}); - - SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase()); - SessionConfiguration sessionConf = kbase.getSessionConfiguration(); - sessionConf.setOption(ThreadSafeOption.NO); + seq0.setFilters(new Pattern[]{bpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); } @Test public void testSubSequenceFailSeq1() { seq1.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -141,12 +108,9 @@ public void testSubSequenceFailSeq1() { public void testSubSequenceFailSeq2() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); @@ -175,12 +139,9 @@ public void testSubSequenceFailSeq2() { public void testSubSequenceComplete() { seq1.setController(new TimoutController(new DurationTimer(1000))); seq2.setController(new TimoutController(new DurationTimer(1000))); - createSession(); + createSession2(); ArrayList stack = sequencerMemory.getSequenceStack(); - assertThat(stack.size()).isEqualTo(0); - - mnode.getSequencer().start(sequencerMemory, session); assertThat(stack.size()).isEqualTo(2); assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java new file mode 100644 index 00000000000..406907a5e1d --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/Predicate1.java @@ -0,0 +1,5 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +interface Predicate1 { + boolean test(A a); +} diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java index 12c91041d85..2daf9b63172 100644 --- a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/SequenceInRuleTest.java @@ -3,9 +3,7 @@ import org.drools.base.base.ClassObjectType; import org.drools.base.base.ObjectType; import org.drools.base.definitions.InternalKnowledgePackage; -import org.drools.base.definitions.impl.KnowledgePackageImpl; import org.drools.base.definitions.rule.impl.RuleImpl; -import org.drools.base.reteoo.DynamicFilterProto; import org.drools.base.reteoo.sequencing.Sequence; import org.drools.base.reteoo.sequencing.signalprocessors.Gates; import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; @@ -13,28 +11,19 @@ import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; import org.drools.base.reteoo.sequencing.steps.Step; import org.drools.base.rule.Pattern; -import org.drools.base.rule.constraint.AlphaNodeFieldConstraint; import org.drools.core.impl.KnowledgeBaseImpl; import org.drools.core.impl.RuleBaseFactory; import org.drools.core.reteoo.CoreComponentFactory; -import org.drools.core.reteoo.builder.BuildContext; import org.drools.core.rule.JavaDialectRuntimeData; import org.drools.kiesession.rulebase.SessionsAwareKnowledgeBase; import org.drools.mvel.integrationtests.phreak.A; import org.drools.mvel.integrationtests.phreak.B; import org.drools.mvel.integrationtests.phreak.C; -import org.drools.mvel.integrationtests.phreak.D; -import org.drools.mvel.integrationtests.phreak.E; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.AlphaConstraint; -import org.drools.mvel.integrationtests.phreak.sequencing.MultiInputNodeBuilder.Predicate1; import org.junit.Before; import org.junit.Test; -import org.kie.api.conf.EventProcessingOption; import org.kie.api.runtime.KieSession; import org.kie.internal.conf.CompositeBaseConfiguration; -import java.util.Collections; - public class SequenceInRuleTest { SessionsAwareKnowledgeBase kbase; @Before @@ -111,7 +100,6 @@ public void setup() { // pkg.addRule(rule); // // buildContext.getRuleBase() - } @Test diff --git a/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java new file mode 100644 index 00000000000..aaeda34ec8d --- /dev/null +++ b/drools-test-coverage/test-compiler-integration/src/test/java/org/drools/mvel/integrationtests/phreak/sequencing/TestMemories.java @@ -0,0 +1,89 @@ +package org.drools.mvel.integrationtests.phreak.sequencing; + +import org.drools.base.base.ClassObjectType; +import org.drools.base.reteoo.DynamicFilter; +import org.drools.base.reteoo.SignalAdapter; +import org.drools.base.reteoo.sequencing.Sequence; +import org.drools.base.reteoo.sequencing.Sequence.SequenceMemory; +import org.drools.base.reteoo.sequencing.SequencerMemory; +import org.drools.base.reteoo.sequencing.signalprocessors.Gates; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicCircuit; +import org.drools.base.reteoo.sequencing.signalprocessors.LogicGate; +import org.drools.base.reteoo.sequencing.signalprocessors.TerminatingSignalProcessor; +import org.drools.base.reteoo.sequencing.steps.Step; +import org.drools.base.rule.EntryPointId; +import org.drools.base.rule.Pattern; +import org.drools.base.util.LinkedList; +import org.drools.core.ClockType; +import org.drools.core.SessionConfiguration; +import org.drools.core.common.InternalFactHandle; +import org.drools.core.reteoo.LeftTuple; +import org.drools.core.reteoo.MockLeftTupleSink; +import org.drools.core.reteoo.ObjectTypeNode; +import org.drools.core.reteoo.SequenceNode; +import org.drools.core.reteoo.builder.BuildContext; +import org.drools.kiesession.session.StatefulKnowledgeSessionImpl; +import org.drools.mvel.integrationtests.phreak.A; +import org.junit.Test; +import org.kie.api.runtime.conf.ThreadSafeOption; + +import java.util.Collections; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TestMemories extends AbstractPhreakSequencerSubsequenceTest { + + @Test + public void testInitilisedMemoryBeforeStart() { + initKBaseWithEmptyRule(); + buildContext = new BuildContext(kbase, Collections.emptyList() ); + buildContext.setRule(rule); + + LogicGate gate1 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask), 0, + new int[] {0, 1}, // B and C + new int[] {0, 1}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate1.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit1 = new LogicCircuit(gate1); + + LogicGate gate2 = new LogicGate((inputMask, sourceMask) -> Gates.and(inputMask, sourceMask),1, + new int[] {1, 2}, // C and D, C Filter is re-used + new int[] {2, 3}, // Each SignalAdapter must be in a unique index for the Sequence + 0); + gate2.setOutput(TerminatingSignalProcessor.get()); + + LogicCircuit circuit2 = new LogicCircuit(gate2); + + seq0 = new Sequence(0, Step.of(circuit1), Step.of(circuit2)); + seq0.setFilters(new Pattern[]{bpattern, cpattern, dpattern}); + rule.addSequence(seq0); + kbase.addPackage(pkg); + + ObjectTypeNode aNode = kbase.getRete().getEntryPointNode(EntryPointId.DEFAULT).getObjectTypeNodes().get(new ClassObjectType(A.class)); + snode = (SequenceNode) aNode.getSinks()[0].getSinks()[0]; + + SessionConfiguration sessionConf = kbase.getSessionConfiguration(); + sessionConf.setOption(ThreadSafeOption.NO); + sessionConf.setClockType(ClockType.PSEUDO_CLOCK); + + session = (StatefulKnowledgeSessionImpl) kbase.newKieSession(sessionConf, null); + + InternalFactHandle fhA0 = (InternalFactHandle) session.insert(new A(0)); + nodeMemory = session.getNodeMemory(snode); + LeftTuple lt = new LeftTuple(fhA0, snode, true); + lt.setContextObject(snode.createSequencerMemory(lt, new MockLeftTupleSink(buildContext.getNextNodeId(), buildContext), nodeMemory)); + nodeMemory.getLeftTupleMemory().add(lt); + sequencerMemory = (SequencerMemory) lt.getContextObject(); + + SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq0); + + // make sure these are empty + assertThat(nodeMemory.getFilters()).usingRecursiveComparison().isEqualTo(new DynamicFilter[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(nodeMemory.getActiveFilters()).usingRecursiveComparison().isEqualTo(new LinkedList[3]); + assertThat(sequenceMemory.getActiveSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequenceMemory.getSignalAdapters()).usingRecursiveComparison().isEqualTo(new SignalAdapter[4]); + assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // sequence not yet started + } +}