use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class NodesPartitioningTest method checkNode.
private void checkNode(NetworkNode node) {
if (node instanceof EntryPointNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
} else if (node instanceof ObjectTypeNode) {
assertSame(RuleBasePartitionId.MAIN_PARTITION, node.getPartitionId());
checkPartitionedSinks((ObjectTypeNode) node);
} else if (node instanceof ObjectSource) {
ObjectSource source = ((ObjectSource) node).getParentObjectSource();
if (!(source instanceof ObjectTypeNode)) {
assertSame(source.getPartitionId(), node.getPartitionId());
}
} else if (node instanceof BetaNode) {
ObjectSource rightInput = ((BetaNode) node).getRightInput();
if (!(rightInput instanceof ObjectTypeNode)) {
assertSame(rightInput.getPartitionId(), node.getPartitionId());
}
LeftTupleSource leftInput = ((BetaNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
} else if (node instanceof TerminalNode) {
LeftTupleSource leftInput = ((TerminalNode) node).getLeftTupleSource();
assertSame(leftInput.getPartitionId(), node.getPartitionId());
}
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class ReteDumper method getSinks.
public static Sink[] getSinks(BaseNode node) {
Sink[] sinks = null;
if (node instanceof EntryPointNode) {
EntryPointNode source = (EntryPointNode) node;
Collection<ObjectTypeNode> otns = source.getObjectTypeNodes().values();
sinks = otns.toArray(new Sink[otns.size()]);
} else if (node instanceof ObjectSource) {
ObjectSource source = (ObjectSource) node;
sinks = source.getObjectSinkPropagator().getSinks();
} else if (node instanceof LeftTupleSource) {
LeftTupleSource source = (LeftTupleSource) node;
sinks = source.getSinkPropagator().getSinks();
}
return sinks;
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class RemoveRuleTest method testRemoveBigRule.
@Test
public void testRemoveBigRule() throws Exception {
// JBRULES-3496
final String str = "package org.drools.compiler.test\n" + "\n" + "declare SimpleFact\n" + " patientSpaceId : String\n" + " block : int\n" + "end\n" + "\n" + "declare SimpleMembership\n" + " patientSpaceId : String\n" + " listId : String\n" + "end\n" + "\n" + "declare SimplePatient\n" + " spaceId : String\n" + "end\n" + "\n" + "rule \"RTR - 47146 retract\"\n" + "agenda-group \"list membership\"\n" + "when\n" + " $listMembership0 : SimpleMembership( $listMembershipPatientSpaceIdRoot : patientSpaceId, ( listId != null && listId == \"47146\" ) )\n" + " not ( $patient0 : SimplePatient( $patientSpaceIdRoot : spaceId, spaceId != null && spaceId == $listMembershipPatientSpaceIdRoot ) \n" + " and ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 1 )\n" + " ) or ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 2 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 3 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 4 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 5 )\n" + " ) ) and ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 6 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 7 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 8 )\n" + " ) ) and ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 9 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 10 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 11 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 12 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 13 )\n" + " ) or ( (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 14 )\n" + " ) and (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 15 )\n" + " ) ) or ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 16 )\n" + " ) and ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 17 )\n" + " ) ) or ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 18 )\n" + " ) and (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 19 )\n" + " ) ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 20 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 21 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 22 )\n" + " ) or ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 23 )\n" + " ) and (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 24 )\n" + " ) ) ) and ( ( " + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 25 )\n" + " ) or (" + " SimpleFact( patientSpaceId == $patientSpaceIdRoot, block == 26 )\n" + " ) ) )\n" + "then\n" + "end\n";
final Collection<KiePackage> kpgs = loadKnowledgePackagesFromString(str);
assertEquals(1, kpgs.size());
final InternalKnowledgeBase kbase = (InternalKnowledgeBase) getKnowledgeBase();
kbase.addPackages(kpgs);
kbase.removeKiePackage(kpgs.iterator().next().getName());
final EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNodes().values().iterator().next();
for (final ObjectTypeNode otn : epn.getObjectTypeNodes().values()) {
final ObjectSink[] sinks = otn.getObjectSinkPropagator().getSinks();
if (sinks.length > 0) {
fail(otn + " has sinks " + Arrays.toString(sinks));
}
}
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class FactHandleMarshallingTest method createEventFactHandle.
private InternalFactHandle createEventFactHandle(StatefulKnowledgeSessionImpl wm, InternalKnowledgeBase kBase) {
// EntryPointNode
Rete rete = kBase.getRete();
NodeFactory nFacotry = kBase.getConfiguration().getComponentFactory().getNodeFactoryService();
RuleBasePartitionId partionId = RuleBasePartitionId.MAIN_PARTITION;
EntryPointNode entryPointNode = nFacotry.buildEntryPointNode(1, partionId, false, (ObjectSource) rete, EntryPointId.DEFAULT);
WorkingMemoryEntryPoint wmEntryPoint = new NamedEntryPoint(EntryPointId.DEFAULT, entryPointNode, wm);
EventFactHandle factHandle = new EventFactHandle(1, (Object) new Person(), 0, (new Date()).getTime(), 0, wmEntryPoint);
return factHandle;
}
use of org.drools.core.reteoo.EntryPointNode in project drools by kiegroup.
the class ParallelEvaluationTest method test.
@Test(timeout = 10000L)
public void test() {
StringBuilder sb = new StringBuilder(400);
sb.append("global java.util.List list;\n");
for (int i = 0; i < 10; i++) {
sb.append(getRule(i, ""));
}
KieBase kbase = new KieHelper().addContent(sb.toString(), ResourceType.DRL).build(MultithreadEvaluationOption.YES);
EntryPointNode epn = ((InternalKnowledgeBase) kbase).getRete().getEntryPointNode(EntryPointId.DEFAULT);
ObjectTypeNode otn = epn.getObjectTypeNodes().get(new ClassObjectType(Integer.class));
assertTrue(((CompositePartitionAwareObjectSinkAdapter) otn.getObjectSinkPropagator()).isHashed());
KieSession ksession = kbase.newKieSession();
assertTrue(((InternalWorkingMemory) ksession).getAgenda().isParallelAgenda());
List<Integer> list = new DebugList<Integer>();
ksession.setGlobal("list", list);
for (int i = 0; i < 10; i++) {
ksession.insert(i);
ksession.insert("" + i);
}
ksession.fireAllRules();
assertEquals(10, list.size());
}
Aggregations