Skip to content

Commit

Permalink
JBRULES-3055: fixing concurrent modification exception
Browse files Browse the repository at this point in the history
  • Loading branch information
etirelli committed Jun 9, 2011
1 parent d34fb6e commit 55e5c13
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -998,7 +999,8 @@ private void createImplicitBindings( final RuleBuildContext context,
final Set<String> unboundIdentifiers,
final BoundIdentifiers boundIdentifiers,
final List factDeclarations ) {
for ( String identifier : unboundIdentifiers ) {
for ( Iterator<String> it = unboundIdentifiers.iterator(); it.hasNext(); ) {
String identifier = it.next();
Declaration declaration = createDeclarationObject( context,
identifier,
pattern );
Expand All @@ -1015,8 +1017,7 @@ private void createImplicitBindings( final RuleBuildContext context,
declaration );
boundIdentifiers.getDeclrClasses().put( identifier,
declaration.getExtractor().getExtractToClass() );
unboundIdentifiers.remove( identifier );

it.remove();
}
}
}
Expand Down
Expand Up @@ -4604,7 +4604,7 @@ public void testEvalInline() throws Exception {
"rule \"inline eval\"\n" +
"when\n" +
" $str : String()\n" +
" Person( eval( name.startsWith($str) && name.endsWith($str)) )\n" +
" Person( eval( name.startsWith($str) && age == 18) )\n" +
"then\n" +
"end";
KnowledgeBase kbase = loadKnowledgeBaseFromString( text );
Expand All @@ -4626,6 +4626,51 @@ public void testEvalInline() throws Exception {

}

@Test
@Ignore( "Requires fixing of mvel regression reported at https://github.com/mvel/mvel/pull/4")
public void testMethodCalls() throws Exception {
final String text = "package org.drools\n" +
"rule \"method calls\"\n" +
"when\n" +
" Person( getName().substring(2) == 'b' )\n" +
"then\n" +
"end";
KnowledgeBase kbase = loadKnowledgeBaseFromString( text );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

ksession.insert( new Person( "mark",
50 ) );
int rules = ksession.fireAllRules();
assertEquals( 0,
rules );

ksession.insert( new Person( "bob",
18 ) );
rules = ksession.fireAllRules();
assertEquals( 1,
rules );

}

@Test
public void testAlphaExpression() throws Exception {
final String text = "package org.drools\n" +
"rule \"alpha\"\n" +
"when\n" +
" Person( 5 < 6 )\n" +
"then\n" +
"end";
KnowledgeBase kbase = loadKnowledgeBaseFromString( text );
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();

ksession.insert( new Person( "mark",
50 ) );
int rules = ksession.fireAllRules();
assertEquals( 1,
rules );

}

@Test
public void testEvalCE() throws Exception {
final String text = "package org.drools\n" +
Expand Down

0 comments on commit 55e5c13

Please sign in to comment.