killbill-uncached

Details

diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
index 47f754e..0e548b7 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestBasic.java
@@ -185,12 +185,12 @@ public class TestBasic {
         testBasePlanComplete(clock.getUTCNow().minusDays(1).getDayOfMonth());
     }
 
-    @Test(groups = "fast", enabled = false)
+    @Test(groups = "fast", enabled = true)
     public void testBasePlanCompleteWithBillingDayPresent() throws Exception {
         testBasePlanComplete(clock.getUTCNow().getDayOfMonth());
     }
 
-    @Test(groups = "fast", enabled = true)
+    @Test(groups = "fast", enabled = false)
     public void testBasePlanCompleteWithBillingDayAlignedWithTrial() throws Exception {
         testBasePlanComplete(clock.getUTCNow().plusDays(30).getDayOfMonth());
     }
@@ -200,10 +200,10 @@ public class TestBasic {
         testBasePlanComplete(clock.getUTCNow().plusDays(1).getDayOfMonth());
     }
 
-
-    private void waitForDebug() throws Exception {
-        Thread.sleep(600000);
-    }
+//
+//    private void waitForDebug() throws Exception {
+//        Thread.sleep(600000);
+//    }
 
 
     @Test(groups = "stress", enabled = false)
@@ -240,7 +240,7 @@ public class TestBasic {
         assertNotNull(subscription);
 
 
-        waitForDebug();
+        //waitForDebug();
 
         assertTrue(busHandler.isCompleted(DELAY));
         log.info("testSimple passed first busHandler checkpoint.");
diff --git a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
index 41a86e1..331372a 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/model/DefaultInvoiceGenerator.java
@@ -150,35 +150,37 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
         if (billingPeriod != BillingPeriod.NO_BILLING_PERIOD) {
             BillingMode billingMode = instantiateBillingMode(thisEvent.getBillingMode());
             DateTime startDate = thisEvent.getEffectiveDate();
-            DateTime endDate = (nextEvent == null) ? null : nextEvent.getEffectiveDate();
-            int billCycleDay = thisEvent.getBillCycleDay();
-
-            List<RecurringInvoiceItemData> itemData;
-            try {
-                itemData = billingMode.calculateInvoiceItemData(startDate, endDate, targetDate, billCycleDay, billingPeriod);
-            } catch (InvalidDateSequenceException e) {
-                throw new InvoiceApiException(ErrorCode.INVOICE_INVALID_DATE_SEQUENCE, startDate, endDate, targetDate);
-            }
+            if (!startDate.isAfter(targetDate)) {
+                DateTime endDate = (nextEvent == null) ? null : nextEvent.getEffectiveDate();
+                int billCycleDay = thisEvent.getBillCycleDay();
 
-            for (RecurringInvoiceItemData itemDatum : itemData) {
-                InternationalPrice price = thisEvent.getRecurringPrice();
-                if (price != null) {
-                    BigDecimal rate;
+                List<RecurringInvoiceItemData> itemData;
+                try {
+                    itemData = billingMode.calculateInvoiceItemData(startDate, endDate, targetDate, billCycleDay, billingPeriod);
+                } catch (InvalidDateSequenceException e) {
+                    throw new InvoiceApiException(ErrorCode.INVOICE_INVALID_DATE_SEQUENCE, startDate, endDate, targetDate);
+                }
 
-                    try {
-                        rate = thisEvent.getRecurringPrice().getPrice(currency);
-                    } catch (CatalogApiException e) {
-                        throw new InvoiceApiException(e, ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency.toString());
+                for (RecurringInvoiceItemData itemDatum : itemData) {
+                    InternationalPrice price = thisEvent.getRecurringPrice();
+                    if (price != null) {
+                        BigDecimal rate;
+
+                        try {
+                            rate = thisEvent.getRecurringPrice().getPrice(currency);
+                        } catch (CatalogApiException e) {
+                            throw new InvoiceApiException(e, ErrorCode.CAT_NO_PRICE_FOR_CURRENCY, currency.toString());
+                        }
+
+                        BigDecimal amount = itemDatum.getNumberOfCycles().multiply(rate).setScale(NUMBER_OF_DECIMALS, ROUNDING_MODE);
+
+                        RecurringInvoiceItem recurringItem = new RecurringInvoiceItem(invoiceId, thisEvent.getSubscription().getId(),
+                                                                                      thisEvent.getPlan().getName(),
+                                                                                      thisEvent.getPlanPhase().getName(),
+                                                                                      itemDatum.getStartDate(), itemDatum.getEndDate(),
+                                                                                      amount, rate, currency);
+                        items.add(recurringItem);
                     }
-
-                    BigDecimal amount = itemDatum.getNumberOfCycles().multiply(rate).setScale(NUMBER_OF_DECIMALS, ROUNDING_MODE);
-
-                    RecurringInvoiceItem recurringItem = new RecurringInvoiceItem(invoiceId, thisEvent.getSubscription().getId(),
-                                                                                  thisEvent.getPlan().getName(),
-                                                                                  thisEvent.getPlanPhase().getName(),
-                                                                                  itemDatum.getStartDate(), itemDatum.getEndDate(),
-                                                                                  amount, rate, currency);
-                    items.add(recurringItem);
                 }
             }
         }