Skip to content

Commit

Permalink
[DROOLS-653] avoid wrapping the LeftTuple created by a subnetwork int…
Browse files Browse the repository at this point in the history
…o a RightTuple
  • Loading branch information
mariofusco committed Jan 7, 2016
1 parent 9722824 commit c87ce8f
Show file tree
Hide file tree
Showing 50 changed files with 749 additions and 411 deletions.
Expand Up @@ -817,7 +817,7 @@ public void testAccumulateMaxMVEL() throws Exception {
execTestAccumulateMax( "test_AccumulateMaxMVEL.drl" );
}

@Test(timeout = 10000)
@Test//(timeout = 10000)
public void testAccumulateMultiPatternJava() throws Exception {
execTestAccumulateReverseModifyMultiPattern( "test_AccumulateMultiPattern.drl" );
}
Expand Down Expand Up @@ -1421,13 +1421,13 @@ public void execTestAccumulateReverseModifyMultiPattern( String fileName ) throw
wm.setGlobal( "results",
results );

final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
10 ), new Cheese( "stilton",
2 ), new Cheese( "stilton",
5 ), new Cheese( "brie",
15 ), new Cheese( "brie",
16 ), new Cheese( "provolone",
8 )};
final Cheese[] cheese = new Cheese[]{ new Cheese( "stilton", 10 ),
new Cheese( "stilton", 2 ),
new Cheese( "stilton", 5 ),
new Cheese( "brie", 15 ),
new Cheese( "brie", 16 ),
new Cheese( "provolone", 8 ) };

final Person bob = new Person( "Bob",
"stilton" );
final Person mark = new Person( "Mark",
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.drools.core.reteoo.RightInputAdapterNode;
import org.junit.Test;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import org.kie.api.runtime.rule.LiveQuery;
import org.kie.api.runtime.rule.QueryResults;
Expand All @@ -52,6 +53,7 @@
import org.kie.internal.definition.KnowledgePackage;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.internal.utils.KieHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -2131,7 +2133,7 @@ public void testCompile() throws IOException, ClassNotFoundException {
KnowledgeBase kbase = SerializationHelper.serializeObject( loadKnowledgeBaseFromString( drl ) );
}

@Test (timeout = 10000)
@Test(timeout = 10000)
public void testInsertionOrderTwo() throws Exception {
String str = "" +
"package org.drools.compiler.test \n" +
Expand Down Expand Up @@ -3258,5 +3260,53 @@ public void testQueryWithEvents() {

}

@Test
public void testNpeOnQuery() {
String drl =
"global java.util.List list; " +
"query foo( Integer $i ) " +
" $i := Integer( this < 10 ) " +
"end\n" +
"\n" +

"rule r1 when " +
" foo( $i ; ) " +
" Integer( this == 10 ) " +
"then " +
" System.out.println(\"10 \" + $i);" +
" list.add( 10 );\n" +
"end\n" +
"\n" +

"rule r2 when " +
" foo( $i; ) " +
" Integer( this == 20 ) " +
"then " +
" System.out.println(\"20 \" + $i);" +
" list.add( 20 );\n" +
"end\n" +

"rule r3 when " +
" $i : Integer( this == 1 ) " +
"then " +
" System.out.println($i);" +
" update( kcontext.getKieRuntime().getFactHandle( $i ), $i + 1 );" +
"end\n" +
"\n";

KieHelper helper = new KieHelper();
helper.addContent( drl, ResourceType.DRL );
KieSession kieSession = helper.build().newKieSession();

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

kieSession.insert( 1 );
kieSession.insert( 20 );

kieSession.fireAllRules();

assertEquals( 1, list.size() );
assertEquals( 20, (int)list.get(0) );
}
}
Expand Up @@ -2456,4 +2456,87 @@ public void testRuleRemovalWithOR() throws Exception {

ksession.fireAllRules();
}

@Test
public void testSplitAfterQuery() throws Exception {
String drl1 =
"global java.util.List list; " +
"query foo( Integer $i ) " +
" $i := Integer( this < 10 ) " +
"end\n" +
"\n" +

"rule r2 when " +
" foo( $i; ) " +
" Integer( this == 20 ) " +
"then " +
" System.out.println(\"20 \" + $i);" +
" list.add( 20 + $i );\n" +
"end\n" +

"rule r3 when " +
" $i : Integer( this == 1 ) " +
"then " +
" System.out.println($i);" +
" update( kcontext.getKieRuntime().getFactHandle( $i ), $i + 1 );" +
"end\n" +
"\n";

String drl2 =
"global java.util.List list; " +
"query foo( Integer $i ) " +
" $i := Integer( this < 10 ) " +
"end\n" +
"\n" +

"rule r1 when " +
" foo( $i ; ) " +
" Integer( this == 10 ) " +
"then " +
" System.out.println(\"10 \" + $i);" +
" list.add( 10 + $i );\n" +
"end\n" +

"rule r2 when " +
" foo( $i; ) " +
" Integer( this == 20 ) " +
"then " +
" System.out.println(\"20 \" + $i);" +
" list.add( 20 + $i );\n" +
"end\n" +

"rule r3 when " +
" $i : Integer( this == 1 ) " +
"then " +
" System.out.println($i);" +
" update( kcontext.getKieRuntime().getFactHandle( $i ), $i + 1 );" +
"end\n" +
"\n";

KieServices ks = KieServices.Factory.get();

ReleaseId releaseId1 = ks.newReleaseId( "org.kie", "test-upgrade", "1.1.1" );
KieModule km = createAndDeployJar( ks, releaseId1, drl1 );

KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();

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

ksession.insert( 1 );
ksession.insert( 20 );

ksession.fireAllRules();

ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar( ks, releaseId2, drl2 );
kc.updateToVersion(releaseId2);

ksession.fireAllRules();

assertEquals( 2, list.size() );
assertEquals( 21, (int)list.get(0) );
assertEquals( 22, (int)list.get(1) );
}
}
Expand Up @@ -884,11 +884,11 @@ public void testDynamicAddRule() {
ksession.insert( new A( 2, 2, 2, 2 ) );

LeftTuple leftTuple = ( (DefaultFactHandle) fh ).getFirstLeftTuple();
ObjectTypeNode.Id letTupleOtnId = leftTuple.getTupleSink().getLeftInputOtnId();
ObjectTypeNode.Id letTupleOtnId = leftTuple.getInputOtnId();
leftTuple = leftTuple.getHandleNext();
while ( leftTuple != null ) {
assertTrue( letTupleOtnId.before( leftTuple.getTupleSink().getLeftInputOtnId() ) );
letTupleOtnId = leftTuple.getTupleSink().getLeftInputOtnId();
assertTrue( letTupleOtnId.before( leftTuple.getInputOtnId() ) );
letTupleOtnId = leftTuple.getInputOtnId();
leftTuple = leftTuple.getHandleNext();
}
}
Expand Down Expand Up @@ -6744,11 +6744,11 @@ public void testNotWithSubNetwork() {
ksession.insert( "1" );
FactHandle iFH = ksession.insert( 1 );
FactHandle lFH = ksession.insert( 1L );
ksession.fireAllRules();
assertEquals( 0, ksession.fireAllRules() );

ksession.delete( iFH );
ksession.delete( lFH );
ksession.fireAllRules();
assertEquals( 1, ksession.fireAllRules() );

assertEquals( 0, ksession.getFactCount() );
}
Expand Down
23 changes: 1 addition & 22 deletions drools-core/src/main/java/org/drools/core/base/DroolsQuery.java
Expand Up @@ -44,7 +44,7 @@ public final class DroolsQuery extends ArrayElements {

private WorkingMemoryAction action;

private TupleSets<LeftTuple> resultLeftTuples;
private final TupleSets<LeftTuple> resultLeftTuples;

private QueryElementNodeMemory qmem;

Expand All @@ -54,24 +54,6 @@ public final class DroolsQuery extends ArrayElements {

private LeftTupleSink sink;

// public DroolsQuery(DroolsQuery droolsQuery) {
// super( new Object[droolsQuery.getElements().length] );
//
// this.name = droolsQuery.getName();
// this.resultsCollector = droolsQuery.getQueryResultCollector();
// this.open = droolsQuery.isOpen();
// final Object[] params = getElements();
// System.arraycopy( droolsQuery.getElements(), 0, params, 0, params.length );
// originalDroolsQuery = droolsQuery;
// }

public DroolsQuery(final String name,
final Object[] params,
final InternalViewChangedEventListener resultsCollector,
final boolean open) {
this(name, params, resultsCollector, open, null, null, null, null, null);
}

public DroolsQuery(final String name,
final Object[] params,
final InternalViewChangedEventListener resultsCollector,
Expand Down Expand Up @@ -207,7 +189,4 @@ public String toString() {
", args=" + Arrays.toString( getElements() ) +
", vars=" + Arrays.toString( vars ) + "]";
}



}
Expand Up @@ -39,6 +39,8 @@ public interface TupleSets<T extends Tuple> {

void addAll(TupleSets<T> source);

void addTo(TupleSets<T> target);

TupleSets<T> takeAll();

boolean isEmpty();
Expand Down

0 comments on commit c87ce8f

Please sign in to comment.