killbill-aplcache
Changes
entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg 14(+7 -7)
entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java 2(+1 -1)
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java 45(+13 -32)
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java 63(+63 -0)
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 e0eaa7e..d04d768 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
@@ -16,20 +16,28 @@
package com.ning.billing.beatrix.integration;
+import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import java.util.UUID;
import com.ning.billing.account.api.AccountApiException;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
+import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.invoice.api.InvoiceItem;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.RandomStringUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
+import org.joda.time.Days;
import org.joda.time.Interval;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.IDBI;
@@ -179,7 +187,7 @@ public class TestBasic {
public Void inTransaction(Handle h, TransactionStatus status)
throws Exception {
h.execute("truncate table accounts");
- h.execute("truncate table events");
+ h.execute("truncate table entitlement_events");
h.execute("truncate table subscriptions");
h.execute("truncate table bundles");
h.execute("truncate table notifications");
@@ -198,43 +206,69 @@ public class TestBasic {
});
}
- private DateTime checkAndGetCTD(UUID subscriptionId) {
-
+ private void verifyTestResult(UUID accountId, UUID subscriptionId,
+ DateTime startDate, DateTime endDate,
+ BigDecimal amount, DateTime chargeThroughDate) {
SubscriptionData subscription = (SubscriptionData) entitlementUserApi.getSubscriptionFromId(subscriptionId);
+
+ List<InvoiceItem> invoiceItems = invoiceUserApi.getInvoiceItemsByAccount(accountId);
+ boolean wasFound = false;
+
+ Iterator<InvoiceItem> invoiceItemIterator = invoiceItems.iterator();
+ while (invoiceItemIterator.hasNext()) {
+ InvoiceItem item = invoiceItemIterator.next();
+ if (item.getStartDate().compareTo(removeMillis(startDate)) == 0) {
+ if (item.getEndDate().compareTo(removeMillis(endDate)) == 0) {
+ if (item.getAmount().compareTo(amount) == 0) {
+ wasFound = true;
+ break;
+ }
+ }
+ }
+ }
+
+ assertTrue(wasFound);
+
DateTime ctd = subscription.getChargedThroughDate();
assertNotNull(ctd);
log.info("Checking CTD: " + ctd.toString() + "; clock is " + clock.getUTCNow().toString());
assertTrue(clock.getUTCNow().isBefore(ctd));
- return ctd;
+ assertTrue(ctd.compareTo(removeMillis(chargeThroughDate)) == 0);
+ }
+
+ private DateTime removeMillis(DateTime input) {
+ return input.toMutableDateTime().millisOfSecond().set(0).toDateTime();
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "fast", enabled = false)
public void testBasePlanCompleteWithBillingDayInPast() throws Exception {
- testBasePlanComplete(clock.getUTCNow().minusDays(1).getDayOfMonth(), false);
+ DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ testBasePlanComplete(startDate, 31, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "fast", enabled = false)
public void testBasePlanCompleteWithBillingDayPresent() throws Exception {
- testBasePlanComplete(clock.getUTCNow().getDayOfMonth(), false);
+ DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ testBasePlanComplete(startDate, 1, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "fast", enabled = false)
public void testBasePlanCompleteWithBillingDayAlignedWithTrial() throws Exception {
- testBasePlanComplete(clock.getUTCNow().plusDays(30).getDayOfMonth(), false);
+ DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ testBasePlanComplete(startDate, 2, false);
}
- @Test(groups = "slow", enabled = true)
+ @Test(groups = "fast", enabled = false)
public void testBasePlanCompleteWithBillingDayInFuture() throws Exception {
- testBasePlanComplete(clock.getUTCNow().plusDays(2).getDayOfMonth(), true);
+ DateTime startDate = new DateTime(2012, 2, 1, 0, 3, 42, 0);
+ testBasePlanComplete(startDate, 3, true);
}
-
private void waitForDebug() throws Exception {
Thread.sleep(600000);
}
-
- @Test(groups = "stress", enabled = true)
+ @Test(groups = "stress", enabled = false)
public void stressTest() throws Exception {
final int maxIterations = 7;
int curIteration = maxIterations;
@@ -255,12 +289,16 @@ public class TestBasic {
}
}
- private void testBasePlanComplete(int billingDay, boolean prorationExpected) throws Exception {
- long DELAY = 5000;
+ private void testBasePlanComplete(DateTime initialCreationDate, int billingDay,
+ boolean proRationExpected) throws Exception {
+ long DELAY = 5000 * 10;
Account account = accountUserApi.createAccount(getAccountData(billingDay), null, null);
+ UUID accountId = account.getId();
assertNotNull(account);
+ // set clock to the initial start date
+ clock.setDeltaFromReality(initialCreationDate.getMillis() - DateTime.now().getMillis());
SubscriptionBundle bundle = entitlementUserApi.createBundleForAccount(account.getId(), "whatever");
String productName = "Shotgun";
@@ -276,17 +314,16 @@ public class TestBasic {
new PlanPhaseSpecifier(productName, ProductCategory.BASE, term, planSetName, null), null);
assertNotNull(subscription);
-
- //waitForDebug();
-
assertTrue(busHandler.isCompleted(DELAY));
log.info("testSimple passed first busHandler checkpoint.");
//
// VERIFY CTD HAS BEEN SET
//
-
- checkAndGetCTD(subscription.getId());
+ DateTime startDate = subscription.getCurrentPhaseStart();
+ DateTime endDate = startDate.plusDays(30);
+ BigDecimal price = subscription.getCurrentPhase().getFixedPrice().getPrice(Currency.USD);
+ verifyTestResult(accountId, subscription.getId(), startDate, endDate, price, endDate);
//
// CHANGE PLAN IMMEDIATELY AND EXPECT BOTH EVENTS: NextEvent.CHANGE NextEvent.INVOICE
@@ -305,7 +342,10 @@ public class TestBasic {
//
// VERIFY AGAIN CTD HAS BEEN SET
//
- DateTime ctd = checkAndGetCTD(subscription.getId());
+ startDate = subscription.getCurrentPhaseStart();
+ endDate = startDate.plusMonths(1);
+ price = subscription.getCurrentPhase().getFixedPrice().getPrice(Currency.USD);
+ verifyTestResult(accountId, subscription.getId(), startDate, endDate, price, endDate);
//
// MOVE TIME TO AFTER TRIAL AND EXPECT BOTH EVENTS : NextEvent.PHASE NextEvent.INVOICE
@@ -314,7 +354,7 @@ public class TestBasic {
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
- if (prorationExpected) {
+ if (proRationExpected) {
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
}
@@ -351,13 +391,14 @@ public class TestBasic {
// MOVE TIME AFTER NEXT BILL CYCLE DAY AND EXPECT EVENT : NextEvent.INVOICE
//
int maxCycles = 3;
- DateTime lastCtd = null;
+ startDate = endDate;
+ endDate = startDate.plusMonths(1);
do {
busHandler.pushExpectedEvent(NextEvent.INVOICE);
busHandler.pushExpectedEvent(NextEvent.PAYMENT);
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS + 1000);
assertTrue(busHandler.isCompleted(DELAY));
- lastCtd = checkAndGetCTD(subscription.getId());
+ verifyTestResult(accountId, subscription.getId(), startDate, endDate, price, endDate);
} while (maxCycles-- > 0);
//
@@ -368,7 +409,7 @@ public class TestBasic {
// MOVE AFTER CANCEL DATE AND EXPECT EVENT : NextEvent.CANCEL
busHandler.pushExpectedEvent(NextEvent.CANCEL);
- Interval it = new Interval(clock.getUTCNow(), lastCtd);
+ Interval it = new Interval(clock.getUTCNow(), endDate);
clock.addDeltaFromReality(it.toDurationMillis());
assertTrue(busHandler.isCompleted(DELAY));
@@ -379,15 +420,14 @@ public class TestBasic {
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS + 1000);
assertTrue(busHandler.isCompleted(DELAY));
-
subscription = (SubscriptionData) entitlementUserApi.getSubscriptionFromId(subscription.getId());
- lastCtd = subscription.getChargedThroughDate();
+ DateTime lastCtd = subscription.getChargedThroughDate();
assertNotNull(lastCtd);
log.info("Checking CTD: " + lastCtd.toString() + "; clock is " + clock.getUTCNow().toString());
assertTrue(lastCtd.isBefore(clock.getUTCNow()));
// The invoice system is still working to verify there is nothing to do
- Thread.sleep(3000);
+ Thread.sleep(DELAY);
log.info("TEST PASSED !");
}
@@ -428,7 +468,6 @@ public class TestBasic {
}
-
protected AccountData getAccountData(final int billingDay) {
final String someRandomKey = RandomStringUtils.randomAlphanumeric(10);
diff --git a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
index a774b61..0f5375b 100644
--- a/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
+++ b/entitlement/src/main/java/com/ning/billing/entitlement/engine/core/Engine.java
@@ -101,7 +101,7 @@ public class Engine implements EventListener, EntitlementService {
NOTIFICATION_QUEUE_NAME,
new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime) {
EntitlementEvent event = dao.getEventById(UUID.fromString(notificationKey));
if (event == null) {
log.warn("Failed to extract event for notification key {}", notificationKey);
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
index 55ad7f4..dfdc746 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
@@ -1,5 +1,5 @@
-DROP TABLE IF EXISTS events;
-CREATE TABLE events (
+DROP TABLE IF EXISTS entitlement_events;
+CREATE TABLE entitlement_events (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
event_id char(36) NOT NULL,
event_type varchar(9) NOT NULL,
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
index 704e2c7..10f565d 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/engine/dao/EventSqlDao.sql.stg
@@ -15,14 +15,14 @@ getEventById(event_id) ::= <<
, plist_name
, current_version
, is_active
- from events
+ from entitlement_events
where
event_id = :event_id
;
>>
insertEvent() ::= <<
- insert into events (
+ insert into entitlement_events (
event_id
, event_type
, user_type
@@ -54,14 +54,14 @@ insertEvent() ::= <<
>>
removeEvents(subscription_id) ::= <<
- delete from events
+ delete from entitlement_events
where
subscription_id = :subscription_id
;
>>
unactiveEvent(event_id, now) ::= <<
- update events
+ update entitlement_events
set
is_active = 0
, updated_dt = :now
@@ -71,7 +71,7 @@ unactiveEvent(event_id, now) ::= <<
>>
reactiveEvent(event_id, now) ::= <<
- update events
+ update entitlement_events
set
is_active = 1
, updated_dt = :now
@@ -95,7 +95,7 @@ getFutureActiveEventForSubscription(subscription_id, now) ::= <<
, plist_name
, current_version
, is_active
- from events
+ from entitlement_events
where
subscription_id = :subscription_id
and is_active = 1
@@ -123,7 +123,7 @@ getEventsForSubscription(subscription_id) ::= <<
, plist_name
, current_version
, is_active
- from events
+ from entitlement_events
where
subscription_id = :subscription_id
order by
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
index 2204274..c5881f9 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/engine/dao/MockEntitlementDaoSql.java
@@ -58,7 +58,7 @@ public class MockEntitlementDaoSql extends EntitlementSqlDao implements MockEnti
public static interface ResetSqlDao extends Transactional<ResetSqlDao>, CloseMe {
- @SqlUpdate("truncate table events")
+ @SqlUpdate("truncate table entitlement_events")
public void resetEvents();
@SqlUpdate("truncate table subscriptions")
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
index e7a26a3..3b27fa6 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
@@ -24,23 +24,31 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
-import com.ning.billing.entitlement.api.billing.EntitlementBillingApi;
-import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
-import com.ning.billing.invoice.model.RecurringInvoiceItem;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.Transaction;
import org.skife.jdbi.v2.TransactionStatus;
+import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.google.inject.Inject;
+import com.ning.billing.entitlement.api.billing.EntitlementBillingApi;
+import com.ning.billing.invoice.api.DefaultInvoiceService;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceCreationNotification;
import com.ning.billing.invoice.api.InvoiceItem;
import com.ning.billing.invoice.api.InvoicePayment;
import com.ning.billing.invoice.api.user.DefaultInvoiceCreationNotification;
-import com.ning.billing.invoice.notification.NextBillingDateNotifier;
+import com.ning.billing.invoice.model.FixedPriceInvoiceItem;
+import com.ning.billing.invoice.model.RecurringInvoiceItem;
+import com.ning.billing.invoice.notification.DefaultNextBillingDateNotifier;
+import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.util.bus.Bus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import com.ning.billing.util.notificationq.NotificationKey;
+import com.ning.billing.util.notificationq.NotificationQueue;
+import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
public class DefaultInvoiceDao implements InvoiceDao {
private final static Logger log = LoggerFactory.getLogger(DefaultInvoiceDao.class);
@@ -49,21 +57,23 @@ public class DefaultInvoiceDao implements InvoiceDao {
private final RecurringInvoiceItemSqlDao recurringInvoiceItemSqlDao;
private final FixedPriceInvoiceItemSqlDao fixedPriceInvoiceItemSqlDao;
private final InvoicePaymentSqlDao invoicePaymentSqlDao;
- private final NextBillingDateNotifier notifier;
private final EntitlementBillingApi entitlementBillingApi;
private final Bus eventBus;
+ private NextBillingDatePoster nextBillingDatePoster;
+
@Inject
public DefaultInvoiceDao(final IDBI dbi, final Bus eventBus,
- final NextBillingDateNotifier notifier, final EntitlementBillingApi entitlementBillingApi) {
+ final EntitlementBillingApi entitlementBillingApi,
+ NextBillingDatePoster nextBillingDatePoster) {
this.invoiceSqlDao = dbi.onDemand(InvoiceSqlDao.class);
this.recurringInvoiceItemSqlDao = dbi.onDemand(RecurringInvoiceItemSqlDao.class);
this.fixedPriceInvoiceItemSqlDao = dbi.onDemand(FixedPriceInvoiceItemSqlDao.class);
this.invoicePaymentSqlDao = dbi.onDemand(InvoicePaymentSqlDao.class);
this.eventBus = eventBus;
- this.notifier = notifier;
this.entitlementBillingApi = entitlementBillingApi;
+ this.nextBillingDatePoster = nextBillingDatePoster;
}
@Override
@@ -273,12 +283,12 @@ public class DefaultInvoiceDao implements InvoiceDao {
if ((recurringInvoiceItem.getEndDate() != null) &&
(recurringInvoiceItem.getAmount() == null ||
recurringInvoiceItem.getAmount().compareTo(BigDecimal.ZERO) >= 0)) {
- notifier.insertNextBillingNotification(dao, item.getSubscriptionId(), recurringInvoiceItem.getEndDate());
+ nextBillingDatePoster.insertNextBillingNotification(dao, item.getSubscriptionId(), recurringInvoiceItem.getEndDate());
}
}
}
}
-
+
private void setChargedThroughDates(final InvoiceSqlDao dao, final Collection<InvoiceItem> fixedPriceItems,
final Collection<InvoiceItem> recurringItems) {
Map<UUID, DateTime> chargeThroughDates = new HashMap<UUID, DateTime>();
diff --git a/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java b/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
index 372952b..26e0865 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/glue/InvoiceModule.java
@@ -32,7 +32,9 @@ import com.ning.billing.invoice.dao.InvoiceDao;
import com.ning.billing.invoice.model.DefaultInvoiceGenerator;
import com.ning.billing.invoice.model.InvoiceGenerator;
import com.ning.billing.invoice.notification.DefaultNextBillingDateNotifier;
+import com.ning.billing.invoice.notification.DefaultNextBillingDatePoster;
import com.ning.billing.invoice.notification.NextBillingDateNotifier;
+import com.ning.billing.invoice.notification.NextBillingDatePoster;
import com.ning.billing.util.glue.ClockModule;
import com.ning.billing.util.glue.GlobalLockerModule;
@@ -65,6 +67,7 @@ public class InvoiceModule extends AbstractModule {
protected void installNotifier() {
bind(NextBillingDateNotifier.class).to(DefaultNextBillingDateNotifier.class).asEagerSingleton();
+ bind(NextBillingDatePoster.class).to(DefaultNextBillingDatePoster.class).asEagerSingleton();
}
protected void installGlobalLocker() {
diff --git a/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
new file mode 100644
index 0000000..0a23d01
--- /dev/null
+++ b/invoice/src/main/java/com/ning/billing/invoice/InvoiceDispatcher.java
@@ -0,0 +1,161 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.invoice;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.ning.billing.ErrorCode;
+import com.ning.billing.account.api.Account;
+import com.ning.billing.account.api.AccountUserApi;
+import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.entitlement.api.billing.BillingEvent;
+import com.ning.billing.entitlement.api.billing.EntitlementBillingApi;
+import com.ning.billing.entitlement.api.user.SubscriptionTransition;
+import com.ning.billing.invoice.api.Invoice;
+import com.ning.billing.invoice.api.InvoiceApiException;
+import com.ning.billing.invoice.api.InvoiceItem;
+import com.ning.billing.invoice.dao.InvoiceDao;
+import com.ning.billing.invoice.model.BillingEventSet;
+import com.ning.billing.invoice.model.InvoiceGenerator;
+import com.ning.billing.invoice.model.InvoiceItemList;
+import com.ning.billing.util.globallocker.GlobalLock;
+import com.ning.billing.util.globallocker.GlobalLocker;
+import com.ning.billing.util.globallocker.LockFailedException;
+import com.ning.billing.util.globallocker.GlobalLocker.LockerService;
+
+public class InvoiceDispatcher {
+ private final static Logger log = LoggerFactory.getLogger(InvoiceDispatcher.class);
+ private final static int NB_LOCK_TRY = 5;
+
+ private final InvoiceGenerator generator;
+ private final EntitlementBillingApi entitlementBillingApi;
+ private final AccountUserApi accountUserApi;
+ private final InvoiceDao invoiceDao;
+ private final GlobalLocker locker;
+
+ private final static boolean VERBOSE_OUTPUT = false;
+ @Inject
+ public InvoiceDispatcher(final InvoiceGenerator generator, final AccountUserApi accountUserApi,
+ final EntitlementBillingApi entitlementBillingApi,
+ final InvoiceDao invoiceDao,
+ final GlobalLocker locker) {
+ this.generator = generator;
+ this.entitlementBillingApi = entitlementBillingApi;
+ this.accountUserApi = accountUserApi;
+ this.invoiceDao = invoiceDao;
+ this.locker = locker;
+ }
+
+
+ public void processSubscription(final SubscriptionTransition transition) throws InvoiceApiException {
+ UUID subscriptionId = transition.getSubscriptionId();
+ DateTime targetDate = transition.getEffectiveTransitionTime();
+ log.info("Got subscription transition from InvoiceListener. id: " + subscriptionId.toString() + "; targetDate: " + targetDate.toString());
+ log.info("Transition type: " + transition.getTransitionType().toString());
+ processSubscription(subscriptionId, targetDate);
+ }
+
+ public void processSubscription(final UUID subscriptionId, final DateTime targetDate) throws InvoiceApiException {
+ if (subscriptionId == null) {
+ log.error("Failed handling entitlement change.", new InvoiceApiException(ErrorCode.INVOICE_INVALID_TRANSITION));
+ return;
+ }
+
+ UUID accountId = entitlementBillingApi.getAccountIdFromSubscriptionId(subscriptionId);
+ if (accountId == null) {
+ log.error("Failed handling entitlement change.",
+ new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, subscriptionId.toString()));
+ return;
+ }
+
+ GlobalLock lock = null;
+ try {
+ lock = locker.lockWithNumberOfTries(LockerService.INVOICE, accountId.toString(), NB_LOCK_TRY);
+
+ processAccountWithLock(accountId, targetDate);
+
+ } catch (LockFailedException e) {
+ // Not good!
+ log.error(String.format("Failed to process invoice for account %s, subscription %s, targetDate %s",
+ accountId.toString(), subscriptionId.toString(), targetDate), e);
+ } finally {
+ if (lock != null) {
+ lock.release();
+ }
+ }
+ }
+
+ private void processAccountWithLock(final UUID accountId, final DateTime targetDate) throws InvoiceApiException {
+
+ Account account = accountUserApi.getAccountById(accountId);
+ if (account == null) {
+ log.error("Failed handling entitlement change.",
+ new InvoiceApiException(ErrorCode.INVOICE_ACCOUNT_ID_INVALID, accountId.toString()));
+ return;
+ }
+
+ SortedSet<BillingEvent> events = entitlementBillingApi.getBillingEventsForAccount(accountId);
+ BillingEventSet billingEvents = new BillingEventSet(events);
+
+ Currency targetCurrency = account.getCurrency();
+
+ List<InvoiceItem> items = invoiceDao.getInvoiceItemsByAccount(accountId);
+ InvoiceItemList invoiceItemList = new InvoiceItemList(items);
+ Invoice invoice = generator.generateInvoice(accountId, billingEvents, invoiceItemList, targetDate, targetCurrency);
+
+ if (invoice == null) {
+ log.info("Generated null invoice.");
+ outputDebugData(events, invoiceItemList);
+ } else {
+ log.info("Generated invoice {} with {} items.", invoice.getId().toString(), invoice.getNumberOfItems());
+
+ if (VERBOSE_OUTPUT) {
+ log.info("New items");
+ for (InvoiceItem item : invoice.getInvoiceItems()) {
+ log.info(item.toString());
+ }
+ }
+ outputDebugData(events, invoiceItemList);
+
+ if (invoice.getNumberOfItems() > 0) {
+ invoiceDao.create(invoice);
+ }
+ }
+ }
+
+ private void outputDebugData(Collection<BillingEvent> events, Collection<InvoiceItem> invoiceItemList) {
+ if (VERBOSE_OUTPUT) {
+ log.info("Events");
+ for (BillingEvent event : events) {
+ log.info(event.toString());
+ }
+
+ log.info("Existing items");
+ for (InvoiceItem item : invoiceItemList) {
+ log.info(item.toString());
+ }
+ }
+ }
+}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/InvoiceListener.java b/invoice/src/main/java/com/ning/billing/invoice/InvoiceListener.java
index ea1fc12..140b106 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/InvoiceListener.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/InvoiceListener.java
@@ -16,9 +16,6 @@
package com.ning.billing.invoice;
-import java.util.Collection;
-import java.util.List;
-import java.util.SortedSet;
import java.util.UUID;
import org.joda.time.DateTime;
@@ -27,162 +24,34 @@ import org.slf4j.LoggerFactory;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
-import com.ning.billing.ErrorCode;
-import com.ning.billing.account.api.Account;
-import com.ning.billing.account.api.AccountUserApi;
-import com.ning.billing.catalog.api.Currency;
-import com.ning.billing.entitlement.api.billing.BillingEvent;
-import com.ning.billing.entitlement.api.billing.EntitlementBillingApi;
import com.ning.billing.entitlement.api.user.SubscriptionTransition;
-import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.invoice.api.InvoiceApiException;
-import com.ning.billing.invoice.api.InvoiceItem;
-import com.ning.billing.invoice.dao.InvoiceDao;
-import com.ning.billing.invoice.model.BillingEventSet;
-import com.ning.billing.invoice.model.InvoiceGenerator;
-import com.ning.billing.invoice.model.InvoiceItemList;
-import com.ning.billing.invoice.notification.NextBillingDateEvent;
-import com.ning.billing.util.clock.Clock;
-import com.ning.billing.util.globallocker.GlobalLock;
-import com.ning.billing.util.globallocker.GlobalLocker;
-import com.ning.billing.util.globallocker.GlobalLocker.LockerService;
-import com.ning.billing.util.globallocker.LockFailedException;
public class InvoiceListener {
-
-
private final static Logger log = LoggerFactory.getLogger(InvoiceListener.class);
- private final static int NB_LOCK_TRY = 5;
-
- private final InvoiceGenerator generator;
- private final EntitlementBillingApi entitlementBillingApi;
- private final AccountUserApi accountUserApi;
- private final InvoiceDao invoiceDao;
- private final Clock clock;
- private final GlobalLocker locker;
-
- private final static boolean VERBOSE_OUTPUT = false;
+ private InvoiceDispatcher dispatcher;
@Inject
- public InvoiceListener(final InvoiceGenerator generator, final AccountUserApi accountUserApi,
- final EntitlementBillingApi entitlementBillingApi,
- final InvoiceDao invoiceDao,
- final GlobalLocker locker,
- final Clock clock) {
- this.generator = generator;
- this.entitlementBillingApi = entitlementBillingApi;
- this.accountUserApi = accountUserApi;
- this.invoiceDao = invoiceDao;
- this.locker = locker;
- this.clock = clock;
+ public InvoiceListener(InvoiceDispatcher dispatcher) {
+ this.dispatcher = dispatcher;
}
@Subscribe
public void handleSubscriptionTransition(final SubscriptionTransition transition) {
try {
- processSubscription(transition);
+ dispatcher.processSubscription(transition);
} catch (InvoiceApiException e) {
log.error(e.getMessage());
}
}
- @Subscribe
- public void handleNextBillingDateEvent(final NextBillingDateEvent event) {
- // STEPH should we use the date of the event instead?
+ public void handleNextBillingDateEvent(final UUID subscriptionId, final DateTime eventDateTime) {
try {
- processSubscription(event.getSubscriptionId(), clock.getUTCNow());
+ dispatcher.processSubscription(subscriptionId, eventDateTime);
} catch (InvoiceApiException e) {
log.error(e.getMessage());
}
}
- private void processSubscription(final SubscriptionTransition transition) throws InvoiceApiException {
- UUID subscriptionId = transition.getSubscriptionId();
- DateTime targetDate = transition.getEffectiveTransitionTime();
- log.info("Got subscription transition from InvoiceListener. id: " + subscriptionId.toString() + "; targetDate: " + targetDate.toString());
- log.info("Transition type: " + transition.getTransitionType().toString());
- processSubscription(subscriptionId, targetDate);
- }
-
- private void processSubscription(final UUID subscriptionId, final DateTime targetDate) throws InvoiceApiException {
- if (subscriptionId == null) {
- log.error("Failed handling entitlement change.", new InvoiceApiException(ErrorCode.INVOICE_INVALID_TRANSITION));
- return;
- }
-
- UUID accountId = entitlementBillingApi.getAccountIdFromSubscriptionId(subscriptionId);
- if (accountId == null) {
- log.error("Failed handling entitlement change.",
- new InvoiceApiException(ErrorCode.INVOICE_NO_ACCOUNT_ID_FOR_SUBSCRIPTION_ID, subscriptionId.toString()));
- return;
- }
-
- GlobalLock lock = null;
- try {
- lock = locker.lockWithNumberOfTries(LockerService.INVOICE, accountId.toString(), NB_LOCK_TRY);
-
- processAccountWithLock(accountId, targetDate);
-
- } catch (LockFailedException e) {
- // Not good!
- log.error(String.format("Failed to process invoice for account %s, subscription %s, targetDate %s",
- accountId.toString(), subscriptionId.toString(), targetDate), e);
- } finally {
- if (lock != null) {
- lock.release();
- }
- }
- }
-
- private void processAccountWithLock(final UUID accountId, final DateTime targetDate) throws InvoiceApiException {
-
- Account account = accountUserApi.getAccountById(accountId);
- if (account == null) {
- log.error("Failed handling entitlement change.",
- new InvoiceApiException(ErrorCode.INVOICE_ACCOUNT_ID_INVALID, accountId.toString()));
- return;
- }
-
- SortedSet<BillingEvent> events = entitlementBillingApi.getBillingEventsForAccount(accountId);
- BillingEventSet billingEvents = new BillingEventSet(events);
-
- Currency targetCurrency = account.getCurrency();
-
- List<InvoiceItem> items = invoiceDao.getInvoiceItemsByAccount(accountId);
- InvoiceItemList invoiceItemList = new InvoiceItemList(items);
- Invoice invoice = generator.generateInvoice(accountId, billingEvents, invoiceItemList, targetDate, targetCurrency);
-
- if (invoice == null) {
- log.info("Generated null invoice.");
- outputDebugData(events, invoiceItemList);
- } else {
- log.info("Generated invoice {} with {} items.", invoice.getId().toString(), invoice.getNumberOfItems());
- if (VERBOSE_OUTPUT) {
- log.info("New items");
- for (InvoiceItem item : invoice.getInvoiceItems()) {
- log.info(item.toString());
- }
- }
- outputDebugData(events, invoiceItemList);
-
- if (invoice.getNumberOfItems() > 0) {
- invoiceDao.create(invoice);
- }
- }
- }
-
- private void outputDebugData(Collection<BillingEvent> events, Collection<InvoiceItem> invoiceItemList) {
- if (VERBOSE_OUTPUT) {
- log.info("Events");
- for (BillingEvent event : events) {
- log.info(event.toString());
- }
-
- log.info("Existing items");
- for (InvoiceItem item : invoiceItemList) {
- log.info(item.toString());
- }
- }
- }
}
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 92180ac..039f305 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
@@ -109,10 +109,6 @@ public class DefaultInvoiceGenerator implements InvoiceGenerator {
proposedItemIterator.remove();
}
}
-// if (existingInvoiceItems.contains(proposedItem)) {
-// existingInvoiceItems.remove(proposedItem);
-// proposedItemIterator.remove();
-// }
}
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
index 3fd03b2..0dd5e3a 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java
@@ -18,8 +18,6 @@ package com.ning.billing.invoice.notification;
import java.util.UUID;
-import com.ning.billing.entitlement.api.user.Subscription;
-import com.ning.billing.entitlement.engine.dao.EntitlementDao;
import org.joda.time.DateTime;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import org.slf4j.Logger;
@@ -27,9 +25,11 @@ import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.ning.billing.config.InvoiceConfig;
+import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.engine.dao.EntitlementDao;
+import com.ning.billing.invoice.InvoiceListener;
import com.ning.billing.invoice.api.DefaultInvoiceService;
import com.ning.billing.util.bus.Bus;
-import com.ning.billing.util.bus.Bus.EventBusException;
import com.ning.billing.util.notificationq.NotificationConfig;
import com.ning.billing.util.notificationq.NotificationKey;
import com.ning.billing.util.notificationq.NotificationQueue;
@@ -41,22 +41,22 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier
private final static Logger log = LoggerFactory.getLogger(DefaultNextBillingDateNotifier.class);
- private static final String NEXT_BILLING_DATE_NOTIFIER_QUEUE = "next-billing-date-queue";
+ public static final String NEXT_BILLING_DATE_NOTIFIER_QUEUE = "next-billing-date-queue";
- private final Bus eventBus;
private final NotificationQueueService notificationQueueService;
private final InvoiceConfig config;
private final EntitlementDao entitlementDao;
private NotificationQueue nextBillingQueue;
+ private InvoiceListener listener;
@Inject
- public DefaultNextBillingDateNotifier(NotificationQueueService notificationQueueService, Bus eventBus,
- InvoiceConfig config, EntitlementDao entitlementDao){
+ public DefaultNextBillingDateNotifier(NotificationQueueService notificationQueueService,
+ InvoiceConfig config, EntitlementDao entitlementDao, InvoiceListener listener){
this.notificationQueueService = notificationQueueService;
this.config = config;
- this.eventBus = eventBus;
this.entitlementDao = entitlementDao;
+ this.listener = listener;
}
@Override
@@ -66,15 +66,14 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier
NEXT_BILLING_DATE_NOTIFIER_QUEUE,
new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
- UUID subscriptionId;
+ public void handleReadyNotification(String notificationKey, DateTime eventDate) {
try {
UUID key = UUID.fromString(notificationKey);
Subscription subscription = entitlementDao.getSubscriptionFromId(key);
if (subscription == null) {
log.warn("Next Billing Date Notification Queue handled spurious notification (key: " + key + ")" );
} else {
- processEvent(key);
+ processEvent(key , eventDate);
}
} catch (IllegalArgumentException e) {
log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
@@ -118,27 +117,9 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier
}
}
- private void processEvent(UUID subscriptionId) {
- try {
- eventBus.post(new NextBillingDateEvent(subscriptionId));
- } catch (EventBusException e) {
- log.error("Failed to post entitlement event " + subscriptionId, e);
- }
+ private void processEvent(UUID subscriptionId, DateTime eventDateTime) {
+ listener.handleNextBillingDateEvent(subscriptionId, eventDateTime);
}
- @Override
- public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
- if (nextBillingQueue != null) {
- log.info("Queuing next billing date notification. id: {}, timestamp: {}", subscriptionId.toString(), futureNotificationTime.toString());
-
- nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
- @Override
- public String toString() {
- return subscriptionId.toString();
- }
- });
- } else {
- log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).");
- }
- }
+
}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
new file mode 100644
index 0000000..8ddb29d
--- /dev/null
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDatePoster.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.invoice.notification;
+
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.ning.billing.invoice.api.DefaultInvoiceService;
+import com.ning.billing.util.notificationq.NotificationKey;
+import com.ning.billing.util.notificationq.NotificationQueue;
+import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
+
+public class DefaultNextBillingDatePoster implements NextBillingDatePoster {
+ private final static Logger log = LoggerFactory.getLogger(DefaultNextBillingDateNotifier.class);
+
+ private final NotificationQueueService notificationQueueService;
+
+ @Inject
+ public DefaultNextBillingDatePoster(
+ NotificationQueueService notificationQueueService) {
+ super();
+ this.notificationQueueService = notificationQueueService;
+ }
+
+ @Override
+ public void insertNextBillingNotification(final Transmogrifier transactionalDao, final UUID subscriptionId, final DateTime futureNotificationTime) {
+ NotificationQueue nextBillingQueue;
+ try {
+ nextBillingQueue = notificationQueueService.getNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
+ DefaultNextBillingDateNotifier.NEXT_BILLING_DATE_NOTIFIER_QUEUE);
+ log.info("Queuing next billing date notification. id: {}, timestamp: {}", subscriptionId.toString(), futureNotificationTime.toString());
+
+ nextBillingQueue.recordFutureNotificationFromTransaction(transactionalDao, futureNotificationTime, new NotificationKey(){
+ @Override
+ public String toString() {
+ return subscriptionId.toString();
+ }
+ });
+ } catch (NoSuchNotificationQueue e) {
+ log.error("Attempting to put items on a non-existent queue (NextBillingDateNotifier).", e);
+ }
+ }
+}
diff --git a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
index d33dc61..ea630aa 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/notification/NextBillingDateNotifier.java
@@ -16,10 +16,6 @@
package com.ning.billing.invoice.notification;
-import java.util.UUID;
-
-import org.joda.time.DateTime;
-import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
public interface NextBillingDateNotifier {
@@ -29,7 +25,4 @@ public interface NextBillingDateNotifier {
public void stop();
- public void insertNextBillingNotification(Transmogrifier transactionalDao,
- UUID subscriptionId, DateTime futureNotificationTime);
-
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/BrainDeadSubscription.java b/invoice/src/test/java/com/ning/billing/invoice/notification/BrainDeadSubscription.java
new file mode 100644
index 0000000..587144b
--- /dev/null
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/BrainDeadSubscription.java
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2010-2011 Ning, Inc.
+ *
+ * Ning licenses this file to you under the Apache License, version 2.0
+ * (the "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package com.ning.billing.invoice.notification;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.joda.time.DateTime;
+
+import com.ning.billing.catalog.api.BillingPeriod;
+import com.ning.billing.catalog.api.Plan;
+import com.ning.billing.catalog.api.PlanPhase;
+import com.ning.billing.entitlement.api.user.EntitlementUserApiException;
+import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionTransition;
+
+public class BrainDeadSubscription implements Subscription {
+
+ @Override
+ public void cancel(DateTime requestedDate, boolean eot)
+ throws EntitlementUserApiException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void uncancel() throws EntitlementUserApiException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void changePlan(String productName, BillingPeriod term,
+ String planSet, DateTime requestedDate)
+ throws EntitlementUserApiException {
+ throw new UnsupportedOperationException();
+
+
+ }
+
+ @Override
+ public void pause() throws EntitlementUserApiException {
+ throw new UnsupportedOperationException();
+
+
+ }
+
+ @Override
+ public void resume() throws EntitlementUserApiException {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public UUID getId() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public UUID getBundleId() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public SubscriptionState getState() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public DateTime getStartDate() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public DateTime getEndDate() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public Plan getCurrentPlan() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public String getCurrentPriceList() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public PlanPhase getCurrentPhase() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public DateTime getChargedThroughDate() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public DateTime getPaidThroughDate() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<SubscriptionTransition> getActiveTransitions() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<SubscriptionTransition> getAllTransitions() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public SubscriptionTransition getPendingTransition() {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public SubscriptionTransition getPreviousTransition() {
+ throw new UnsupportedOperationException();
+ }
+
+}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
index d2fcdee..67c27fa 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
@@ -16,17 +16,15 @@
package com.ning.billing.invoice.notification;
+import static com.jayway.awaitility.Awaitility.await;
+import static java.util.concurrent.TimeUnit.MINUTES;
+
import java.io.IOException;
import java.sql.SQLException;
+import java.util.List;
import java.util.UUID;
import java.util.concurrent.Callable;
-import com.ning.billing.catalog.DefaultCatalogService;
-import com.ning.billing.catalog.api.CatalogService;
-import com.ning.billing.config.CatalogConfig;
-import com.ning.billing.entitlement.engine.dao.EntitlementDao;
-import com.ning.billing.entitlement.engine.dao.EntitlementSqlDao;
-import com.ning.billing.util.bus.InMemoryBus;
import org.apache.commons.io.IOUtils;
import org.joda.time.DateTime;
import org.skife.config.ConfigurationObjectFactory;
@@ -38,25 +36,36 @@ import org.slf4j.LoggerFactory;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import com.google.common.eventbus.Subscribe;
+
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
+import com.ning.billing.catalog.DefaultCatalogService;
+import com.ning.billing.catalog.api.CatalogService;
+import com.ning.billing.config.CatalogConfig;
import com.ning.billing.config.InvoiceConfig;
import com.ning.billing.dbi.MysqlTestingHelper;
+import com.ning.billing.entitlement.api.migration.AccountMigrationData;
+import com.ning.billing.entitlement.api.user.Subscription;
+import com.ning.billing.entitlement.api.user.SubscriptionBundle;
+import com.ning.billing.entitlement.api.user.SubscriptionBundleData;
+import com.ning.billing.entitlement.api.user.SubscriptionData;
+import com.ning.billing.entitlement.engine.dao.EntitlementDao;
+import com.ning.billing.entitlement.engine.dao.EntitlementSqlDao;
+import com.ning.billing.entitlement.events.EntitlementEvent;
+import com.ning.billing.invoice.InvoiceListener;
+import com.ning.billing.invoice.dao.DefaultInvoiceDao;
import com.ning.billing.lifecycle.KillbillService.ServiceException;
+import com.ning.billing.util.bus.Bus;
+import com.ning.billing.util.bus.InMemoryBus;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.clock.ClockMock;
-import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
import com.ning.billing.util.notificationq.DummySqlTest;
import com.ning.billing.util.notificationq.NotificationQueueService;
import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
-import static com.jayway.awaitility.Awaitility.await;
-import static java.util.concurrent.TimeUnit.MINUTES;
-
public class TestNextBillingDateNotifier {
private static Logger log = LoggerFactory.getLogger(TestNextBillingDateNotifier.class);
private Clock clock;
@@ -64,7 +73,159 @@ public class TestNextBillingDateNotifier {
private DummySqlTest dao;
private Bus eventBus;
private MysqlTestingHelper helper;
+ private InvoiceListenerMock listener = new InvoiceListenerMock();
+ private NotificationQueueService notificationQueueService;
+
+ private static final class InvoiceListenerMock extends InvoiceListener {
+ int eventCount = 0;
+ UUID latestSubscriptionId = null;
+
+ public InvoiceListenerMock() {
+ super(null);
+ }
+
+
+ @Override
+ public void handleNextBillingDateEvent(UUID subscriptionId,
+ DateTime eventDateTime) {
+ eventCount++;
+ latestSubscriptionId=subscriptionId;
+ }
+
+ public int getEventCount() {
+ return eventCount;
+ }
+
+ public UUID getLatestSubscriptionId(){
+ return latestSubscriptionId;
+ }
+
+ }
+
+ private class MockEntitlementDao implements EntitlementDao {
+
+ @Override
+ public List<SubscriptionBundle> getSubscriptionBundleForAccount(
+ UUID accountId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SubscriptionBundle getSubscriptionBundleFromKey(String bundleKey) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SubscriptionBundle getSubscriptionBundleFromId(UUID bundleId) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SubscriptionBundle createSubscriptionBundle(
+ SubscriptionBundleData bundle) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public Subscription getSubscriptionFromId(UUID subscriptionId) {
+ return new BrainDeadSubscription();
+
+ }
+
+ @Override
+ public UUID getAccountIdFromSubscriptionId(UUID subscriptionId) {
+ throw new UnsupportedOperationException();
+
+ }
+ @Override
+ public Subscription getBaseSubscription(UUID bundleId) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<Subscription> getSubscriptions(UUID bundleId) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<Subscription> getSubscriptionsForKey(String bundleKey) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void updateSubscription(SubscriptionData subscription) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void createNextPhaseEvent(UUID subscriptionId,
+ EntitlementEvent nextPhase) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public EntitlementEvent getEventById(UUID eventId) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<EntitlementEvent> getEventsForSubscription(
+ UUID subscriptionId) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public List<EntitlementEvent> getPendingEventsForSubscription(
+ UUID subscriptionId) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void createSubscription(SubscriptionData subscription,
+ List<EntitlementEvent> initialEvents) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void cancelSubscription(UUID subscriptionId,
+ EntitlementEvent cancelEvent) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void uncancelSubscription(UUID subscriptionId,
+ List<EntitlementEvent> uncancelEvents) {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void changePlan(UUID subscriptionId,
+ List<EntitlementEvent> changeEvents) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void migrate(UUID acountId, AccountMigrationData data) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void undoMigration(UUID accountId) {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
@BeforeClass(groups={"setup"})
public void setup() throws ServiceException, IOException, ClassNotFoundException, SQLException {
//TestApiBase.loadSystemPropertiesFromClasspath("/entitlement.properties");
@@ -91,7 +252,8 @@ public class TestNextBillingDateNotifier {
dao = dbi.onDemand(DummySqlTest.class);
eventBus = g.getInstance(Bus.class);
helper = g.getInstance(MysqlTestingHelper.class);
- notifier = new DefaultNextBillingDateNotifier(g.getInstance(NotificationQueueService.class), eventBus, g.getInstance(InvoiceConfig.class), g.getInstance(EntitlementDao.class));
+ notificationQueueService = g.getInstance(NotificationQueueService.class);
+ notifier = new DefaultNextBillingDateNotifier(notificationQueueService,g.getInstance(InvoiceConfig.class), new MockEntitlementDao(), listener);
startMysql();
}
@@ -105,48 +267,30 @@ public class TestNextBillingDateNotifier {
helper.initDb(entitlementDdl);
}
- public static class NextBillingEventListener {
- private int eventCount=0;
- private NextBillingDateEvent event;
- public int getEventCount() {
- return eventCount;
- }
-
- @Subscribe
- public synchronized void processEvent(NextBillingDateEvent event) {
- eventCount++;
- this.event = event;
- //log.debug("Got event {} {}", event.name, event.value);
- }
-
- public NextBillingDateEvent getLatestEvent() {
- return event;
- }
- }
-
- @Test(enabled=false, groups="slow")
+ @Test(enabled=true, groups="slow")
public void test() throws Exception {
- final UUID subscriptionId = new UUID(0L,1000L);
+ final UUID subscriptionId = new UUID(0L,1L);
final DateTime now = new DateTime();
final DateTime readyTime = now.plusMillis(2000);
+ final NextBillingDatePoster poster = new DefaultNextBillingDatePoster(notificationQueueService);
- final NextBillingEventListener listener = new NextBillingEventListener();
eventBus.start();
notifier.initialize();
notifier.start();
+
- eventBus.register(listener);
dao.inTransaction(new Transaction<Void, DummySqlTest>() {
@Override
public Void inTransaction(DummySqlTest transactional,
TransactionStatus status) throws Exception {
- notifier.insertNextBillingNotification(transactional, subscriptionId, readyTime);
+ poster.insertNextBillingNotification(transactional, subscriptionId, readyTime);
return null;
}
});
-
+
+
// Move time in the future after the notification effectiveDate
((ClockMock) clock).setDeltaFromReality(3000);
@@ -159,6 +303,6 @@ public class TestNextBillingDateNotifier {
});
Assert.assertEquals(listener.getEventCount(), 1);
- Assert.assertEquals(listener.getLatestEvent().getSubscriptionId(), subscriptionId);
+ Assert.assertEquals(listener.getLatestSubscriptionId(), subscriptionId);
}
}
diff --git a/util/src/main/java/com/ning/billing/util/bus/InMemoryBus.java b/util/src/main/java/com/ning/billing/util/bus/InMemoryBus.java
index 9e4460b..31105c8 100644
--- a/util/src/main/java/com/ning/billing/util/bus/InMemoryBus.java
+++ b/util/src/main/java/com/ning/billing/util/bus/InMemoryBus.java
@@ -28,9 +28,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class InMemoryBus implements Bus {
- // STEPH config ?
- private final static int MAX_EVENT_THREADS = 1;
-
private final static String EVENT_BUS_IDENTIFIER = "bus-service";
private final static String EVENT_BUS_GROUP_NAME = "bus-grp";
private final static String EVENT_BUS_TH_NAME = "bus-th";
@@ -68,7 +65,7 @@ public class InMemoryBus implements Bus {
public InMemoryBus() {
final ThreadGroup group = new ThreadGroup(EVENT_BUS_GROUP_NAME);
- Executor executor = Executors.newFixedThreadPool(MAX_EVENT_THREADS, new ThreadFactory() {
+ Executor executor = Executors.newCachedThreadPool(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(group, r, EVENT_BUS_TH_NAME);
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 3c19a2b..8e2aaf8 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
@@ -38,26 +38,29 @@ public class DefaultNotificationQueue extends NotificationQueueBase {
}
@Override
- protected void doProcessEvents(final int sequenceId) {
+ protected int doProcessEvents(final int sequenceId) {
logDebug("ENTER doProcessEvents");
List<Notification> notifications = getReadyNotifications(sequenceId);
if (notifications.size() == 0) {
logDebug("EXIT doProcessEvents");
- return;
+ return 0;
}
logDebug("START processing %d events at time %s", notifications.size(), clock.getUTCNow().toDate());
+ int result = 0;
for (final Notification cur : notifications) {
nbProcessedEvents.incrementAndGet();
logDebug("handling notification %s, key = %s for time %s",
cur.getUUID(), cur.getNotificationKey(), cur.getEffectiveDate());
- handler.handleReadyNotification(cur.getNotificationKey());
+ handler.handleReadyNotification(cur.getNotificationKey(), cur.getEffectiveDate());
+ result++;
clearNotification(cur);
logDebug("done handling notification %s, key = %s for time %s",
cur.getUUID(), cur.getNotificationKey(), cur.getEffectiveDate());
}
+ return result;
}
@Override
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
index 4ea38f7..e1dcdbf 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueue.java
@@ -38,8 +38,9 @@ public interface NotificationQueue {
* This is only valid when the queue has been configured with isNotificationProcessingOff is true
* In which case, it will callback users for all the ready notifications.
*
+ * @return the number of entries we processed
*/
- public void processReadyNotification();
+ public int processReadyNotification();
/**
* Stops the queue. Blocks until queue is completely stopped.
@@ -55,4 +56,10 @@ public interface NotificationQueue {
*/
public void startQueue();
+ /**
+ *
+ * @return the name of that queue
+ */
+ public String getFullQName();
+
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
index 9a42d2e..cc1ea28 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueBase.java
@@ -57,10 +57,10 @@ public abstract class NotificationQueueBase implements NotificationQueue {
// Use this object's monitor for synchronization (no need for volatile)
protected boolean isProcessingEvents;
-
+
private boolean startedComplete = false;
private boolean stoppedComplete = false;
-
+
// Package visibility on purpose
NotificationQueueBase(final Clock clock, final String svcName, final String queueName, final NotificationQueueHandler handler, final NotificationConfig config) {
this.clock = clock;
@@ -88,8 +88,8 @@ public abstract class NotificationQueueBase implements NotificationQueue {
@Override
- public void processReadyNotification() {
- doProcessEvents(sequenceId.incrementAndGet());
+ public int processReadyNotification() {
+ return doProcessEvents(sequenceId.incrementAndGet());
}
@@ -181,14 +181,14 @@ public abstract class NotificationQueueBase implements NotificationQueue {
});
waitForNotificationStartCompletion();
}
-
+
private void completedQueueStop() {
synchronized (this) {
stoppedComplete = true;
this.notifyAll();
}
}
-
+
private void completedQueueStart() {
synchronized (this) {
startedComplete = true;
@@ -233,9 +233,10 @@ public abstract class NotificationQueueBase implements NotificationQueue {
}
}
- protected String getFullQName() {
+ @Override
+ public String getFullQName() {
return svcName + ":" + queueName;
}
- protected abstract void doProcessEvents(int sequenceId);
+ protected abstract int doProcessEvents(int sequenceId);
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueService.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueService.java
index 5cb00aa..4d56b03 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueService.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueService.java
@@ -16,6 +16,8 @@
package com.ning.billing.util.notificationq;
+import org.joda.time.DateTime;
+
public interface NotificationQueueService {
@@ -25,7 +27,7 @@ public interface NotificationQueueService {
*
* @param notificationKey the notification key associated to that notification entry
*/
- public void handleReadyNotification(String notificationKey);
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime);
}
public static final class NotificationQueueAlreadyExists extends Exception {
@@ -76,7 +78,7 @@ public interface NotificationQueueService {
/**
*
* @param services
- * @return
+ * @return the number of processed notifications
*/
- public void triggerManualQueueProcessing(final String [] services);
+ public int triggerManualQueueProcessing(final String [] services, final Boolean keepRunning);
}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
index 7833529..3f8f26f 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueServiceBase.java
@@ -83,8 +83,13 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
}
+ //
+ // Test ONLY
+ //
@Override
- public void triggerManualQueueProcessing(final String [] services) {
+ public int triggerManualQueueProcessing(final String [] services, final Boolean keepRunning) {
+
+ int result = 0;
List<NotificationQueue> manualQueues = null;
if (services == null) {
@@ -102,8 +107,14 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
}
}
for (NotificationQueue cur : manualQueues) {
- cur.processReadyNotification();
+ int processedNotifications = 0;
+ do {
+ processedNotifications = cur.processReadyNotification();
+ log.info("Got {} results from queue {}", processedNotifications, cur.getFullQName());
+ result += processedNotifications;
+ } while(keepRunning && processedNotifications > 0);
}
+ return result;
}
private final void addQueuesForService(final List<NotificationQueue> result, final String svcName) {
diff --git a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
index 72fd8f4..ad3e5d3 100644
--- a/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
+++ b/util/src/test/java/com/ning/billing/util/clock/ClockMock.java
@@ -38,13 +38,13 @@ public class ClockMock extends DefaultClock {
private long deltaFromRealityMs;
private List<Duration> deltaFromRealityDuration;
- private long deltaFromRealitDurationEpsilon;
+ private long deltaFromRealityDurationEpsilon;
private DeltaType deltaType;
public ClockMock() {
deltaType = DeltaType.DELTA_NONE;
deltaFromRealityMs = 0;
- deltaFromRealitDurationEpsilon = 0;
+ deltaFromRealityDurationEpsilon = 0;
deltaFromRealityDuration = null;
}
@@ -58,7 +58,7 @@ public class ClockMock extends DefaultClock {
return getNow(DateTimeZone.UTC);
}
- private void logClockAdjustement(DateTime prev, DateTime next) {
+ private void logClockAdjustment(DateTime prev, DateTime next) {
log.info(String.format(" ************ ADJUSTING CLOCK FROM %s to %s ********************", prev, next));
}
@@ -67,9 +67,9 @@ public class ClockMock extends DefaultClock {
deltaType = DeltaType.DELTA_DURATION;
deltaFromRealityDuration = new ArrayList<Duration>();
deltaFromRealityDuration.add(delta);
- deltaFromRealitDurationEpsilon = epsilon;
+ deltaFromRealityDurationEpsilon = epsilon;
deltaFromRealityMs = 0;
- logClockAdjustement(prev, getUTCNow());
+ logClockAdjustment(prev, getUTCNow());
}
public synchronized void addDeltaFromReality(Duration delta) {
@@ -78,16 +78,16 @@ public class ClockMock extends DefaultClock {
throw new RuntimeException("ClockMock should be set with type DELTA_DURATION");
}
deltaFromRealityDuration.add(delta);
- logClockAdjustement(prev, getUTCNow());
+ logClockAdjustment(prev, getUTCNow());
}
public synchronized void setDeltaFromReality(long delta) {
DateTime prev = getUTCNow();
deltaType = DeltaType.DELTA_ABS;
deltaFromRealityDuration = null;
- deltaFromRealitDurationEpsilon = 0;
+ deltaFromRealityDurationEpsilon = 0;
deltaFromRealityMs = delta;
- logClockAdjustement(prev, getUTCNow());
+ logClockAdjustment(prev, getUTCNow());
}
public synchronized void addDeltaFromReality(long delta) {
@@ -96,15 +96,15 @@ public class ClockMock extends DefaultClock {
throw new RuntimeException("ClockMock should be set with type DELTA_ABS");
}
deltaFromRealityDuration = null;
- deltaFromRealitDurationEpsilon = 0;
+ deltaFromRealityDurationEpsilon = 0;
deltaFromRealityMs += delta;
- logClockAdjustement(prev, getUTCNow());
+ logClockAdjustment(prev, getUTCNow());
}
public synchronized void resetDeltaFromReality() {
deltaType = DeltaType.DELTA_NONE;
deltaFromRealityDuration = null;
- deltaFromRealitDurationEpsilon = 0;
+ deltaFromRealityDurationEpsilon = 0;
deltaFromRealityMs = 0;
}
@@ -125,8 +125,6 @@ public class ClockMock extends DefaultClock {
DateTime result = input;
for (Duration cur : deltaFromRealityDuration) {
-
- int length = cur.getNumber();
switch (cur.getUnit()) {
case DAYS:
result = result.plusDays(cur.getNumber());
@@ -142,11 +140,11 @@ public class ClockMock extends DefaultClock {
case UNLIMITED:
default:
- throw new RuntimeException("ClockMock is adjusting an unlimtited time period");
+ throw new RuntimeException("ClockMock is adjusting an unlimited time period");
}
}
- if (deltaFromRealitDurationEpsilon != 0) {
- result = result.plus(deltaFromRealitDurationEpsilon);
+ if (deltaFromRealityDurationEpsilon != 0) {
+ result = result.plus(deltaFromRealityDurationEpsilon);
}
return result;
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
index e1da366..e96d2cf 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueue.java
@@ -59,7 +59,9 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
}
@Override
- protected void doProcessEvents(int sequenceId) {
+ protected int doProcessEvents(int sequenceId) {
+
+ int result = 0;
List<Notification> processedNotifications = new ArrayList<Notification>();
List<Notification> oldNotifications = new ArrayList<Notification>();
@@ -73,8 +75,10 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
readyNotifications.add(cur);
}
}
+
+ result = readyNotifications.size();
for (Notification cur : readyNotifications) {
- handler.handleReadyNotification(cur.getNotificationKey());
+ handler.handleReadyNotification(cur.getNotificationKey(), cur.getEffectiveDate());
DefaultNotification processedNotification = new DefaultNotification(-1L, cur.getUUID(), hostname, "MockQueue", clock.getUTCNow().plus(config.getDaoClaimTimeMs()), NotificationLifecycleState.PROCESSED, cur.getNotificationKey(), cur.getEffectiveDate());
oldNotifications.add(cur);
processedNotifications.add(processedNotification);
@@ -87,6 +91,6 @@ public class MockNotificationQueue extends NotificationQueueBase implements Noti
notifications.addAll(processedNotifications);
}
}
-
+ return result;
}
}
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
index eac2d78..fbcf8f9 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/TestNotificationQueue.java
@@ -48,7 +48,6 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.inject.AbstractModule;
import com.google.inject.Inject;
-import com.google.inject.name.Named;
import com.google.inject.name.Names;
import com.ning.billing.dbi.MysqlTestingHelper;
import com.ning.billing.util.clock.Clock;
@@ -119,7 +118,7 @@ public class TestNotificationQueue {
final DefaultNotificationQueue queue = new DefaultNotificationQueue(dbi, clock, "test-svc", "foo",
new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime) {
synchronized (expectedNotifications) {
log.info("Handler received key: " + notificationKey);
@@ -182,7 +181,7 @@ public class TestNotificationQueue {
final DefaultNotificationQueue queue = new DefaultNotificationQueue(dbi, clock, "test-svc", "many",
new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime) {
synchronized (expectedNotifications) {
expectedNotifications.put(notificationKey, Boolean.TRUE);
expectedNotifications.notify();
@@ -292,7 +291,7 @@ public class TestNotificationQueue {
final NotificationQueue queueFred = notificationQueueService.createNotificationQueue("UtilTest", "Fred", new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime) {
log.info("Fred received key: " + notificationKey);
expectedNotificationsFred.put(notificationKey, Boolean.TRUE);
eventsReceived++;
@@ -302,7 +301,7 @@ public class TestNotificationQueue {
final NotificationQueue queueBarney = notificationQueueService.createNotificationQueue("UtilTest", "Barney", new NotificationQueueHandler() {
@Override
- public void handleReadyNotification(String notificationKey) {
+ public void handleReadyNotification(String notificationKey, DateTime eventDateTime) {
log.info("Barney received key: " + notificationKey);
expectedNotificationsBarney.put(notificationKey, Boolean.TRUE);
eventsReceived++;