killbill-memoizeit

Changes

Details

diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/MockOverdueService.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/MockOverdueService.java
index caf6d33..df76116 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/MockOverdueService.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/MockOverdueService.java
@@ -19,7 +19,7 @@ package com.ning.billing.beatrix.integration.overdue;
 import javax.inject.Named;
 
 import com.google.inject.Inject;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.overdue.notification.OverdueNotifier;
 import com.ning.billing.overdue.OverdueProperties;
 import com.ning.billing.overdue.OverdueUserApi;
 import com.ning.billing.overdue.glue.DefaultOverdueModule;
diff --git a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
index 0859297..477ad68 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/applicator/OverdueStateApplicator.java
@@ -49,9 +49,9 @@ import com.ning.billing.invoice.api.InvoiceApiException;
 import com.ning.billing.invoice.api.InvoiceInternalApi;
 import com.ning.billing.junction.BlockingInternalApi;
 import com.ning.billing.junction.DefaultBlockingState;
-import com.ning.billing.ovedue.notification.OverdueCheckNotificationKey;
-import com.ning.billing.ovedue.notification.OverdueCheckNotifier;
-import com.ning.billing.ovedue.notification.OverduePoster;
+import com.ning.billing.overdue.notification.OverdueCheckNotificationKey;
+import com.ning.billing.overdue.notification.OverdueCheckNotifier;
+import com.ning.billing.overdue.notification.OverduePoster;
 import com.ning.billing.overdue.OverdueApiException;
 import com.ning.billing.overdue.OverdueCancellationPolicy;
 import com.ning.billing.overdue.OverdueService;
diff --git a/overdue/src/main/java/com/ning/billing/overdue/glue/DefaultOverdueModule.java b/overdue/src/main/java/com/ning/billing/overdue/glue/DefaultOverdueModule.java
index 0fca842..18550e2 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/glue/DefaultOverdueModule.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/glue/DefaultOverdueModule.java
@@ -20,13 +20,12 @@ import org.skife.config.ConfigSource;
 import org.skife.config.ConfigurationObjectFactory;
 
 import com.ning.billing.glue.OverdueModule;
-import com.ning.billing.ovedue.notification.DefaultOverduePosterBase;
-import com.ning.billing.ovedue.notification.OverdueAsyncBusNotifier;
-import com.ning.billing.ovedue.notification.OverdueAsyncBusPoster;
-import com.ning.billing.ovedue.notification.OverdueCheckNotifier;
-import com.ning.billing.ovedue.notification.OverdueCheckPoster;
-import com.ning.billing.ovedue.notification.OverduePoster;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.overdue.notification.OverdueAsyncBusNotifier;
+import com.ning.billing.overdue.notification.OverdueAsyncBusPoster;
+import com.ning.billing.overdue.notification.OverdueCheckNotifier;
+import com.ning.billing.overdue.notification.OverdueCheckPoster;
+import com.ning.billing.overdue.notification.OverduePoster;
+import com.ning.billing.overdue.notification.OverdueNotifier;
 import com.ning.billing.overdue.OverdueProperties;
 import com.ning.billing.overdue.OverdueService;
 import com.ning.billing.overdue.OverdueUserApi;
diff --git a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
index bd69aa2..8e37747 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/listener/OverdueListener.java
@@ -24,13 +24,12 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.ning.billing.ObjectType;
+import com.ning.billing.bus.api.BusEvent;
 import com.ning.billing.clock.Clock;
-import com.ning.billing.ovedue.notification.OverdueAsyncBusNotificationKey;
-import com.ning.billing.ovedue.notification.OverdueAsyncBusNotificationKey.OverdueAsyncBusNotificationAction;
-import com.ning.billing.ovedue.notification.OverdueAsyncBusNotifier;
-import com.ning.billing.ovedue.notification.OverdueCheckNotificationKey;
-import com.ning.billing.ovedue.notification.OverdueCheckNotifier;
-import com.ning.billing.ovedue.notification.OverduePoster;
+import com.ning.billing.overdue.notification.OverdueAsyncBusNotificationKey;
+import com.ning.billing.overdue.notification.OverdueAsyncBusNotificationKey.OverdueAsyncBusNotificationAction;
+import com.ning.billing.overdue.notification.OverdueAsyncBusNotifier;
+import com.ning.billing.overdue.notification.OverduePoster;
 import com.ning.billing.overdue.glue.DefaultOverdueModule;
 import com.ning.billing.util.callcontext.CallOrigin;
 import com.ning.billing.callcontext.InternalCallContext;
@@ -69,18 +68,14 @@ public class OverdueListener {
     @Subscribe
     public void handle_OVERDUE_ENFORCEMENT_OFF_Insert(final ControlTagCreationInternalEvent event) {
         if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) {
-            final UUID accountId = event.getObjectId();
-            final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, OverdueAsyncBusNotificationAction.CLEAR);
-            asyncPoster.insertOverdueNotification(accountId, clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
+            insertBusEventIntoNotificationQueue(event.getObjectId(), event, OverdueAsyncBusNotificationAction.CLEAR);
         }
     }
 
     @Subscribe
     public void handle_OVERDUE_ENFORCEMENT_OFF_Removal(final ControlTagDeletionInternalEvent event) {
         if (event.getTagDefinition().getName().equals(ControlTagType.OVERDUE_ENFORCEMENT_OFF.toString()) && event.getObjectType() == ObjectType.ACCOUNT) {
-            final UUID accountId = event.getObjectId();
-            final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, OverdueAsyncBusNotificationAction.REFRESH);
-            asyncPoster.insertOverdueNotification(accountId, clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
+            insertBusEventIntoNotificationQueue(event.getObjectId(), event, OverdueAsyncBusNotificationAction.REFRESH);
         }
     }
 
@@ -88,32 +83,25 @@ public class OverdueListener {
     @Subscribe
     public void handlePaymentInfoEvent(final PaymentInfoInternalEvent event) {
         log.debug("Received PaymentInfo event {}", event);
-        final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(event.getAccountId(), OverdueAsyncBusNotificationAction.REFRESH);
-        asyncPoster.insertOverdueNotification(event.getAccountId(), clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
+        insertBusEventIntoNotificationQueue(event.getAccountId(), event, OverdueAsyncBusNotificationAction.REFRESH);
     }
 
     @Subscribe
     public void handlePaymentErrorEvent(final PaymentErrorInternalEvent event) {
         log.debug("Received PaymentError event {}", event);
-        final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(event.getAccountId(), OverdueAsyncBusNotificationAction.REFRESH);
-        asyncPoster.insertOverdueNotification(event.getAccountId(), clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
+        insertBusEventIntoNotificationQueue(event.getAccountId(), event, OverdueAsyncBusNotificationAction.REFRESH);
     }
 
     @Subscribe
     public void handleInvoiceAdjustmentEvent(final InvoiceAdjustmentInternalEvent event) {
         log.debug("Received InvoiceAdjustment event {}", event);
-        final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(event.getAccountId(), OverdueAsyncBusNotificationAction.REFRESH);
-        asyncPoster.insertOverdueNotification(event.getAccountId(), clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
+        insertBusEventIntoNotificationQueue(event.getAccountId(), event, OverdueAsyncBusNotificationAction.REFRESH);
     }
 
-    public void handleProcessOverdueForAccount(final UUID accountId, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
-        log.info(String.format("Handle overdue notification processing for id = %s", accountId));
-        dispatcher.processOverdueForAccount(accountId, createCallContext(userToken, accountRecordId, tenantRecordId));
-    }
+    private void insertBusEventIntoNotificationQueue(final UUID accountId, final BusEvent event, final OverdueAsyncBusNotificationAction action) {
+        final OverdueAsyncBusNotificationKey notificationKey = new OverdueAsyncBusNotificationKey(accountId, action);
+        asyncPoster.insertOverdueNotification(accountId, clock.getUTCNow(), OverdueAsyncBusNotifier.OVERDUE_ASYNC_BUS_NOTIFIER_QUEUE, notificationKey, createCallContext(event.getUserToken(), event.getSearchKey1(), event.getSearchKey2()));
 
-    public void handleClearOverdueForAccount(final UUID accountId, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
-        log.info(String.format("Handle overdue notification clear for id = %s", accountId));
-        dispatcher.clearOverdueForAccount(accountId, createCallContext(userToken, accountRecordId, tenantRecordId));
     }
 
     private InternalCallContext createCallContext(final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
diff --git a/overdue/src/main/java/com/ning/billing/overdue/service/DefaultOverdueService.java b/overdue/src/main/java/com/ning/billing/overdue/service/DefaultOverdueService.java
index 4194687..eee40a8 100644
--- a/overdue/src/main/java/com/ning/billing/overdue/service/DefaultOverdueService.java
+++ b/overdue/src/main/java/com/ning/billing/overdue/service/DefaultOverdueService.java
@@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
 import com.ning.billing.bus.api.PersistentBus.EventBusException;
 import com.ning.billing.lifecycle.LifecycleHandlerType;
 import com.ning.billing.lifecycle.LifecycleHandlerType.LifecycleLevel;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.overdue.notification.OverdueNotifier;
 import com.ning.billing.overdue.OverdueProperties;
 import com.ning.billing.overdue.OverdueService;
 import com.ning.billing.overdue.OverdueUserApi;
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueNotifier.java b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueNotifier.java
index 7b6c029..0ddc8f6 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueNotifier.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/MockOverdueNotifier.java
@@ -21,7 +21,6 @@ import java.util.UUID;
 import org.joda.time.DateTime;
 
 import com.ning.billing.notificationq.api.NotificationEvent;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
 
 public class MockOverdueNotifier implements OverdueNotifier {
 
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
index cbac52d..82fb6b9 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueCheckNotifier.java
@@ -27,11 +27,9 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
 import com.ning.billing.account.api.Account;
-import com.ning.billing.ovedue.notification.OverdueCheckNotificationKey;
-import com.ning.billing.ovedue.notification.OverdueCheckNotifier;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.callcontext.InternalCallContext;
 import com.ning.billing.overdue.OverdueTestSuiteWithEmbeddedDB;
-import com.ning.billing.overdue.listener.OverdueListener;
+import com.ning.billing.overdue.listener.OverdueDispatcher;
 import com.ning.billing.util.callcontext.InternalCallContextFactory;
 import com.ning.billing.callcontext.InternalTenantContext;
 
@@ -40,20 +38,22 @@ import static java.util.concurrent.TimeUnit.SECONDS;
 
 public class TestOverdueCheckNotifier extends OverdueTestSuiteWithEmbeddedDB {
 
-    private OverdueListenerMock mockListener;
+    private OverdueDispatcherMock mockDispatcher;
     private OverdueNotifier notifierForMock;
 
-    private static final class OverdueListenerMock extends OverdueListener {
+
+
+    private static final class  OverdueDispatcherMock extends OverdueDispatcher {
 
         int eventCount = 0;
         UUID latestAccountId = null;
 
-        public OverdueListenerMock(final InternalCallContextFactory internalCallContextFactory) {
-            super(null, getClock(), null,internalCallContextFactory);
+        public OverdueDispatcherMock(final InternalCallContextFactory internalCallContextFactory) {
+            super(null);
         }
 
         @Override
-        public void handleProcessOverdueForAccount(final UUID accountId, final UUID userToken, final Long accountRecordId, final Long tenantRecordId) {
+        public void processOverdueForAccount(final UUID accountId, final InternalCallContext context) {
             eventCount++;
             latestAccountId = accountId;
         }
@@ -76,8 +76,8 @@ public class TestOverdueCheckNotifier extends OverdueTestSuiteWithEmbeddedDB {
         final Account account = Mockito.mock(Account.class);
         Mockito.when(accountApi.getAccountById(Mockito.<UUID>any(), Mockito.<InternalTenantContext>any())).thenReturn(account);
 
-        mockListener = new OverdueListenerMock(internalCallContextFactory);
-        notifierForMock = new OverdueCheckNotifier(notificationQueueService, overdueProperties, mockListener);
+        mockDispatcher = new OverdueDispatcherMock(internalCallContextFactory);
+        notifierForMock = new OverdueCheckNotifier(notificationQueueService, overdueProperties, internalCallContextFactory, mockDispatcher);
 
         notifierForMock.initialize();
         notifierForMock.start();
@@ -107,11 +107,11 @@ public class TestOverdueCheckNotifier extends OverdueTestSuiteWithEmbeddedDB {
         await().atMost(5, SECONDS).until(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {
-                return mockListener.getEventCount() == 1;
+                return mockDispatcher.getEventCount() == 1;
             }
         });
 
-        Assert.assertEquals(mockListener.getEventCount(), 1);
-        Assert.assertEquals(mockListener.getLatestAccountId(), accountId);
+        Assert.assertEquals(mockDispatcher.getEventCount(), 1);
+        Assert.assertEquals(mockDispatcher.getLatestAccountId(), accountId);
     }
 }
diff --git a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueNotificationKeyJson.java b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueNotificationKeyJson.java
index 7c8e3f2..3b47b60 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueNotificationKeyJson.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/notification/TestOverdueNotificationKeyJson.java
@@ -21,7 +21,6 @@ import java.util.UUID;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 
-import com.ning.billing.ovedue.notification.OverdueCheckNotificationKey;
 import com.ning.billing.util.jackson.ObjectMapper;
 
 import static org.testng.Assert.assertEquals;
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteNoDB.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteNoDB.java
index 1d77fc2..2eee23d 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteNoDB.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteNoDB.java
@@ -24,10 +24,10 @@ import org.testng.annotations.BeforeMethod;
 
 import com.ning.billing.GuicyKillbillTestSuiteNoDB;
 import com.ning.billing.bus.api.PersistentBus;
-import com.ning.billing.ovedue.notification.OverduePoster;
+import com.ning.billing.overdue.notification.OverduePoster;
 import com.ning.billing.overdue.calculator.BillingStateCalculator;
 import com.ning.billing.notificationq.api.NotificationQueueService;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.overdue.notification.OverdueNotifier;
 import com.ning.billing.overdue.applicator.OverdueBusListenerTester;
 import com.ning.billing.overdue.applicator.OverdueStateApplicator;
 import com.ning.billing.overdue.glue.DefaultOverdueModule;
diff --git a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java
index af20526..085f0b0 100644
--- a/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java
+++ b/overdue/src/test/java/com/ning/billing/overdue/OverdueTestSuiteWithEmbeddedDB.java
@@ -24,10 +24,10 @@ import org.testng.annotations.BeforeMethod;
 
 import com.ning.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
 import com.ning.billing.bus.api.PersistentBus;
-import com.ning.billing.ovedue.notification.OverduePoster;
+import com.ning.billing.overdue.notification.OverduePoster;
 import com.ning.billing.overdue.calculator.BillingStateCalculator;
 import com.ning.billing.notificationq.api.NotificationQueueService;
-import com.ning.billing.ovedue.notification.OverdueNotifier;
+import com.ning.billing.overdue.notification.OverdueNotifier;
 import com.ning.billing.overdue.applicator.OverdueBusListenerTester;
 import com.ning.billing.overdue.applicator.OverdueStateApplicator;
 import com.ning.billing.overdue.glue.DefaultOverdueModule;
diff --git a/util/src/main/resources/accountRecordIdSanity.sql b/util/src/main/resources/accountRecordIdSanity.sql
index 02f8029..42ee9cf 100644
--- a/util/src/main/resources/accountRecordIdSanity.sql
+++ b/util/src/main/resources/accountRecordIdSanity.sql
@@ -15,18 +15,6 @@ from (
   )
   union
   select
-    'ACCOUNT_HISTORY' table_name
-  , count(1) count
-  from audit_log al
-  join account_history t on al.target_record_id = t.record_id
-  where 1 = 1
-  and al.table_name = 'ACCOUNT_HISTORY'
-  and (
-       al.account_record_id != t.account_record_id
-    or al.account_record_id is null
-  )
-  union
-  select
     'BLOCKING_STATES' table_name
   , count(1) count
   from audit_log al