diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
index c65bbef..a8281d4 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBasic.java
@@ -161,6 +161,7 @@ public class TestBasic {
});
}
+
private DateTime checkAndGetCTD(UUID subscriptionId) {
SubscriptionData subscription = (SubscriptionData) entitlementUserApi.getSubscriptionFromId(subscriptionId);
DateTime ctd = subscription.getChargedThroughDate();
@@ -170,9 +171,9 @@ public class TestBasic {
}
@Test(groups = "fast", enabled = true)
- public void testSimple() throws Exception {
+ public void testBasePlanComplete() throws Exception {
long DELAY = 5000;
-
+
Account account = accountUserApi.createAccount(getAccountData(), null, null);
assertNotNull(account);
@@ -217,6 +218,13 @@ public class TestBasic {
DateTime ctd = checkAndGetCTD(subscription.getId());
//
+ // MOVE TIME TO AFTER TRIAL AND EXPECT BOTH EVENTS : NextEvent.PHASE NextEvent.INVOICE
+ //
+ busHandler.pushExpectedEvent(NextEvent.PHASE);
+ busHandler.pushExpectedEvent(NextEvent.INVOICE);
+ clock.setDeltaFromReality(AT_LEAST_ONE_MONTH_MS);
+
+ //
// CHANGE PLAN EOT AND EXPECT NOTHING
//
newTerm = BillingPeriod.MONTHLY;
@@ -229,7 +237,7 @@ public class TestBasic {
//
busHandler.pushExpectedEvent(NextEvent.CHANGE);
busHandler.pushExpectedEvent(NextEvent.INVOICE);
- clock.setDeltaFromReality(ctd.getMillis() - clock.getUTCNow().getMillis());
+ clock.addDeltaFromReality(ctd.getMillis() - clock.getUTCNow().getMillis());
//clock.setDeltaFromReality(AT_LEAST_ONE_MONTH_MS + 1000);
assertTrue(busHandler.isCompleted(DELAY));
log.info("testSimple passed fourth busHandler checkpoint.");
@@ -251,12 +259,19 @@ public class TestBasic {
//
subscription.cancel(clock.getUTCNow(), false);
- // MOVE AFTER CANCEL DATE AND EXPECT EVENT : NextEvent.CANCEL, NextEvent.INVOICE
+ // MOVE AFTER CANCEL DATE AND EXPECT EVENT : NextEvent.CANCEL
busHandler.pushExpectedEvent(NextEvent.CANCEL);
- busHandler.pushExpectedEvent(NextEvent.INVOICE);
Interval it = new Interval(lastCtd, clock.getUTCNow());
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(busHandler.isCompleted(DELAY));
+
+ //
+ // CHECK AGAIN THERE IS NO MORE INVOICES GENERATED
+ //
+ busHandler.reset();
+ clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS + 1000);
+ assertTrue(busHandler.isCompleted(DELAY));
+ lastCtd = checkAndGetCTD(subscription.getId());
}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBusHandler.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBusHandler.java
index 58074c6..307131b 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBusHandler.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/inv_ent/TestBusHandler.java
@@ -109,6 +109,7 @@ public class TestBusHandler {
public void reset() {
nextExpectedEvent.clear();
+ completed = true;
}
public void pushExpectedEvent(NextEvent next) {
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
index b6f9b09..3780ade 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueue.java
@@ -85,34 +85,31 @@ public class DefaultNotificationQueue extends NotificationQueueBase {
log.debug(String.format("NotificationQueue %s getEventsReady START effectiveNow = %s", getFullQName(), now));
- List<Notification> result = dao.inTransaction(new Transaction<List<Notification>, NotificationSqlDao>() {
-
+ List<Notification> input = dao.inTransaction(new Transaction<List<Notification>, NotificationSqlDao>() {
@Override
public List<Notification> inTransaction(NotificationSqlDao transactionalDao,
TransactionStatus status) throws Exception {
-
- List<Notification> claimedNotifications = new ArrayList<Notification>();
- List<Notification> input = transactionalDao.getReadyNotifications(now, config.getDaoMaxReadyEvents(), getFullQName());
- for (Notification cur : input) {
- final boolean claimed = (transactionalDao.claimNotification(hostname, nextAvailable, cur.getId().toString(), now) == 1);
- if (claimed) {
- claimedNotifications.add(cur);
- transactionalDao.insertClaimedHistory(seqId, hostname, now, cur.getId().toString());
- }
- }
- return claimedNotifications;
+ return transactionalDao.getReadyNotifications(now, config.getDaoMaxReadyEvents(), getFullQName());
}
});
- for (Notification cur : result) {
- log.debug(String.format("NotificationQueue %sclaimed events %s",
+ List<Notification> claimedNotifications = new ArrayList<Notification>();
+ for (Notification cur : input) {
+ final boolean claimed = (dao.claimNotification(hostname, nextAvailable, cur.getId().toString(), now) == 1);
+ if (claimed) {
+ claimedNotifications.add(cur);
+ dao.insertClaimedHistory(seqId, hostname, now, cur.getId().toString());
+ }
+ }
+
+ for (Notification cur : claimedNotifications) {
+ log.debug(String.format("NotificationQueue %s claimed events %s",
getFullQName(), cur.getId()));
if (cur.getOwner() != null && !cur.getOwner().equals(hostname)) {
log.warn(String.format("NotificationQueue %s stealing notification %s from %s",
getFullQName(), cur, cur.getOwner()));
}
}
- return result;
+ return claimedNotifications;
}
-
}