use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class TraitTest method testTMSConsistencyWithNonTraitableBeans.
@Test(timeout = 10000)
public void testTMSConsistencyWithNonTraitableBeans() {
String s1 = "package org.drools.test;\n" + "import org.drools.compiler.Person; \n" + "import org.drools.core.factmodel.traits.Traitable; \n" + "" + "declare Person @Traitable end \n" + "" + "rule \"Init\"\n" + "when\n" + "then\n" + " insertLogical( new Person( \"x\", 18 ) );\n" + "end\n" + "\n" + "declare trait Student\n" + " age : int\n" + " name : String\n" + "end\n" + "\n" + "rule \"Trait\"\n" + "when\n" + " $p : Person( )\n" + "then\n" + " don( $p, Student.class, true );\n" + "end\n";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(s1.getBytes()), ResourceType.DRL);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
TraitFactory.setMode(mode, ksession.getKieBase());
ksession.fireAllRules();
FactHandle personHandle = ksession.getFactHandles(new ClassObjectFilter(Person.class)).iterator().next();
InternalFactHandle h = ((InternalFactHandle) personHandle);
ObjectTypeConfigurationRegistry reg = h.getEntryPoint().getObjectTypeConfigurationRegistry();
ObjectTypeConf conf = reg.getObjectTypeConf(h.getEntryPoint().getEntryPoint(), ((InternalFactHandle) personHandle).getObject());
assertTrue(conf.isTMSEnabled());
ksession.dispose();
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class MarshallerTest method testOrderFacts.
@Test
public void testOrderFacts() throws Exception {
List<InternalFactHandle> list = new ArrayList<InternalFactHandle>();
List<Integer> ids = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 30, 31, 32, -2147483640, 7, 8, 9, 10, 11, 12, 13, 14, 15, 28, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
for (Integer i : ids) {
list.add(new DefaultFactHandle(i.intValue(), i));
}
InternalFactHandle first = ProtobufOutputMarshaller.orderFacts(list)[0];
assertEquals(-2147483640, first.getId());
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class MockObjectSource method updateSink.
public void updateSink(final ObjectSink sink, final PropagationContext context, final InternalWorkingMemory workingMemory) {
this.updated++;
for (final Iterator it = this.facts.iterator(); it.hasNext(); ) {
final InternalFactHandle handle = (InternalFactHandle) it.next();
sink.assertObject(handle, context, workingMemory);
}
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class NodeSegmentUnlinkingTest method testLiaNodeLinking.
@Test
public void testLiaNodeLinking() {
setUp(JOIN_NODE);
// Initialise from lian
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
InternalKnowledgeBase kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
SegmentUtilities.createSegmentMemory(liaNode, ksession);
InternalFactHandle fh1 = (InternalFactHandle) ksession.insert("str1");
n1.assertObject(fh1, context, ksession);
LiaNodeMemory liaMem = (LiaNodeMemory) ksession.getNodeMemory(liaNode);
assertEquals(1, liaMem.getNodePosMaskBit());
assertEquals(3, liaMem.getSegmentMemory().getAllLinkedMaskTest());
BetaMemory bm1 = (BetaMemory) ksession.getNodeMemory(n1);
assertEquals(2, bm1.getNodePosMaskBit());
assertEquals(3, bm1.getSegmentMemory().getAllLinkedMaskTest());
// still unlinked
assertFalse(liaMem.getSegmentMemory().isSegmentLinked());
// now linked
InternalFactHandle fh2 = (InternalFactHandle) ksession.insert("str2");
liaNode.assertObject(fh2, context, ksession);
assertTrue(liaMem.getSegmentMemory().isSegmentLinked());
// test unlink after one retract
liaNode.retractLeftTuple(fh2.getFirstLeftTuple(), context, ksession);
assertFalse(liaMem.getSegmentMemory().isSegmentLinked());
// check counter, after multiple asserts
InternalFactHandle fh3 = (InternalFactHandle) ksession.insert("str3");
InternalFactHandle fh4 = (InternalFactHandle) ksession.insert("str4");
liaNode.assertObject(fh3, context, ksession);
liaNode.assertObject(fh4, context, ksession);
assertTrue(liaMem.getSegmentMemory().isSegmentLinked());
liaNode.retractLeftTuple(fh3.getFirstLeftTuple(), context, ksession);
assertTrue(liaMem.getSegmentMemory().isSegmentLinked());
liaNode.retractLeftTuple(fh4.getFirstLeftTuple(), context, ksession);
assertFalse(liaMem.getSegmentMemory().isSegmentLinked());
}
use of org.drools.core.common.InternalFactHandle in project drools by kiegroup.
the class RightTupleIndexHashTableIteratorTest method test1.
@Test
public void test1() {
BetaNodeFieldConstraint constraint0 = getConstraint("d", Operator.EQUAL, "this", Foo.class);
BetaNodeFieldConstraint[] constraints = new BetaNodeFieldConstraint[] { constraint0 };
RuleBaseConfiguration config = new RuleBaseConfiguration();
BetaConstraints betaConstraints = null;
betaConstraints = new SingleBetaConstraints(constraints, config);
BetaMemory betaMemory = betaConstraints.createBetaMemory(config, NodeTypeEnums.JoinNode);
KieBase kBase = KnowledgeBaseFactory.newKnowledgeBase();
KieSession ss = kBase.newKieSession();
InternalFactHandle fh1 = (InternalFactHandle) ss.insert(new Foo("brie", 1));
InternalFactHandle fh2 = (InternalFactHandle) ss.insert(new Foo("brie", 1));
InternalFactHandle fh3 = (InternalFactHandle) ss.insert(new Foo("soda", 1));
InternalFactHandle fh4 = (InternalFactHandle) ss.insert(new Foo("soda", 1));
InternalFactHandle fh5 = (InternalFactHandle) ss.insert(new Foo("bread", 3));
InternalFactHandle fh6 = (InternalFactHandle) ss.insert(new Foo("bread", 3));
InternalFactHandle fh7 = (InternalFactHandle) ss.insert(new Foo("cream", 3));
InternalFactHandle fh8 = (InternalFactHandle) ss.insert(new Foo("gorda", 15));
InternalFactHandle fh9 = (InternalFactHandle) ss.insert(new Foo("beer", 16));
InternalFactHandle fh10 = (InternalFactHandle) ss.insert(new Foo("mars", 0));
InternalFactHandle fh11 = (InternalFactHandle) ss.insert(new Foo("snicker", 0));
InternalFactHandle fh12 = (InternalFactHandle) ss.insert(new Foo("snicker", 0));
InternalFactHandle fh13 = (InternalFactHandle) ss.insert(new Foo("snicker", 0));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh1, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh2, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh3, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh4, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh5, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh6, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh7, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh8, null));
betaMemory.getRightTupleMemory().add(new RightTupleImpl(fh9, null));
TupleIndexHashTable hashTable = (TupleIndexHashTable) betaMemory.getRightTupleMemory();
// can't create a 0 hashCode, so forcing
TupleList rightTupleList = new TupleList();
rightTupleList.add(new RightTupleImpl(fh10, null));
hashTable.getTable()[0] = rightTupleList;
rightTupleList = new TupleList();
rightTupleList.add(new RightTupleImpl(fh11, null));
rightTupleList.add(new RightTupleImpl(fh12, null));
rightTupleList.add(new RightTupleImpl(fh13, null));
((TupleList) hashTable.getTable()[0]).setNext(rightTupleList);
Entry[] table = hashTable.getTable();
List list = new ArrayList();
for (int i = 0; i < table.length; i++) {
if (table[i] != null) {
List entries = new ArrayList();
entries.add(i);
Entry entry = table[i];
while (entry != null) {
entries.add(entry);
entry = entry.getNext();
}
list.add(entries.toArray());
}
}
assertEquals(5, list.size());
Object[] entries = (Object[]) list.get(0);
assertEquals(0, entries[0]);
assertEquals(3, entries.length);
entries = (Object[]) list.get(1);
assertEquals(102, entries[0]);
assertEquals(2, entries.length);
entries = (Object[]) list.get(2);
assertEquals(103, entries[0]);
assertEquals(2, entries.length);
entries = (Object[]) list.get(3);
assertEquals(115, entries[0]);
assertEquals(3, entries.length);
entries = (Object[]) list.get(4);
assertEquals(117, entries[0]);
assertEquals(3, entries.length);
// System.out.println( entries );
list = new ArrayList<LeftTupleImpl>();
Iterator it = betaMemory.getRightTupleMemory().iterator();
for (RightTuple rightTuple = (RightTuple) it.next(); rightTuple != null; rightTuple = (RightTuple) it.next()) {
list.add(rightTuple);
}
assertEquals(13, list.size());
}
Aggregations