Skip to content

Commit

Permalink
cleaned up abstract file
Browse files Browse the repository at this point in the history
  • Loading branch information
mdproctor committed Aug 15, 2024
1 parent 7cfaef2 commit 5fd8820
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.drools.core.impl.KnowledgeBaseImpl;
import org.drools.core.impl.RuleBaseFactory;
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;
Expand Down Expand Up @@ -113,29 +111,6 @@ public static BuildContext createContext() {
}

void createSession() {
SessionsAwareKnowledgeBase kbase = new SessionsAwareKnowledgeBase(buildContext.getRuleBase());
SessionConfiguration sessionConf = kbase.getSessionConfiguration();
sessionConf.setOption(ThreadSafeOption.NO);
sessionConf.setClockType(ClockType.PSEUDO_CLOCK);

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));
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void setup() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
}

private LogicCircuit getLogicCircuit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void setup() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
sequenceMemory = sequencerMemory.getSequenceMemory(seq0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void setup() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
}

private LogicCircuit getLogicCircuit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void setup() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
}

private LogicCircuit getLogicCircuit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public void testAnd() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c"));
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated

// reverse B and C
createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
fhC0 = (InternalFactHandle) session.insert(new C(0, "c"));

Expand All @@ -92,14 +92,14 @@ public void testOr() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();
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
createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhC0 = (InternalFactHandle) session.insert(new C(0, "c"));

Expand Down Expand Up @@ -131,7 +131,7 @@ public void testComposite() {
kbase.addPackage(pkg);

// D last
createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
Expand All @@ -143,7 +143,7 @@ public void testComposite() {
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(-1); // terminated

// change order, D first
createSession2();
createSession();
fhD0 = (InternalFactHandle) session.insert(new D(0, "d"));
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testSequenceLoopConstraint() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();

ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
assertThat(sequencerMemory.getSequenceMemory(seq0).getCount()).isEqualTo(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testSequenceTimeout() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService();
Expand All @@ -86,7 +86,7 @@ public void testSequenceComplete() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();

InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void testEventCountEqual() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0);
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testEventCountLessThan() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0);
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));

Expand All @@ -105,7 +105,7 @@ public void testEventCountLessThan() {

InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b"));

createSession2(); // fail
createSession(); // fail
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0);
fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));

Expand Down Expand Up @@ -135,7 +135,7 @@ public void testEventCountBetween() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2(); // pass
createSession(); // pass

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0);
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand All @@ -146,7 +146,7 @@ public void testEventCountBetween() {

InternalFactHandle fhB2 = (InternalFactHandle) session.insert(new B(2, "b"));

createSession2(); // fail
createSession(); // fail
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0);
fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));

Expand All @@ -173,7 +173,7 @@ public void testSingleOutputCounter() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2(); // pass
createSession(); // pass

SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq);

Expand Down Expand Up @@ -229,7 +229,7 @@ public void testCompositeInputAndOutputCounters() {
kbase.addPackage(pkg);

// D First
createSession2();
createSession();
SequenceMemory sequenceMemory = sequencerMemory.getSequenceMemory(seq);

InternalFactHandle fhD0 = (InternalFactHandle) session.insert(new D(0, "d"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testTimeout() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
PseudoClockScheduler pseudo = (PseudoClockScheduler) session.getTimerService();
Expand All @@ -76,7 +76,7 @@ public void testTimeout() {
session.fireAllRules(); // if the rest of the system is immediate, why isn't this?
assertThat(pseudo.getQueue().size()).isEqualTo(0);

createSession2();
createSession();
assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
pseudo = (PseudoClockScheduler) session.getTimerService();
Expand Down Expand Up @@ -110,7 +110,7 @@ public void testTimeoutWithCountFailure() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand Down Expand Up @@ -154,7 +154,7 @@ public void testDelayFromActivation() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand All @@ -165,7 +165,7 @@ public void testDelayFromActivation() {
session.fireAllRules(); // if the rest of the system is immediate, why isn't this?
assertThat(pseudo.getQueue().size()).isEqualTo(0);

createSession2();
createSession();

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand Down Expand Up @@ -194,7 +194,7 @@ public void testDelayFromMatch() {
rule.addSequence(seq);
kbase.addPackage(pkg);

createSession2();
createSession();

assertThat(sequencerMemory.getCurrentStep()).isEqualTo(0); // step 0
InternalFactHandle fhB0 = (InternalFactHandle) session.insert(new B(0, "b"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testSubSequence() {
seq2.setController(new LoopController(m -> m.getCount() < 2));
kbase.addPackage(pkg);

createSession2();
createSession();

ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
assertThat(stack.size()).isEqualTo(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void setup() {
rule.addSequence(seq0);
kbase.addPackage(pkg);

createSession2();
createSession();
}

private static LogicGate get1InputLogicGate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public void setup() {
@Test
public void testSubSequenceFailSeq1() {
seq1.setController(new TimoutController(new DurationTimer(1000)));
createSession2();
createSession();

ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
assertThat(stack.size()).isEqualTo(2);
Expand All @@ -108,7 +108,7 @@ public void testSubSequenceFailSeq1() {
public void testSubSequenceFailSeq2() {
seq1.setController(new TimoutController(new DurationTimer(1000)));
seq2.setController(new TimoutController(new DurationTimer(1000)));
createSession2();
createSession();

ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
assertThat(stack.size()).isEqualTo(2);
Expand Down Expand Up @@ -139,7 +139,7 @@ public void testSubSequenceFailSeq2() {
public void testSubSequenceComplete() {
seq1.setController(new TimoutController(new DurationTimer(1000)));
seq2.setController(new TimoutController(new DurationTimer(1000)));
createSession2();
createSession();

ArrayList<SequenceMemory> stack = sequencerMemory.getSequenceStack();
assertThat(stack.size()).isEqualTo(2);
Expand Down

0 comments on commit 5fd8820

Please sign in to comment.