killbill-memoizeit
Changes
invoice/src/main/java/com/ning/billing/invoice/notification/DefaultNextBillingDateNotifier.java 99(+49 -50)
Details
diff --git a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
index f5ed38e..5e467a8 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/api/TestAnalyticsService.java
@@ -281,9 +281,10 @@ public class TestAnalyticsService {
paymentInfoNotification = new DefaultPaymentInfoEvent.Builder().setId(UUID.randomUUID()).setPaymentMethod(PAYMENT_METHOD).setCardCountry(CARD_COUNTRY).build();
final PaymentAttempt paymentAttempt = new DefaultPaymentAttempt(UUID.randomUUID(), invoice.getId(), account.getId(), BigDecimal.TEN,
- ACCOUNT_CURRENCY, clock.getUTCNow(), clock.getUTCNow(), paymentInfoNotification.getPaymentId(), 1, new DateTime(), new DateTime(), PaymentAttemptStatus.COMPLETED_SUCCESS);
+ ACCOUNT_CURRENCY, clock.getUTCNow(), clock.getUTCNow(), paymentInfoNotification.getId(), 1, new DateTime(), new DateTime(), PaymentAttemptStatus.COMPLETED_SUCCESS);
paymentDao.createPaymentAttempt(paymentAttempt, PaymentAttemptStatus.COMPLETED_SUCCESS, context);
paymentDao.savePaymentInfo(paymentInfoNotification, context);
+ paymentDao.updatePaymentAttemptWithPaymentId(paymentAttempt.getId(), paymentInfoNotification.getId(), context);
Assert.assertEquals(paymentDao.getPaymentInfoList(Arrays.asList(invoice.getId())).size(), 1);
}
diff --git a/api/src/main/java/com/ning/billing/ErrorCode.java b/api/src/main/java/com/ning/billing/ErrorCode.java
index 860ae6c..af590b0 100644
--- a/api/src/main/java/com/ning/billing/ErrorCode.java
+++ b/api/src/main/java/com/ning/billing/ErrorCode.java
@@ -206,6 +206,7 @@ public enum ErrorCode {
/*
* Range 7000 : Payment
*/
+ PAYMENT_INTERNAL_ERROR(7010, "Internal payment error : %s"),
PAYMENT_NO_SUCH_PAYMENT_METHOD(7001, "Payment method for account %s, and paymentId %s does not exist"),
PAYMENT_NO_PAYMENT_METHODS(7002, "Payment methods for account %s don't exist"),
PAYMENT_UPD_GATEWAY_FAILED(7003, "Failed to update payment gateway for account %s : %s"),
@@ -220,6 +221,7 @@ public enum ErrorCode {
PAYMENT_CREATE_PAYMENT_PROVIDER_ACCOUNT(7012, "Failed to create payment provider account for account %s : %s"),
PAYMENT_UPD_PAYMENT_PROVIDER_ACCOUNT(7013, "Failed to update payment provider account for account %s : %s"),
PAYMENT_CREATE_REFUND(7014, "Failed to create refund for account %s : %s"),
+
/*
*
* Range 9000: Miscellaneous
diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentApiException.java b/api/src/main/java/com/ning/billing/payment/api/PaymentApiException.java
index 90a843f..5c3113b 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentApiException.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentApiException.java
@@ -25,7 +25,6 @@ public class PaymentApiException extends BillingExceptionBase {
private static final long serialVersionUID = 39445033L;
-
public PaymentApiException(AccountApiException e) {
super(e, e.getCode(), e.getMessage());
}
diff --git a/api/src/main/java/com/ning/billing/payment/api/PaymentInfoEvent.java b/api/src/main/java/com/ning/billing/payment/api/PaymentInfoEvent.java
index ab200cd..7cbd73d 100644
--- a/api/src/main/java/com/ning/billing/payment/api/PaymentInfoEvent.java
+++ b/api/src/main/java/com/ning/billing/payment/api/PaymentInfoEvent.java
@@ -26,8 +26,6 @@ public interface PaymentInfoEvent extends Entity, BusEvent {
public UUID getAccountId();
- public UUID getPaymentId();
-
public BigDecimal getAmount();
public String getBankIdentificationNumber();
diff --git a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentInfoPlugin.java b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentInfoPlugin.java
index 9b2d8ef..8f1117b 100644
--- a/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentInfoPlugin.java
+++ b/api/src/main/java/com/ning/billing/payment/plugin/api/PaymentInfoPlugin.java
@@ -22,9 +22,6 @@ import org.joda.time.DateTime;
public interface PaymentInfoPlugin {
- // STEPH How can plugin have paymentId?
- public UUID getPaymentId();
-
public BigDecimal getAmount();
public String getBankIdentificationNumber();
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
index dae1175..4885843 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegration.java
@@ -332,6 +332,10 @@ public class TestIntegration extends TestIntegrationBase {
clock.addDeltaFromReality(AT_LEAST_ONE_MONTH_MS);
+ // STEPH
+ /*
+ Thread.sleep(6000000);
+ */
assertTrue(busHandler.isCompleted(DELAY));
startDate = subscription.getCurrentPhaseStart();
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 344f47e..d5b9fb1 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
@@ -64,6 +64,7 @@ import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
@@ -155,11 +156,13 @@ public class Engine implements EventListener, EntitlementService {
}
@LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
if (subscriptionEventQueue != null) {
subscriptionEventQueue.stopQueue();
+ notificationQueueService.deleteNotificationQueue(subscriptionEventQueue.getServiceName(), subscriptionEventQueue.getQueueName());
}
}
+
@Override
public void processEventReady(final EntitlementEvent event, final int seqId, final CallContext context) {
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
index 7d1389e..337ef59 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/api/TestApiBase.java
@@ -184,8 +184,7 @@ public abstract class TestApiBase implements TestListenerStatus {
setupDao();
- ((DefaultCatalogService) catalogService).loadCatalog();
- ((Engine) entitlementService).initialize();
+ ((DefaultCatalogService) catalogService).loadCatalog();
accountData = getAccountData();
assertNotNull(accountData);
@@ -230,6 +229,7 @@ public abstract class TestApiBase implements TestListenerStatus {
busService.getBus().register(testListener);
// START NOTIFICATION QUEUE FOR ENTITLEMENT
+ ((Engine) entitlementService).initialize();
((Engine)entitlementService).start();
// SETUP START DATE
diff --git a/invoice/src/main/java/com/ning/billing/invoice/api/DefaultInvoiceService.java b/invoice/src/main/java/com/ning/billing/invoice/api/DefaultInvoiceService.java
index da41e77..9b80d9c 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/api/DefaultInvoiceService.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/api/DefaultInvoiceService.java
@@ -22,6 +22,8 @@ import com.ning.billing.invoice.notification.NextBillingDateNotifier;
import com.ning.billing.lifecycle.LifecycleHandlerType;
import com.ning.billing.lifecycle.LifecycleHandlerType.LifecycleLevel;
import com.ning.billing.util.bus.Bus;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
+import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
public class DefaultInvoiceService implements InvoiceService {
@@ -44,7 +46,7 @@ public class DefaultInvoiceService implements InvoiceService {
}
@LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.INIT_SERVICE)
- public void initialize() {
+ public void initialize() throws NotificationQueueAlreadyExists {
dateNotifier.initialize();
}
@@ -72,7 +74,7 @@ public class DefaultInvoiceService implements InvoiceService {
}
@LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
dateNotifier.stop();
}
}
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 d61e206..4418dd9 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
@@ -32,6 +32,7 @@ import com.ning.billing.invoice.InvoiceListener;
import com.ning.billing.invoice.api.DefaultInvoiceService;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
@@ -42,75 +43,73 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier
public static final String NEXT_BILLING_DATE_NOTIFIER_QUEUE = "next-billing-date-queue";
private final NotificationQueueService notificationQueueService;
- private final InvoiceConfig config;
- private final EntitlementUserApi entitlementUserApi;
+ private final InvoiceConfig config;
+ private final EntitlementUserApi entitlementUserApi;
+
-
private NotificationQueue nextBillingQueue;
- private final InvoiceListener listener;
+ private final InvoiceListener listener;
@Inject
- public DefaultNextBillingDateNotifier(NotificationQueueService notificationQueueService,
- InvoiceConfig config, EntitlementUserApi entitlementUserApi, InvoiceListener listener){
- this.notificationQueueService = notificationQueueService;
- this.config = config;
+ public DefaultNextBillingDateNotifier(NotificationQueueService notificationQueueService,
+ InvoiceConfig config, EntitlementUserApi entitlementUserApi, InvoiceListener listener){
+ this.notificationQueueService = notificationQueueService;
+ this.config = config;
this.entitlementUserApi = entitlementUserApi;
this.listener = listener;
- }
+ }
@Override
- public void initialize() {
- try {
- nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
- NEXT_BILLING_DATE_NOTIFIER_QUEUE,
- new NotificationQueueHandler() {
- @Override
- public void handleReadyNotification(String notificationKey, DateTime eventDate) {
+ public void initialize() throws NotificationQueueAlreadyExists {
+ nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
+ NEXT_BILLING_DATE_NOTIFIER_QUEUE,
+ new NotificationQueueHandler() {
+ @Override
+ public void handleReadyNotification(String notificationKey, DateTime eventDate) {
+ try {
+ UUID key = UUID.fromString(notificationKey);
try {
- UUID key = UUID.fromString(notificationKey);
- try {
- Subscription subscription = entitlementUserApi.getSubscriptionFromId(key);
- if (subscription == null) {
- log.warn("Next Billing Date Notification Queue handled spurious notification (key: " + key + ")" );
- } else {
- processEvent(key , eventDate);
- }
- } catch (EntitlementUserApiException e) {
- log.warn("Next Billing Date Notification Queue handled spurious notification (key: " + key + ")", e );
+ Subscription subscription = entitlementUserApi.getSubscriptionFromId(key);
+ if (subscription == null) {
+ log.warn("Next Billing Date Notification Queue handled spurious notification (key: " + key + ")" );
+ } else {
+ processEvent(key , eventDate);
}
- } catch (IllegalArgumentException e) {
- log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
- return;
- }
-
- }
- },
- new NotificationConfig() {
-
- @Override
- public long getSleepTimeMs() {
- return config.getSleepTimeMs();
- }
-
- @Override
- public boolean isNotificationProcessingOff() {
- return config.isNotificationProcessingOff();
+ } catch (EntitlementUserApiException e) {
+ log.warn("Next Billing Date Notification Queue handled spurious notification (key: " + key + ")", e );
+ }
+ } catch (IllegalArgumentException e) {
+ log.error("The key returned from the NextBillingNotificationQueue is not a valid UUID", e);
+ return;
}
- });
- } catch (NotificationQueueAlreadyExists e) {
- throw new RuntimeException(e);
- }
+
+ }
+ },
+ new NotificationConfig() {
+
+ @Override
+ public long getSleepTimeMs() {
+ return config.getSleepTimeMs();
+ }
+
+ @Override
+ public boolean isNotificationProcessingOff() {
+ return config.isNotificationProcessingOff();
+ }
+ });
+
}
@Override
public void start() {
- nextBillingQueue.startQueue();
+ nextBillingQueue.startQueue();
}
@Override
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
if (nextBillingQueue != null) {
- nextBillingQueue.stopQueue();
+ nextBillingQueue.stopQueue();
+ notificationQueueService.deleteNotificationQueue(nextBillingQueue.getServiceName(), nextBillingQueue.getQueueName());
}
}
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 ea630aa..4f4c70a 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,13 +16,16 @@
package com.ning.billing.invoice.notification;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
+import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
+
public interface NextBillingDateNotifier {
- public void initialize();
+ public void initialize() throws NotificationQueueAlreadyExists;
public void start();
- public void stop();
+ public void stop() throws NoSuchNotificationQueue;
}
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 a0eb6d5..38b1203 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
@@ -201,7 +201,7 @@ public class TestNextBillingDateNotifier {
}
@AfterClass(groups="slow")
- public void tearDown() {
+ public void tearDown() throws Exception {
notifier.stop();
helper.stopMysql();
}
diff --git a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
index 26403d0..992274d 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/TestInvoiceDispatcher.java
@@ -100,7 +100,7 @@ public class TestInvoiceDispatcher extends InvoicingTestBase {
private CallContext context;
@BeforeSuite(groups = "slow")
- public void setup() throws IOException
+ public void setup() throws Exception
{
final String invoiceDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/invoice/ddl.sql"));
final String utilDdl = IOUtils.toString(TestInvoiceDispatcher.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
index 93604e1..b331f37 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentApi.java
@@ -270,8 +270,7 @@ public class DefaultPaymentApi implements PaymentApi {
PaymentInfoEvent result = null;
if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0 ) {
- // STEPH null
- PaymentAttempt paymentAttempt = paymentDao.createPaymentAttempt(invoice, null, context);
+ PaymentAttempt paymentAttempt = paymentDao.createPaymentAttempt(invoice, PaymentAttemptStatus.IN_PROCESSING, context);
result = processPaymentWithAccountLocked(plugin, account, invoice, paymentAttempt, context);
}
@@ -304,14 +303,14 @@ public class DefaultPaymentApi implements PaymentApi {
if (paymentMethodInfo instanceof CreditCardPaymentMethodInfo) {
CreditCardPaymentMethodInfo ccPaymentMethod = (CreditCardPaymentMethodInfo)paymentMethodInfo;
- paymentDao.updatePaymentInfo(ccPaymentMethod.getType(), paymentInfo.getPaymentId(), ccPaymentMethod.getCardType(), ccPaymentMethod.getCardCountry(), context);
+ paymentDao.updatePaymentInfo(ccPaymentMethod.getType(), paymentInfo.getId(), ccPaymentMethod.getCardType(), ccPaymentMethod.getCardCountry(), context);
} else if (paymentMethodInfo instanceof PaypalPaymentMethodInfo) {
PaypalPaymentMethodInfo paypalPaymentMethodInfo = (PaypalPaymentMethodInfo)paymentMethodInfo;
- paymentDao.updatePaymentInfo(paypalPaymentMethodInfo.getType(), paymentInfo.getPaymentId(), null, null, context);
+ paymentDao.updatePaymentInfo(paypalPaymentMethodInfo.getType(), paymentInfo.getId(), null, null, context);
}
- if (paymentInfo.getPaymentId() != null) {
- paymentDao.updatePaymentAttemptWithPaymentId(paymentAttempt.getId(), paymentInfo.getPaymentId(), context);
+ if (paymentInfo.getId() != null) {
+ paymentDao.updatePaymentAttemptWithPaymentId(paymentAttempt.getId(), paymentInfo.getId(), context);
}
invoicePaymentApi.notifyOfPaymentAttempt(invoice.getId(),
@@ -472,11 +471,9 @@ public class DefaultPaymentApi implements PaymentApi {
lock = locker.lockWithNumberOfTries(LockerService.PAYMENT, accountExternalKey, NB_LOCK_TRY);
return callback.doOperation();
} catch (LockFailedException e) {
- // Not good!
- log.error(String.format("Failed to lock account %s",
- accountExternalKey), e);
- // STEPH or throws
- return null;
+ String format = String.format("Failed to lock account %s", accountExternalKey);
+ log.error(String.format(format), e);
+ throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, format);
} finally {
if (lock != null) {
lock.release();
diff --git a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
index 367857d..759a4bc 100644
--- a/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
+++ b/payment/src/main/java/com/ning/billing/payment/api/DefaultPaymentInfoEvent.java
@@ -34,7 +34,6 @@ import com.ning.billing.util.bus.BusEvent.BusEventType;
public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEvent {
private final UUID accountId;
- private final UUID paymentId;
private final BigDecimal amount;
private final BigDecimal refundAmount;
private final String paymentNumber;
@@ -54,7 +53,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
@JsonCreator
public DefaultPaymentInfoEvent(@JsonProperty("id") UUID id,
@JsonProperty("accountId") UUID accountId,
- @JsonProperty("paymentId") UUID paymentId,
@JsonProperty("amount") BigDecimal amount,
@JsonProperty("refundAmount") BigDecimal refundAmount,
@JsonProperty("bankIdentificationNumber") String bankIdentificationNumber,
@@ -72,7 +70,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
@JsonProperty("updatedDate") DateTime updatedDate) {
super(id);
this.accountId = accountId;
- this.paymentId = paymentId;
this.amount = amount;
this.refundAmount = refundAmount;
this.bankIdentificationNumber = bankIdentificationNumber;
@@ -93,7 +90,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
public DefaultPaymentInfoEvent(DefaultPaymentInfoEvent src) {
this(src.id,
src.accountId,
- src.paymentId,
src.amount,
src.refundAmount,
src.bankIdentificationNumber,
@@ -110,13 +106,16 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
src.createdDate,
src.updatedDate);
}
+
public DefaultPaymentInfoEvent(PaymentInfoPlugin info, UUID accountId, UUID invoiceId) {
- this(invoiceId, accountId, info.getPaymentId(), info.getAmount(), info.getRefundAmount(), info.getBankIdentificationNumber(), info.getPaymentNumber(),
+ this(UUID.randomUUID(), accountId, info.getAmount(), info.getRefundAmount(), info.getBankIdentificationNumber(), info.getPaymentNumber(),
info.getStatus(), info.getCardType(), info.getReferenceId(), info.getPaymentMethodId(), info.getPaymentMethod(), info.getCardType(), info.getCardCountry(),
null, info.getEffectiveDate(), info.getCreatedDate(), info.getUpdatedDate());
}
+
+
@JsonIgnore
@Override
public BusEventType getBusEventType() {
@@ -133,11 +132,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
}
@Override
- public UUID getPaymentId() {
- return paymentId;
- }
-
- @Override
public UUID getId() {
return id;
}
@@ -243,9 +237,8 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
}
public Builder(DefaultPaymentInfoEvent src) {
- this.accountId = src.accountId;
this.id = src.id;
- this.paymentId = src.paymentId;
+ this.accountId = src.accountId;
this.amount = src.amount;
this.refundAmount = src.refundAmount;
this.paymentNumber = src.paymentNumber;
@@ -358,7 +351,6 @@ public class DefaultPaymentInfoEvent extends EntityBase implements PaymentInfoEv
public PaymentInfoEvent build() {
return new DefaultPaymentInfoEvent(id,
accountId,
- paymentId,
amount,
refundAmount,
bankIdentificationNumber,
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/PaymentAttemptHistoryBinder.java b/payment/src/main/java/com/ning/billing/payment/dao/PaymentAttemptHistoryBinder.java
index 569ef40..2c93e91 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/PaymentAttemptHistoryBinder.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/PaymentAttemptHistoryBinder.java
@@ -53,6 +53,7 @@ public @interface PaymentAttemptHistoryBinder {
q.bind("paymentAttemptDate", getDate(paymentAttempt.getPaymentAttemptDate()));
q.bind("paymentId", paymentAttempt.getPaymentId() == null ? null : paymentAttempt.getPaymentId().toString());
q.bind("retryCount", paymentAttempt.getRetryCount());
+ q.bind("processingStatus", paymentAttempt.getPaymentAttemptStatus().toString());
}
};
}
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java b/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
index 3e54135..f4fb78e 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/PaymentSqlDao.java
@@ -103,7 +103,7 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, UpdatableEn
// STEPH
UUID accountId = null;
- UUID paymentId = getUUID(rs, "payment_id");
+
UUID id = getUUID(rs, "id");
BigDecimal amount = rs.getBigDecimal("amount");
BigDecimal refundAmount = rs.getBigDecimal("refund_amount");
@@ -119,11 +119,9 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, UpdatableEn
DateTime effectiveDate = getDate(rs, "effective_date");
DateTime createdDate = getDate(rs, "created_date");
DateTime updatedDate = getDate(rs, "updated_date");
- UUID userToken = rs.getString("user_token") != null ? UUID.fromString(rs.getString("user_token")) : null;
return new DefaultPaymentInfoEvent(id,
accountId,
- paymentId,
amount,
refundAmount,
bankIdentificationNumber,
@@ -135,7 +133,7 @@ public interface PaymentSqlDao extends Transactional<PaymentSqlDao>, UpdatableEn
paymentMethod,
cardType,
cardCountry,
- userToken,
+ null,
effectiveDate,
createdDate,
updatedDate);
diff --git a/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPlugin.java b/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPlugin.java
index af0d547..dcef952 100644
--- a/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPlugin.java
+++ b/payment/src/main/java/com/ning/billing/payment/provider/NoOpPaymentProviderPlugin.java
@@ -71,10 +71,6 @@ public class NoOpPaymentProviderPlugin implements PaymentProviderPlugin {
return null;
}
@Override
- public UUID getPaymentId() {
- return UUID.randomUUID();
- }
- @Override
public DateTime getEffectiveDate() {
return null;
}
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/FailedPaymentRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/FailedPaymentRetryService.java
index 8f686c4..f0d77e8 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/FailedPaymentRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/FailedPaymentRetryService.java
@@ -38,6 +38,7 @@ import com.ning.billing.payment.api.PaymentStatus;
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;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
@@ -51,8 +52,9 @@ public class FailedPaymentRetryService implements RetryService {
private final NotificationQueueService notificationQueueService;
private final PaymentConfig config;
private final PaymentApi paymentApi;
+
private NotificationQueue retryQueue;
-
+
@Inject
public FailedPaymentRetryService(Clock clock,
NotificationQueueService notificationQueueService,
@@ -82,10 +84,11 @@ public class FailedPaymentRetryService implements RetryService {
}
@Override
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
if (retryQueue != null) {
retryQueue.stopQueue();
- }
+ notificationQueueService.deleteNotificationQueue(retryQueue.getServiceName(), retryQueue.getQueueName());
+ }
}
public void scheduleRetry(PaymentAttempt paymentAttempt, DateTime timeOfRetry) {
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/RetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/RetryService.java
index 6809514..52bf1a9 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/RetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/RetryService.java
@@ -15,6 +15,7 @@
*/
package com.ning.billing.payment.retry;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
public interface RetryService {
@@ -24,6 +25,7 @@ public interface RetryService {
public void start();
- public void stop();
+ public void stop()
+ throws NoSuchNotificationQueue;
}
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/TimedoutPaymentRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/TimedoutPaymentRetryService.java
index 4313b24..3eef33b 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/TimedoutPaymentRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/TimedoutPaymentRetryService.java
@@ -32,6 +32,7 @@ import com.ning.billing.util.callcontext.UserType;
import com.ning.billing.util.clock.Clock;
import com.ning.billing.util.notificationq.NotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
@@ -78,9 +79,10 @@ public class TimedoutPaymentRetryService implements RetryService {
}
@Override
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
if (retryQueue != null) {
retryQueue.stopQueue();
+ notificationQueueService.deleteNotificationQueue(retryQueue.getServiceName(), retryQueue.getQueueName());
}
}
diff --git a/payment/src/main/java/com/ning/billing/payment/setup/DefaultPaymentService.java b/payment/src/main/java/com/ning/billing/payment/setup/DefaultPaymentService.java
index 4bc3ed3..5431b85 100644
--- a/payment/src/main/java/com/ning/billing/payment/setup/DefaultPaymentService.java
+++ b/payment/src/main/java/com/ning/billing/payment/setup/DefaultPaymentService.java
@@ -16,12 +16,10 @@
package com.ning.billing.payment.setup;
-import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
-import com.ning.billing.lifecycle.KillbillService;
import com.ning.billing.lifecycle.LifecycleHandlerType;
import com.ning.billing.lifecycle.LifecycleHandlerType.LifecycleLevel;
import com.ning.billing.payment.RequestProcessor;
@@ -30,12 +28,8 @@ import com.ning.billing.payment.api.PaymentService;
import com.ning.billing.payment.retry.FailedPaymentRetryService;
import com.ning.billing.payment.retry.TimedoutPaymentRetryService;
import com.ning.billing.util.bus.Bus;
-import com.ning.billing.util.callcontext.CallContext;
-import com.ning.billing.util.callcontext.CallOrigin;
-import com.ning.billing.util.callcontext.DefaultCallContext;
-import com.ning.billing.util.callcontext.UserType;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists;
-import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
public class DefaultPaymentService implements PaymentService {
private static final Logger log = LoggerFactory.getLogger(DefaultPaymentService.class);
@@ -86,7 +80,7 @@ public class DefaultPaymentService implements PaymentService {
}
@LifecycleHandlerType(LifecycleLevel.STOP_SERVICE)
- public void stop() {
+ public void stop() throws NoSuchNotificationQueue {
failedRetryService.stop();
timedoutRetryService.stop();
}
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
index 15302fe..24df3d6 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentAttemptSqlDao.sql.stg
@@ -10,6 +10,7 @@ paymentAttemptFields(prefix) ::= <<
<prefix>payment_attempt_date,
<prefix>invoice_date,
<prefix>retry_count,
+ <prefix>processing_status,
<prefix>created_by,
<prefix>created_date,
<prefix>updated_by,
@@ -19,7 +20,7 @@ paymentAttemptFields(prefix) ::= <<
insertPaymentAttempt() ::= <<
INSERT INTO payment_attempts (<paymentAttemptFields()>)
VALUES (:id, :invoiceId, :accountId, :amount, :currency, :paymentId,
- :paymentAttemptDate, :invoiceDate, :retryCount, :userName, :createdDate, :userName, :createdDate);
+ :paymentAttemptDate, :invoiceDate, :retryCount, :processingStatus, :userName, :createdDate, :userName, :createdDate);
>>
getPaymentAttemptForPaymentId() ::= <<
@@ -64,6 +65,7 @@ historyFields(prefix) ::= <<
payment_attempt_date,
payment_id,
retry_count,
+ processing_status,
invoice_date,
created_by,
created_date,
@@ -74,7 +76,7 @@ historyFields(prefix) ::= <<
insertHistoryFromTransaction() ::= <<
INSERT INTO payment_attempt_history (<historyFields()>)
VALUES (:recordId, :id, :accountId, :invoiceId, :amount, :currency, :paymentAttemptDate, :paymentId,
- :retryCount, :invoiceDate, :userName, :createdDate, :userName, :updatedDate);
+ :retryCount, :processingStatus, :invoiceDate, :userName, :createdDate, :userName, :updatedDate);
>>
getRecordId() ::= <<
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
index 459b049..3f125ab 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentSqlDao.sql.stg
@@ -1,25 +1,5 @@
group PaymentSqlDao;
-<<<<<<< HEAD
-paymentAttemptFields(prefix) ::= <<
- <prefix>payment_attempt_id,
- <prefix>invoice_id,
- <prefix>account_id,
- <prefix>amount,
- <prefix>currency,
- <prefix>payment_id,
- <prefix>payment_attempt_dt,
- <prefix>invoice_dt,
- <prefix>retry_count,
- <prefix>processing_status,
- <prefix>created_by,
- <prefix>created_dt,
- <prefix>updated_by,
- <prefix>updated_dt
->>
-
-=======
->>>>>>> origin/integration
paymentInfoFields(prefix) ::= <<
<prefix>id,
<prefix>amount,
@@ -37,55 +17,7 @@ paymentInfoFields(prefix) ::= <<
<prefix>created_by,
<prefix>created_date,
<prefix>updated_by,
-<<<<<<< HEAD
- <prefix>updated_dt
->>
-
-insertPaymentAttempt() ::= <<
- INSERT INTO payment_attempts (<paymentAttemptFields()>)
- VALUES (:payment_attempt_id, :invoice_id, :account_id, :amount, :currency, :payment_id,
- :payment_attempt_dt, :invoice_dt, :retry_count, :processing_status, :userName, :createdDate, :userName, :createdDate);
->>
-
-insertPaymentAttemptHistory() ::= <<
- INSERT INTO payment_attempt_history (history_record_id, <paymentAttemptFields()>)
- VALUES (:historyRecordId, :payment_attempt_id, :invoice_id, :account_id, :amount, :currency, :payment_id,
- :payment_attempt_dt, :invoice_dt, :retry_count, :processing_status, :userName, :createdDate, :userName, :createdDate);
->>
-
-getPaymentAttemptForPaymentId() ::= <<
- SELECT <paymentAttemptFields()>
- FROM payment_attempts
- WHERE payment_id = :payment_id
->>
-
-getPaymentAttemptById() ::= <<
- SELECT <paymentAttemptFields()>
- FROM payment_attempts
- WHERE payment_attempt_id = :payment_attempt_id
->>
-
-getPaymentAttemptsForInvoiceIds(invoiceIds) ::= <<
- SELECT <paymentAttemptFields()>
- FROM payment_attempts
- WHERE invoice_id in (<invoiceIds>)
->>
-
-getPaymentAttemptsForInvoiceId() ::= <<
- SELECT <paymentAttemptFields()>
- FROM payment_attempts
- WHERE invoice_id = :invoice_id
->>
-
-updatePaymentAttemptWithPaymentId() ::= <<
- UPDATE payment_attempts
- SET payment_id = :payment_id,
- updated_by = :userName,
- updated_dt = :updatedDate
- WHERE payment_attempt_id = :payment_attempt_id
-=======
<prefix>updated_date
->>>>>>> origin/integration
>>
insertPaymentInfo() ::= <<
@@ -122,7 +54,7 @@ getLastPaymentInfo(invoiceIds) ::= <<
>>
getPaymentInfoForPaymentAttemptId() ::= <<
- SELECT <paymentInfoFields("p.")>,
+ SELECT <paymentInfoFields("p.")>
FROM payments p, payment_attempts pa
WHERE pa.payment_attempt_id = :payment_attempt_id
AND pa.payment_id = p.id
diff --git a/payment/src/main/resources/com/ning/billing/payment/ddl.sql b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
index e2b0ff8..7ef4570 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -1,22 +1,5 @@
DROP TABLE IF EXISTS payment_attempts;
CREATE TABLE payment_attempts (
-<<<<<<< HEAD
- payment_attempt_id char(36) COLLATE utf8_bin NOT NULL,
- account_id char(36) COLLATE utf8_bin NOT NULL,
- invoice_id char(36) COLLATE utf8_bin NOT NULL,
- amount decimal(8,2),
- currency char(3),
- payment_attempt_dt datetime NOT NULL,
- payment_id varchar(36) COLLATE utf8_bin,
- retry_count tinyint,
- processing_status varchar(20),
- invoice_dt datetime NOT NULL,
- created_by varchar(50) NOT NULL,
- created_dt datetime NOT NULL,
- updated_by varchar(50) NOT NULL,
- updated_dt datetime NOT NULL,
- PRIMARY KEY (payment_attempt_id)
-=======
record_id int(11) unsigned NOT NULL AUTO_INCREMENT,
id char(36) NOT NULL,
account_id char(36) COLLATE utf8_bin NOT NULL,
@@ -26,13 +9,13 @@ CREATE TABLE payment_attempts (
payment_attempt_date datetime NOT NULL,
payment_id varchar(36) COLLATE utf8_bin,
retry_count tinyint,
+ processing_status varchar(20),
invoice_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
updated_by varchar(50) NOT NULL,
updated_date datetime NOT NULL,
PRIMARY KEY (record_id)
->>>>>>> origin/integration
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
CREATE INDEX payment_attempts_account_id_invoice_id ON payment_attempts(account_id, invoice_id);
@@ -49,6 +32,7 @@ CREATE TABLE payment_attempt_history (
payment_attempt_date datetime NOT NULL,
payment_id varchar(36) COLLATE utf8_bin,
retry_count tinyint,
+ processing_status varchar(20),
invoice_date datetime NOT NULL,
created_by varchar(50) NOT NULL,
created_date datetime NOT NULL,
diff --git a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
index 71356d6..31e3b6a 100644
--- a/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
+++ b/payment/src/test/java/com/ning/billing/payment/api/TestEventJson.java
@@ -49,7 +49,7 @@ public class TestEventJson {
@Test(groups= {"fast"})
public void testPaymentInfoEvent() throws Exception {
- PaymentInfoEvent e = new DefaultPaymentInfoEvent(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12), new BigDecimal(12.9), "BNP", "eeert", "success",
+ PaymentInfoEvent e = new DefaultPaymentInfoEvent(UUID.randomUUID(), UUID.randomUUID(), new BigDecimal(12), new BigDecimal(12.9), "BNP", "eeert", "success",
"credit", "ref", "paypal", "paypal", "", "", UUID.randomUUID(), new DateTime(), new DateTime(), new DateTime());
String json = mapper.writeValueAsString(e);
diff --git a/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java b/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
index 9c7f2e9..ca341bd 100644
--- a/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
+++ b/payment/src/test/java/com/ning/billing/payment/dao/MockPaymentDao.java
@@ -93,7 +93,7 @@ public class MockPaymentDao implements PaymentDao {
Collection<PaymentAttempt> attempts = Collections2.filter(paymentAttempts.values(), new Predicate<PaymentAttempt>() {
@Override
public boolean apply(PaymentAttempt input) {
- return invoiceId.equals(input.getInvoiceId().toString());
+ return invoiceId.equals(input.getInvoiceId());
}
});
return new ArrayList<PaymentAttempt>(attempts);
diff --git a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
index e8c881c..a4e72ca 100644
--- a/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
+++ b/payment/src/test/java/com/ning/billing/payment/provider/MockPaymentProviderPlugin.java
@@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang.RandomStringUtils;
-import org.apache.commons.lang.StringUtils;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
@@ -33,14 +32,12 @@ import com.google.inject.Inject;
import com.ning.billing.account.api.Account;
import com.ning.billing.invoice.api.Invoice;
import com.ning.billing.payment.api.CreditCardPaymentMethodInfo;
-import com.ning.billing.payment.api.DefaultPaymentErrorEvent;
import com.ning.billing.payment.api.DefaultPaymentInfoEvent;
-import com.ning.billing.payment.api.Either;
-import com.ning.billing.payment.api.PaymentErrorEvent;
import com.ning.billing.payment.api.PaymentInfoEvent;
import com.ning.billing.payment.api.PaymentMethodInfo;
import com.ning.billing.payment.api.PaymentProviderAccount;
import com.ning.billing.payment.api.PaypalPaymentMethodInfo;
+import com.ning.billing.payment.plugin.api.MockPaymentInfoPlugin;
import com.ning.billing.payment.plugin.api.PaymentInfoPlugin;
import com.ning.billing.payment.plugin.api.PaymentPluginApiException;
import com.ning.billing.payment.plugin.api.PaymentProviderPlugin;
@@ -78,10 +75,10 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
.setPaymentNumber("12345")
.setReferenceId("12345")
.setType("Electronic")
+ .setPaymentMethodId("123-456-678-89")
.build();
- // STEPH
- //return payment;
- return null;
+
+ return new MockPaymentInfoPlugin(payment);
}
@@ -91,8 +88,7 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
if (payment == null) {
throw new PaymentPluginApiException("", "No payment found for id " + paymentId);
}
- // STEPH
- return null;
+ return new MockPaymentInfoPlugin(payment);
}
@Override
@@ -173,7 +169,7 @@ public class MockPaymentProviderPlugin implements PaymentProviderPlugin {
new PaymentProviderAccount.Builder()
.copyFrom(account)
// STEPH
- .setDefaultPaymentMethod("")
+ .setDefaultPaymentMethod("paypal")
.build());
List<PaymentMethodInfo> paymentMethodsToUpdate = new ArrayList<PaymentMethodInfo>();
for (PaymentMethodInfo paymentMethod : paymentMethods.values()) {
diff --git a/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithEmbeddedDb.java b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithEmbeddedDb.java
index da38b34..30bbda7 100644
--- a/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithEmbeddedDb.java
+++ b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithEmbeddedDb.java
@@ -26,6 +26,7 @@ import com.ning.billing.mock.BrainDeadProxyFactory;
import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
import com.ning.billing.util.bus.Bus;
import com.ning.billing.util.bus.InMemoryBus;
+import com.ning.billing.util.glue.GlobalLockerModule;
import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
import com.ning.billing.util.notificationq.NotificationQueueService;
@@ -52,5 +53,6 @@ public class PaymentTestModuleWithEmbeddedDb extends PaymentModule {
super.configure();
bind(Bus.class).to(InMemoryBus.class).asEagerSingleton();
bind(NotificationQueueService.class).to(DefaultNotificationQueueService.class).asEagerSingleton();
+ install(new GlobalLockerModule());
}
}
diff --git a/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithMocks.java b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithMocks.java
index 14f2ab9..5394c29 100644
--- a/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithMocks.java
+++ b/payment/src/test/java/com/ning/billing/payment/setup/PaymentTestModuleWithMocks.java
@@ -29,8 +29,11 @@ import com.ning.billing.mock.glue.TestDbiModule;
import com.ning.billing.payment.dao.MockPaymentDao;
import com.ning.billing.payment.dao.PaymentDao;
import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
+import com.ning.billing.util.globallocker.GlobalLocker;
+import com.ning.billing.util.globallocker.MockGlobalLocker;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.BusModule.BusType;
+import com.ning.billing.util.glue.GlobalLockerModule;
public class PaymentTestModuleWithMocks extends PaymentModule {
public static class MockProvider implements Provider<BillingApi> {
@@ -64,5 +67,6 @@ public class PaymentTestModuleWithMocks extends PaymentModule {
install(new MockNotificationQueueModule());
install(new MockInvoiceModule());
install(new TestDbiModule());
+ bind(GlobalLocker.class).to(MockGlobalLocker.class).asEagerSingleton();
}
}
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 f28ff63..71735cd 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
@@ -67,6 +67,16 @@ public interface NotificationQueue extends QueueLifecycle {
* @return the name of that queue
*/
public String getFullQName();
+
+ /**
+ * @return the service name associated to that queue
+ */
+ public String getServiceName();
+
+ /**
+ * @return the queue name associated
+ */
+ public String getQueueName();
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 cd3c0c2..a335668 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
@@ -105,10 +105,19 @@ public abstract class NotificationQueueBase extends PersistentQueueBase implemen
return getFullQName();
}
+ @Override
+ public String getServiceName() {
+ return svcName;
+ }
@Override
+ public String getQueueName() {
+ return queueName;
+ }
+
+
public String getFullQName() {
- return svcName + ":" + queueName;
+ return NotificationQueueServiceBase.getCompositeName(svcName, queueName);
}
@Override
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 828608a..6d05e3a 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
@@ -76,6 +76,18 @@ public interface NotificationQueueService {
public NotificationQueue getNotificationQueue(final String svcName, final String queueName)
throws NoSuchNotificationQueue;
+ /**
+ * Delete notificationQueue
+ *
+ * @param svcName
+ * @param queueName
+ * @return
+ *
+ * @throws NoSuchNotificationQueue if queue does not exist
+ */
+ public void deleteNotificationQueue(final String svcName, final String queueName)
+ throws NoSuchNotificationQueue;
+
/**
*
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 90c27b0..f782484 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
@@ -29,6 +29,7 @@ import com.google.common.base.Joiner;
import com.google.inject.Inject;
import com.ning.billing.config.NotificationConfig;
import com.ning.billing.util.clock.Clock;
+import com.ning.billing.util.notificationq.NotificationQueueService.NoSuchNotificationQueue;
public abstract class NotificationQueueServiceBase implements NotificationQueueService {
@@ -44,6 +45,7 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
this.queues = new TreeMap<String, NotificationQueue>();
}
+
@Override
public NotificationQueue createNotificationQueue(String svcName,
String queueName, NotificationQueueHandler handler,
@@ -82,6 +84,20 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
return result;
}
+
+ public void deleteNotificationQueue(final String svcName, final String queueName)
+ throws NoSuchNotificationQueue {
+ String compositeName = getCompositeName(svcName, queueName);
+ synchronized(queues) {
+ NotificationQueue result = queues.get(compositeName);
+ if (result == null) {
+ throw new NoSuchNotificationQueue(String.format("Queue for svc %s and name %s does not exist",
+ svcName, queueName));
+ }
+ queues.remove(compositeName);
+ }
+ }
+
//
// Test ONLY
@@ -130,7 +146,7 @@ public abstract class NotificationQueueServiceBase implements NotificationQueueS
NotificationConfig config);
- private String getCompositeName(String svcName, String queueName) {
+ public static String getCompositeName(String svcName, String queueName) {
return svcName + ":" + queueName;
}
}