Index: drools-compiler/src/test/java/org/drools/ExpensiveCheese.java =================================================================== --- drools-compiler/src/test/java/org/drools/ExpensiveCheese.java (revision 16463) +++ drools-compiler/src/test/java/org/drools/ExpensiveCheese.java (working copy) @@ -19,66 +19,39 @@ * limitations under the License. */ -public class Cheese - implements - Serializable { +public class ExpensiveCheese + extends + Cheese { - public static final String STILTON = "stilton"; + private long longPrice; - /** - * - */ - private static final long serialVersionUID = 400L; - private String type; - private int price; - private int oldPrice; - private Date usedBy; + public ExpensiveCheese() { - public Cheese() { - } - public Cheese(final String type, - final int price) { - super(); - this.type = type; - this.price = price; + public ExpensiveCheese(final String type, + final long longPrice) { + super(type, (int) longPrice); + this.longPrice = longPrice; } - public Cheese(final String type, - final int price, - final int oldPrice ) { - super(); - this.type = type; - this.price = price; - this.oldPrice = oldPrice; + public long getLongPrice() { + return longPrice; } - public int getPrice() { - return this.price; + public void setLongPrice(long longPrice) { + this.longPrice = longPrice; } - public String getType() { - return this.type; - } - - public void setType(final String type) { - this.type = type; - } - - public void setPrice(final int price) { - this.price = price; - } - public String toString() { - return "Cheese( type='" + this.type + "', price=" + this.price + " )"; + return super.toString() + "&( longPrice=" + this.longPrice + " )"; } public int hashCode() { final int PRIME = 31; int result = 1; - result = PRIME * result + price; - result = PRIME * result + ((type == null) ? 0 : type.hashCode()); + result = PRIME * result + super.hashCode(); + result = PRIME * result + ((int) longPrice); return result; } @@ -86,30 +59,10 @@ if ( this == obj ) return true; if ( obj == null ) return false; if ( getClass() != obj.getClass() ) return false; - final Cheese other = (Cheese) obj; - if ( price != other.price ) return false; - if ( type == null ) { - if ( other.type != null ) return false; - } else if ( !type.equals( other.type ) ) return false; + final ExpensiveCheese other = (ExpensiveCheese) obj; + if (!super.equals(obj)) return false; + if ( longPrice != other.longPrice ) return false; return true; } - public int getOldPrice() { - return oldPrice; - } - - public void setOldPrice(int oldPrice) { - this.oldPrice = oldPrice; - } - - public Date getUsedBy() { - return usedBy; - } - - public void setUsedBy(Date usedBy) { - this.usedBy = usedBy; - } - - - } \ No newline at end of file Index: drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java =================================================================== --- drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java (revision 16463) +++ drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java (working copy) @@ -8,9 +8,9 @@ import junit.framework.Assert; import junit.framework.TestCase; - import org.drools.Cheese; import org.drools.Cheesery; +import org.drools.ExpensiveCheese; import org.drools.FactHandle; import org.drools.OuterClass; import org.drools.Person; @@ -628,6 +628,10 @@ execTestAccumulateSum( "test_AccumulateSum.drl" ); } + public void testAccumulateSumLongJava() throws Exception { + execTestAccumulateSumLong( "test_AccumulateSumLong.drl" ); + } + public void testAccumulateSumMVEL() throws Exception { execTestAccumulateSum( "test_AccumulateSumMVEL.drl" ); } @@ -747,6 +751,38 @@ } + public void execTestAccumulateSumLong(String fileName) throws Exception { + // read in the source + final Reader reader = new InputStreamReader( getClass().getResourceAsStream( fileName ) ); + final RuleBase ruleBase = loadRuleBase( reader ); + + final WorkingMemory wm = ruleBase.newStatefulSession(); + final List results = new ArrayList(); + + wm.setGlobal( "results", + results ); + + long maxLongMinus3 = Long.MAX_VALUE - 4L; + + final ExpensiveCheese[] cheese = new ExpensiveCheese[]{ + new ExpensiveCheese( "stilton", 3L ), + new ExpensiveCheese( "stilton", maxLongMinus3 ) + }; + + final FactHandle[] cheeseHandles = new FactHandle[cheese.length]; + for ( int i = 0; i < cheese.length; i++ ) { + cheeseHandles[i] = wm.insert( cheese[i] ); + } + + // ---------------- 1st scenario + wm.fireAllRules(); + Assert.assertEquals( 1, + results.size() ); + Assert.assertEquals( Long.MAX_VALUE - 1L, + ((Number) results.get( results.size() - 1 )).longValue() ); + + } + public void execTestAccumulateCount(String fileName) throws Exception { // read in the source final Reader reader = new InputStreamReader( getClass().getResourceAsStream( fileName ) ); Index: drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateSumLong.drl =================================================================== --- drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateSumLong.drl (revision 16463) +++ drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateSumLong.drl (working copy) @@ -1,17 +1,16 @@ package org.drools.test; -import org.drools.Cheese; +import org.drools.ExpensiveCheese; import org.drools.Person; global java.util.List results; -rule "Test sum" salience 80 +rule "Test sum with long" salience 80 dialect "java" when - $person : Person( $likes : likes ) - $sum : Number( doubleValue >= 10 ) - from accumulate( Cheese( type == $likes, $price : price ), - sum( $price ) ); + $sum : Number() + from accumulate( ExpensiveCheese( $longPrice : longPrice ), + sum( $longPrice ) ); then results.add( $sum ); end