use of org.drools.core.base.ClassObjectType in project drools by kiegroup.
the class RuleUnlinkingTest method setUp.
public void setUp(int type) {
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase();
buildContext = new BuildContext(kBase);
PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
liaNode = new LeftInputAdapterNode(5, otn, buildContext);
n1 = (BetaNode) createNetworkNode(10, type, liaNode, null);
n2 = (BetaNode) createNetworkNode(11, type, n1, null);
n3 = (BetaNode) createNetworkNode(12, type, n2, null);
rule1 = new RuleImpl("rule1");
rule1.setActivationListener("agenda");
rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
n4 = (BetaNode) createNetworkNode(13, type, n3, null);
n5 = (BetaNode) createNetworkNode(14, type, n4, null);
rule2 = new RuleImpl("rule2");
rule2.setActivationListener("agenda");
rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
n6 = (BetaNode) createNetworkNode(15, type, n5, null);
n7 = (BetaNode) createNetworkNode(16, type, n6, null);
n8 = (BetaNode) createNetworkNode(17, type, n7, null);
rule3 = new RuleImpl("rule3");
rule3.setActivationListener("agenda");
rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
// n1 -> n2 -> n3 -> r1
// \
// n4 -> n5 -> r2
// \
// n6 -> n7 -> n8 -> r3
liaNode.addAssociation(rule1);
liaNode.addAssociation(rule2);
liaNode.addAssociation(rule3);
n1.addAssociation(rule1);
n1.addAssociation(rule2);
n1.addAssociation(rule3);
n2.addAssociation(rule1);
n2.addAssociation(rule2);
n2.addAssociation(rule3);
n3.addAssociation(rule1);
n3.addAssociation(rule2);
n3.addAssociation(rule3);
n4.addAssociation(rule2);
n4.addAssociation(rule3);
n5.addAssociation(rule2);
n5.addAssociation(rule3);
n6.addAssociation(rule3);
n7.addAssociation(rule3);
n8.addAssociation(rule3);
}
use of org.drools.core.base.ClassObjectType in project drools by kiegroup.
the class RuleUnlinkingWithSegmentMemoryTest method setUp.
public void setUp(int type) {
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
buildContext = new BuildContext(kBase);
PropagationContextFactory pctxFactory = kBase.getConfiguration().getComponentFactory().getPropagationContextFactory();
context = pctxFactory.createPropagationContext(0, PropagationContext.Type.INSERTION, null, null, null);
ObjectTypeNode otn = new ObjectTypeNode(4, null, new ClassObjectType(String.class), buildContext);
lian = new LeftInputAdapterNode(5, otn, buildContext);
n1 = (BetaNode) createNetworkNode(10, type, lian, null);
n2 = (BetaNode) createNetworkNode(11, type, n1, null);
n3 = (BetaNode) createNetworkNode(12, type, n2, null);
rule1 = new RuleImpl("rule1");
rule1.setActivationListener("agenda");
rtn1 = (RuleTerminalNode) createNetworkNode(18, RULE_TERMINAL_NODE, n3, rule1);
n4 = (BetaNode) createNetworkNode(13, type, n3, null);
n5 = (BetaNode) createNetworkNode(14, type, n4, null);
rule2 = new RuleImpl("rule2");
rule2.setActivationListener("agenda");
rtn2 = (RuleTerminalNode) createNetworkNode(19, RULE_TERMINAL_NODE, n5, rule2);
n6 = (BetaNode) createNetworkNode(15, type, n5, null);
n7 = (BetaNode) createNetworkNode(16, type, n6, null);
n8 = (BetaNode) createNetworkNode(17, type, n7, null);
rule3 = new RuleImpl("rule3");
rule3.setActivationListener("agenda");
rtn3 = (RuleTerminalNode) createNetworkNode(20, RULE_TERMINAL_NODE, n8, rule3);
lian.addAssociation(rule1);
lian.addAssociation(rule2);
lian.addAssociation(rule3);
n1.addAssociation(rule1);
n1.addAssociation(rule2);
n1.addAssociation(rule3);
n2.addAssociation(rule1);
n2.addAssociation(rule2);
n2.addAssociation(rule3);
n3.addAssociation(rule1);
n3.addAssociation(rule2);
n3.addAssociation(rule3);
n4.addAssociation(rule2);
n4.addAssociation(rule3);
n5.addAssociation(rule2);
n5.addAssociation(rule3);
n6.addAssociation(rule3);
n7.addAssociation(rule3);
n8.addAssociation(rule3);
}
use of org.drools.core.base.ClassObjectType in project drools by kiegroup.
the class ReteooRuleBuilderTest method testAddRuleWithPatterns.
@Test
public void testAddRuleWithPatterns() {
final RuleImpl rule = new RuleImpl("only patterns");
final Pattern c1 = new Pattern(0, new ClassObjectType(String.class));
final Pattern c2 = new Pattern(1, new ClassObjectType(String.class));
final Pattern c3 = new Pattern(2, new ClassObjectType(String.class));
final GroupElement lhsroot = GroupElementFactory.newAndInstance();
lhsroot.addChild(c1);
lhsroot.addChild(c2);
lhsroot.addChild(c3);
rule.setLhs(lhsroot);
final Consequence consequence = new Consequence() {
public void evaluate(KnowledgeHelper knowledgeHelper, WorkingMemory workingMemory) throws Exception {
System.out.println("Consequence!");
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
}
public void writeExternal(ObjectOutput out) throws IOException {
}
public String getName() {
return "default";
}
};
rule.setConsequence(consequence);
final List terminals = this.builder.addRule(rule, this.rulebase);
assertEquals("Rule must have a single terminal node", 1, terminals.size());
final RuleTerminalNode terminal = (RuleTerminalNode) terminals.get(0);
}
use of org.drools.core.base.ClassObjectType in project drools by kiegroup.
the class RightTupleIndexHashTableTest method testSingleEntry.
@Test
public void testSingleEntry() throws Exception {
final InternalReadAccessor extractor = store.getReader(Cheese.class, "type");
final Pattern pattern = new Pattern(0, new ClassObjectType(Cheese.class));
final Declaration declaration = new Declaration("typeOfCheese", extractor, pattern);
final FieldIndex fieldIndex = new FieldIndex(extractor, declaration, MvelConstraint.INDEX_EVALUATOR);
final TupleIndexHashTable map = new TupleIndexHashTable(new FieldIndex[] { fieldIndex }, false);
final Cheese cheddar = new Cheese("cheddar", 10);
final InternalFactHandle cheddarHandle1 = new DefaultFactHandle(0, cheddar);
assertEquals(0, map.size());
assertNull(map.getFirst(new LeftTupleImpl(cheddarHandle1, null, true)));
final Cheese stilton1 = new Cheese("stilton", 35);
RightTuple stiltonRighTuple = new RightTupleImpl(new DefaultFactHandle(1, stilton1), null);
map.add(stiltonRighTuple);
assertEquals(1, map.size());
assertEquals(1, tablePopulationSize(map));
final Cheese stilton2 = new Cheese("stilton", 80);
final InternalFactHandle stiltonHandle2 = new DefaultFactHandle(2, stilton2);
final Tuple tuple = map.getFirst(new LeftTupleImpl(stiltonHandle2, null, true));
assertSame(stiltonRighTuple.getFactHandle(), tuple.getFactHandle());
assertNull(tuple.getNext());
}
use of org.drools.core.base.ClassObjectType in project drools by kiegroup.
the class RightTupleIndexHashTableTest method testTwoDifferentEntriesSameHashCode.
@Test
public void testTwoDifferentEntriesSameHashCode() throws Exception {
final InternalReadAccessor extractor = store.getReader(TestClass.class, "object");
final Pattern pattern = new Pattern(0, new ClassObjectType(TestClass.class));
final Declaration declaration = new Declaration("theObject", extractor, pattern);
final FieldIndex fieldIndex = new FieldIndex(extractor, declaration, MvelConstraint.INDEX_EVALUATOR);
final TupleIndexHashTable map = new TupleIndexHashTable(new FieldIndex[] { fieldIndex }, false);
final TestClass c1 = new TestClass(0, new TestClass(20, "stilton"));
final InternalFactHandle ch1 = new DefaultFactHandle(1, c1);
map.add(new RightTupleImpl(ch1, null));
final TestClass c2 = new TestClass(0, new TestClass(20, "cheddar"));
final InternalFactHandle ch2 = new DefaultFactHandle(2, c2);
map.add(new RightTupleImpl(ch2, null));
// same hashcode, but different values, so it should result in a size of 2
assertEquals(2, map.size());
// however both are in the same table bucket
assertEquals(1, tablePopulationSize(map));
// this table bucket will have two FieldIndexEntries, as they are actually two different values
Entry[] entries = getEntries(map);
assertEquals(1, entries.length);
TupleList list = (TupleList) entries[0];
assertSame(ch2, list.getFirst().getFactHandle());
assertNull(list.getFirst().getNext());
assertSame(ch1, list.getNext().getFirst().getFactHandle());
assertNull(list.getNext().getFirst().getNext());
assertNull(list.getNext().getNext());
}
Aggregations