use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testProgrammaticPropertiesFile.
@Test
public void testProgrammaticPropertiesFile() {
RuleBaseConfiguration cfg = new RuleBaseConfiguration();
assertEquals(true, cfg.isIndexLeftBetaMemory());
Properties properties = new Properties();
properties.setProperty("drools.indexLeftBetaMemory", "false");
cfg = new RuleBaseConfiguration(properties);
assertEquals(false, cfg.isIndexLeftBetaMemory());
System.getProperties().remove("drools.indexLeftBetaMemory");
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class RuleBaseConfigurationTest method testSequential.
@Test
public void testSequential() {
Properties properties = new Properties();
properties.setProperty("drools.sequential", "false");
RuleBaseConfiguration cfg = new RuleBaseConfiguration(properties);
assertFalse(cfg.isSequential());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "sequential");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.SEQUENTIAL, cfg.getSequentialAgenda());
properties = new Properties();
properties.setProperty("drools.sequential.agenda", "dynamic");
properties.setProperty("drools.sequential", "true");
cfg = new RuleBaseConfiguration(properties);
assertTrue(cfg.isSequential());
assertEquals(SequentialAgenda.DYNAMIC, cfg.getSequentialAgenda());
assertTrue(cfg.getAgendaGroupFactory() instanceof PriorityQueueAgendaGroupFactory);
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class LeftLeftTupleIndexHashTableIteratorTest 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);
InternalKnowledgeBase kBase = (InternalKnowledgeBase) 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.getLeftTupleMemory().add(new LeftTupleImpl(fh1, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh2, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh3, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh4, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh5, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh6, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh7, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh8, null, true));
betaMemory.getLeftTupleMemory().add(new LeftTupleImpl(fh9, null, true));
TupleIndexHashTable hashTable = (TupleIndexHashTable) betaMemory.getLeftTupleMemory();
// can't create a 0 hashCode, so forcing
TupleList leftTupleList = new TupleList();
leftTupleList.add(new LeftTupleImpl(fh10, null, true));
hashTable.getTable()[0] = leftTupleList;
leftTupleList = new TupleList();
leftTupleList.add(new LeftTupleImpl(fh11, null, true));
leftTupleList.add(new LeftTupleImpl(fh12, null, true));
leftTupleList.add(new LeftTupleImpl(fh13, null, true));
((TupleList) hashTable.getTable()[0]).setNext(leftTupleList);
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());
// This tests the hashcode index allocation. If the rehash function (or any other way hashcodes are computed) changes, these numbers will change.
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.getLeftTupleMemory().iterator();
for (LeftTupleImpl leftTuple = (LeftTupleImpl) it.next(); leftTuple != null; leftTuple = (LeftTupleImpl) it.next()) {
list.add(leftTuple);
}
assertEquals(13, list.size());
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class BaseBetaConstraintsTest method checkBetaConstraints.
protected void checkBetaConstraints(BetaNodeFieldConstraint[] constraints, Class cls, short betaNodeType) {
RuleBaseConfiguration config = new RuleBaseConfiguration();
int depth = config.getCompositeKeyDepth();
BetaConstraints betaConstraints;
try {
betaConstraints = (BetaConstraints) cls.getConstructor(new Class[] { BetaNodeFieldConstraint[].class, RuleBaseConfiguration.class }).newInstance(constraints, config);
} catch (Exception e) {
throw new RuntimeException("could not invoke constructor for " + cls.getName());
}
betaConstraints.initIndexes(depth, betaNodeType);
// BetaConstraints betaConstraints = new DefaultBetaConstraints(constraints, config );
constraints = betaConstraints.getConstraints();
List<Integer> list = new ArrayList<Integer>();
// get indexed positions
for (int i = 0; i < constraints.length && list.size() < depth; i++) {
if (((IndexableConstraint) constraints[i]).isIndexable(betaNodeType)) {
list.add(i);
}
}
// convert to array
int[] indexedPositions = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
indexedPositions[i] = i;
}
assertEquals((indexedPositions.length > 0), betaConstraints.isIndexed());
assertEquals(indexedPositions.length, betaConstraints.getIndexCount());
BetaMemory betaMemory = betaConstraints.createBetaMemory(config, NodeTypeEnums.JoinNode);
if (indexedPositions.length > 0) {
if (((IndexableConstraint) constraints[indexedPositions[0]]).getConstraintType() == ConstraintType.EQUAL) {
TupleIndexHashTable tupleHashTable = (TupleIndexHashTable) betaMemory.getLeftTupleMemory();
assertTrue(tupleHashTable.isIndexed());
Index index = tupleHashTable.getIndex();
for (int i = 0; i < indexedPositions.length; i++) {
checkSameConstraintForIndex((IndexableConstraint) constraints[indexedPositions[i]], index.getFieldIndex(i));
}
TupleIndexHashTable factHashTable = (TupleIndexHashTable) betaMemory.getRightTupleMemory();
assertTrue(factHashTable.isIndexed());
index = factHashTable.getIndex();
for (int i = 0; i < indexedPositions.length; i++) {
checkSameConstraintForIndex((IndexableConstraint) constraints[indexedPositions[i]], index.getFieldIndex(i));
}
} else {
}
} else {
TupleList tupleHashTable = (TupleList) betaMemory.getLeftTupleMemory();
assertFalse(tupleHashTable.isIndexed());
TupleList factHashTable = (TupleList) betaMemory.getRightTupleMemory();
assertFalse(factHashTable.isIndexed());
}
}
use of org.drools.core.RuleBaseConfiguration in project drools by kiegroup.
the class ScenarioTest method createContext.
public BuildContext createContext() {
RuleBaseConfiguration conf = new RuleBaseConfiguration();
KnowledgeBaseImpl rbase = new KnowledgeBaseImpl("ID", conf);
BuildContext buildContext = new BuildContext(rbase);
RuleImpl rule = new RuleImpl("rule1").setPackage("org.pkg1");
InternalKnowledgePackage pkg = new KnowledgePackageImpl("org.pkg1");
pkg.getDialectRuntimeRegistry().setDialectData("mvel", new MVELDialectRuntimeData());
pkg.addRule(rule);
buildContext.setRule(rule);
return buildContext;
}
Aggregations