Skip to content

Commit

Permalink
[BZ-1089285] fix evals when used inside subnetworks
Browse files Browse the repository at this point in the history
  • Loading branch information
mariofusco committed Apr 22, 2014
1 parent a36b963 commit 0a80dc9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5570,4 +5570,42 @@ public void setDescription(final String desc) {
this.description = desc;
}
}

@Test
public void testEvalInSubnetwork() {
// DROOLS-460
String str = "global java.util.List list;\n" +
"\n" +
"declare StatusEvent\n" +
"@role(event)\n" +
"timestamp : int\n" +
"end\n" +
"\n" +
"rule R when\n" +
"$i : Integer()\n" +
"eval(true)\n" +
"exists(\n" +
"Integer(intValue > $i.intValue)\n" +
"and eval(true)\n" +
")\n" +
"then\n" +
"list.add($i.intValue());\n" +
"end";

KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write( "src/main/resources/r1.drl", str );
ks.newKieBuilder( kfs ).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();

List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);

ksession.insert(0);
ksession.fireAllRules();
ksession.insert(1);
ksession.fireAllRules();

assertEquals(1, list.size());
assertEquals(0, (int)list.get(0));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.drools.core.common;

import org.drools.core.phreak.RightTupleEntry;
import org.drools.core.phreak.TupleEntry;

public class TupleEntryQueueImpl implements TupleEntryQueue {
Expand All @@ -11,11 +10,6 @@ public class TupleEntryQueueImpl implements TupleEntryQueue {
private TupleEntry tail;

public synchronized boolean add(TupleEntry entry) {
/*
if (entry.toString().contains("SynthEvent")) {
new RuntimeException("" + size).printStackTrace();
}
*/
if (head == null) {
head = entry;
tail = entry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package org.drools.core.common;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import org.drools.core.reteoo.LeftTuple;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.Declaration;
import org.drools.core.spi.BetaNodeFieldConstraint;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
* Checks if one tuple is the start subtuple of other tuple.
* For instance, if we have two tuples:
Expand Down Expand Up @@ -96,7 +96,7 @@ public boolean isAllowedCachedLeft(final ContextEntry context,

public boolean isAllowedCachedRight(final LeftTuple tuple,
final ContextEntry context) {
return tuple.equals( ((TupleStartEqualsConstraintContextEntry) context).right.getSubTuple( tuple.size() ) );
return tuple.skipEmptyHandles().equals( ((TupleStartEqualsConstraintContextEntry) context).right.getSubTuple( tuple.size() ) );
}

public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,14 @@ public LeftTuple getSubTuple(final int elements) {
return entry;
}

public LeftTuple skipEmptyHandles() {
LeftTuple entry = this;
while ( entry != null && entry.getLastHandle() == null ) {
entry = entry.getParent();
}
return entry;
}

/* (non-Javadoc)
* @see org.kie.reteoo.LeftTuple#toObjectArray()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public interface LeftTuple
*/
LeftTuple getSubTuple(final int elements);

LeftTuple skipEmptyHandles();

Object[] toObjectArray();

LeftTuple getParent();
Expand Down

0 comments on commit 0a80dc9

Please sign in to comment.