killbill-uncached

Bug fixes for notificationQ rework

11/20/2012 3:19:08 AM

Changes

Details

diff --git a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
index 8d0960e..c1450c0 100644
--- a/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
+++ b/analytics/src/test/java/com/ning/billing/analytics/TestBusinessTagRecorder.java
@@ -59,6 +59,7 @@ import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.config.CatalogConfig;
 import com.ning.billing.util.config.NotificationConfig;
 import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueConfig;
 import com.ning.billing.util.svcapi.account.AccountInternalApi;
 import com.ning.billing.util.svcapi.entitlement.EntitlementInternalApi;
 
@@ -76,7 +77,7 @@ public class TestBusinessTagRecorder extends AnalyticsTestSuiteWithEmbeddedDB {
     private BusinessTagDao tagDao;
 
 
-    private NotificationConfig config = new NotificationConfig() {
+    private NotificationQueueConfig config = new NotificationQueueConfig() {
         @Override
         public boolean isNotificationProcessingOff() {
             return false;
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 27c9eea..b4d8d88 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
@@ -134,22 +134,9 @@ public class Engine implements EventListener, EntitlementService {
                 }
             };
 
-            final NotificationConfig notificationConfig = new NotificationConfig() {
-                @Override
-                public long getSleepTimeMs() {
-                    return config.getSleepTimeMs();
-                }
-
-                @Override
-                public boolean isNotificationProcessingOff() {
-                    return config.isNotificationProcessingOff();
-                }
-            };
-
             subscriptionEventQueue = notificationQueueService.createNotificationQueue(ENTITLEMENT_SERVICE_NAME,
                                                                                       NOTIFICATION_QUEUE_NAME,
-                                                                                      queueHandler,
-                                                                                      notificationConfig);
+                                                                                      queueHandler);
         } catch (NotificationQueueAlreadyExists e) {
             throw new RuntimeException(e);
         }
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
index fff17a9..a580f01 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/MockEngineModuleMemory.java
@@ -17,6 +17,7 @@
 package com.ning.billing.entitlement.glue;
 
 import org.mockito.Mockito;
+import org.skife.config.ConfigurationObjectFactory;
 import org.skife.jdbi.v2.IDBI;
 
 import com.ning.billing.entitlement.api.timeline.RepairEntitlementLifecycleDao;
@@ -28,6 +29,7 @@ import com.ning.billing.util.callcontext.MockCallContextSqlDao;
 import com.ning.billing.util.glue.BusModule;
 import com.ning.billing.util.glue.BusModule.BusType;
 import com.ning.billing.util.notificationq.MockNotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueConfig;
 import com.ning.billing.util.notificationq.NotificationQueueService;
 
 import com.google.inject.name.Names;
@@ -44,6 +46,12 @@ public class MockEngineModuleMemory extends MockEngineModule {
 
     private void installNotificationQueue() {
         bind(NotificationQueueService.class).to(MockNotificationQueueService.class).asEagerSingleton();
+        configureNotificationQueueConfig();
+    }
+
+    protected void configureNotificationQueueConfig() {
+        final NotificationQueueConfig config = new ConfigurationObjectFactory(System.getProperties()).build(NotificationQueueConfig.class);
+        bind(NotificationQueueConfig.class).toInstance(config);
     }
 
     protected void installDBI() {
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 6e3a8d7..41b15a8 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
@@ -68,17 +68,6 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
 
     @Override
     public void initialize() throws NotificationQueueAlreadyExists {
-        final NotificationConfig notificationConfig = new NotificationConfig() {
-            @Override
-            public long getSleepTimeMs() {
-                return config.getSleepTimeMs();
-            }
-
-            @Override
-            public boolean isNotificationProcessingOff() {
-                return config.isNotificationProcessingOff();
-            }
-        };
 
         final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {
             @Override
@@ -108,8 +97,7 @@ public class DefaultNextBillingDateNotifier implements NextBillingDateNotifier {
 
         nextBillingQueue = notificationQueueService.createNotificationQueue(DefaultInvoiceService.INVOICE_SERVICE_NAME,
                                                                             NEXT_BILLING_DATE_NOTIFIER_QUEUE,
-                                                                            notificationQueueHandler,
-                                                                            notificationConfig);
+                                                                            notificationQueueHandler);
     }
 
     @Override
diff --git a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
index 2d1bb07..ad8c7e0 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/dao/InvoiceDaoTestBase.java
@@ -65,16 +65,6 @@ public class InvoiceDaoTestBase extends InvoicingTestBase {
 
     private final InvoiceConfig invoiceConfig = new InvoiceConfig() {
         @Override
-        public long getSleepTimeMs() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
-        public boolean isNotificationProcessingOff() {
-            throw new UnsupportedOperationException();
-        }
-
-        @Override
         public int getNumberOfMonthsInFuture() {
             return 36;
         }
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
index 5864d95..9c4087a 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGenerator.java
@@ -82,11 +82,6 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
         final Clock clock = new DefaultClock();
         final InvoiceConfig invoiceConfig = new InvoiceConfig() {
             @Override
-            public long getSleepTimeMs() {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override
             public int getNumberOfMonthsInFuture() {
                 return 36;
             }
@@ -95,11 +90,6 @@ public class TestDefaultInvoiceGenerator extends InvoicingTestBase {
             public boolean isEmailNotificationsEnabled() {
                 return false;
             }
-
-            @Override
-            public boolean isNotificationProcessingOff() {
-                throw new UnsupportedOperationException();
-            }
         };
         this.generator = new DefaultInvoiceGenerator(clock, invoiceConfig);
     }
diff --git a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
index 1fd99d3..c5c7168 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/generator/TestDefaultInvoiceGeneratorUnit.java
@@ -67,21 +67,11 @@ public class TestDefaultInvoiceGeneratorUnit extends InvoicingTestBase {
         clock = new ClockMock();
         gen = new TestDefaultInvoiceGeneratorMock(clock, new InvoiceConfig() {
             @Override
-            public boolean isNotificationProcessingOff() {
-                return false;
-            }
-
-            @Override
             public boolean isEmailNotificationsEnabled() {
                 return false;
             }
 
             @Override
-            public long getSleepTimeMs() {
-                return 100;
-            }
-
-            @Override
             public int getNumberOfMonthsInFuture() {
                 return 5;
             }
diff --git a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
index 39b7ef4..ffe594f 100644
--- a/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
+++ b/overdue/src/main/java/com/ning/billing/ovedue/notification/DefaultOverdueCheckNotifier.java
@@ -55,18 +55,6 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
 
     @Override
     public void initialize() {
-        final NotificationConfig notificationConfig = new NotificationConfig() {
-            @Override
-            public boolean isNotificationProcessingOff() {
-                return config.isNotificationProcessingOff();
-            }
-
-            @Override
-            public long getSleepTimeMs() {
-                return config.getSleepTimeMs();
-            }
-        };
-
         final NotificationQueueHandler notificationQueueHandler = new NotificationQueueHandler() {
             @Override
             public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDate, final Long accountRecordId, final Long tenantRecordId) {
@@ -88,8 +76,7 @@ public class DefaultOverdueCheckNotifier implements OverdueCheckNotifier {
         try {
             overdueQueue = notificationQueueService.createNotificationQueue(DefaultOverdueService.OVERDUE_SERVICE_NAME,
                                                                             OVERDUE_CHECK_NOTIFIER_QUEUE,
-                                                                            notificationQueueHandler,
-                                                                            notificationConfig);
+                                                                            notificationQueueHandler);
         } catch (NotificationQueueAlreadyExists e) {
             throw new RuntimeException(e);
         }
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/AutoPayRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/AutoPayRetryService.java
index b45819d..5ffb060 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/AutoPayRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/AutoPayRetryService.java
@@ -39,7 +39,7 @@ public class AutoPayRetryService extends BaseRetryService implements RetryServic
                                final PaymentConfig config,
                                final PaymentProcessor paymentProcessor,
                                final InternalCallContextFactory internalCallContextFactory) {
-        super(notificationQueueService, config, internalCallContextFactory);
+        super(notificationQueueService, internalCallContextFactory);
         this.paymentProcessor = paymentProcessor;
     }
 
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
index 2828c63..b22e915 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/BaseRetryService.java
@@ -47,16 +47,13 @@ public abstract class BaseRetryService implements RetryService {
     private static final String PAYMENT_RETRY_SERVICE = "PaymentRetryService";
 
     private final NotificationQueueService notificationQueueService;
-    private final PaymentConfig config;
     private final InternalCallContextFactory internalCallContextFactory;
 
     private NotificationQueue retryQueue;
 
     public BaseRetryService(final NotificationQueueService notificationQueueService,
-                            final PaymentConfig config,
                             final InternalCallContextFactory internalCallContextFactory) {
         this.notificationQueueService = notificationQueueService;
-        this.config = config;
         this.internalCallContextFactory = internalCallContextFactory;
     }
 
@@ -75,8 +72,7 @@ public abstract class BaseRetryService implements RetryService {
                                                                               final InternalCallContext callContext = internalCallContextFactory.createInternalCallContext(tenantRecordId, accountRecordId, PAYMENT_RETRY_SERVICE, CallOrigin.INTERNAL, UserType.SYSTEM, null);
                                                                               retry(key.getUuidKey(), callContext);
                                                                           }
-                                                                      },
-                                                                      config);
+                                                                      });
     }
 
     @Override
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 250987b..c9a80a1 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
@@ -45,7 +45,7 @@ public class FailedPaymentRetryService extends BaseRetryService implements Retry
                                      final PaymentConfig config,
                                      final PaymentProcessor paymentProcessor,
                                      final InternalCallContextFactory internalCallContextFactory) {
-        super(notificationQueueService, config, internalCallContextFactory);
+        super(notificationQueueService, internalCallContextFactory);
         this.paymentProcessor = paymentProcessor;
     }
 
diff --git a/payment/src/main/java/com/ning/billing/payment/retry/PluginFailureRetryService.java b/payment/src/main/java/com/ning/billing/payment/retry/PluginFailureRetryService.java
index 9217abd..2e76ea2 100644
--- a/payment/src/main/java/com/ning/billing/payment/retry/PluginFailureRetryService.java
+++ b/payment/src/main/java/com/ning/billing/payment/retry/PluginFailureRetryService.java
@@ -43,10 +43,9 @@ public class PluginFailureRetryService extends BaseRetryService implements Retry
 
     @Inject
     public PluginFailureRetryService(final NotificationQueueService notificationQueueService,
-                                     final PaymentConfig config,
                                      final PaymentProcessor paymentProcessor,
                                      final InternalCallContextFactory internalCallContextFactory) {
-        super(notificationQueueService, config, internalCallContextFactory);
+        super(notificationQueueService, internalCallContextFactory);
         this.paymentProcessor = paymentProcessor;
     }
 
diff --git a/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
index a01dda5..0da7d2b 100644
--- a/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
+++ b/payment/src/test/java/com/ning/billing/payment/glue/PaymentTestModuleWithMocks.java
@@ -16,8 +16,6 @@
 
 package com.ning.billing.payment.glue;
 
-import static org.testng.Assert.assertNotNull;
-
 import java.io.IOException;
 import java.net.URL;
 import java.util.Properties;
@@ -28,7 +26,6 @@ import org.skife.config.SimplePropertyConfigSource;
 import org.skife.jdbi.v2.IDBI;
 
 import com.ning.billing.ObjectType;
-import com.ning.billing.util.config.PaymentConfig;
 import com.ning.billing.mock.glue.MockInvoiceModule;
 import com.ning.billing.mock.glue.MockNotificationQueueModule;
 import com.ning.billing.payment.dao.MockPaymentDao;
@@ -37,6 +34,7 @@ import com.ning.billing.payment.provider.MockPaymentProviderPluginModule;
 import com.ning.billing.util.callcontext.CallContextSqlDao;
 import com.ning.billing.util.callcontext.InternalTenantContext;
 import com.ning.billing.util.callcontext.MockCallContextSqlDao;
+import com.ning.billing.util.config.PaymentConfig;
 import com.ning.billing.util.globallocker.GlobalLocker;
 import com.ning.billing.util.globallocker.MockGlobalLocker;
 import com.ning.billing.util.glue.BusModule;
@@ -46,9 +44,11 @@ import com.ning.billing.util.svcapi.tag.TagInternalApi;
 import com.ning.billing.util.tag.Tag;
 
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
+
+import static org.testng.Assert.assertNotNull;
 
 public class PaymentTestModuleWithMocks extends PaymentModule {
+
     public static final String PLUGIN_TEST_NAME = "my-mock";
 
     private void loadSystemPropertiesFromClasspath(final String resource) {
diff --git a/util/src/main/java/com/ning/billing/util/config/EntitlementConfig.java b/util/src/main/java/com/ning/billing/util/config/EntitlementConfig.java
index aad7427..30c0ebd 100644
--- a/util/src/main/java/com/ning/billing/util/config/EntitlementConfig.java
+++ b/util/src/main/java/com/ning/billing/util/config/EntitlementConfig.java
@@ -19,14 +19,5 @@ package com.ning.billing.util.config;
 import org.skife.config.Config;
 import org.skife.config.Default;
 
-public interface EntitlementConfig extends NotificationConfig, KillbillConfig {
-    @Override
-    @Config("killbill.entitlement.engine.notifications.sleep")
-    @Default("500")
-    public long getSleepTimeMs();
-
-    @Override
-    @Config("killbill.entitlement.engine.notifications.off")
-    @Default("false")
-    public boolean isNotificationProcessingOff();
+public interface EntitlementConfig extends KillbillConfig {
 }
diff --git a/util/src/main/java/com/ning/billing/util/config/InvoiceConfig.java b/util/src/main/java/com/ning/billing/util/config/InvoiceConfig.java
index a1f8d7b..73db4fc 100644
--- a/util/src/main/java/com/ning/billing/util/config/InvoiceConfig.java
+++ b/util/src/main/java/com/ning/billing/util/config/InvoiceConfig.java
@@ -19,17 +19,7 @@ package com.ning.billing.util.config;
 import org.skife.config.Config;
 import org.skife.config.Default;
 
-public interface InvoiceConfig extends NotificationConfig, KillbillConfig {
-    @Override
-    @Config("killbill.invoice.engine.notifications.sleep")
-    @Default("500")
-    public long getSleepTimeMs();
-
-    @Override
-    @Config("killbill.invoice.engine.notifications.off")
-    @Default("false")
-    public boolean isNotificationProcessingOff();
-
+public interface InvoiceConfig extends KillbillConfig {
     @Config("killbill.invoice.maxNumberOfMonthsInFuture")
     @Default("36")
     public int getNumberOfMonthsInFuture();
diff --git a/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java b/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
index 16a6e4b..f4739d0 100644
--- a/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
+++ b/util/src/main/java/com/ning/billing/util/config/PaymentConfig.java
@@ -43,16 +43,6 @@ public interface PaymentConfig extends NotificationConfig, KillbillConfig {
     @Default("8")
     public int getPluginFailureRetryMaxAttempts();
 
-    @Override
-    @Config("killbill.payment.engine.notifications.sleep")
-    @Default("500")
-    public long getSleepTimeMs();
-
-    @Override
-    @Config("killbill.payment.engine.notifications.off")
-    @Default("false")
-    public boolean isNotificationProcessingOff();
-
     @Config("killbill.payment.off")
     @Default("false")
     public boolean isPaymentOff();
diff --git a/util/src/main/java/com/ning/billing/util/glue/NotificationQueueModule.java b/util/src/main/java/com/ning/billing/util/glue/NotificationQueueModule.java
index 557a6e1..7e4e1c9 100644
--- a/util/src/main/java/com/ning/billing/util/glue/NotificationQueueModule.java
+++ b/util/src/main/java/com/ning/billing/util/glue/NotificationQueueModule.java
@@ -16,15 +16,25 @@
 
 package com.ning.billing.util.glue;
 
+import org.skife.config.ConfigurationObjectFactory;
+
+import com.ning.billing.util.config.NotificationConfig;
 import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
+import com.ning.billing.util.notificationq.NotificationQueueConfig;
 import com.ning.billing.util.notificationq.NotificationQueueService;
 
 import com.google.inject.AbstractModule;
 
 public class NotificationQueueModule extends AbstractModule {
 
+
+    protected void configureNotificationQueueConfig() {
+        final NotificationQueueConfig config = new ConfigurationObjectFactory(System.getProperties()).build(NotificationQueueConfig.class);
+        bind(NotificationQueueConfig.class).toInstance(config);
+    }
     @Override
     protected void configure() {
         bind(NotificationQueueService.class).to(DefaultNotificationQueueService.class).asEagerSingleton();
+        configureNotificationQueueConfig();
     }
 }
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 acb281e..4791d60 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
@@ -143,8 +143,9 @@ public class DefaultNotificationQueue implements NotificationQueue {
 
     @Override
     public void stopQueue() {
-        notificationQueueService.stopQueue();
+        // Order matters...
         isStarted = false;
+        notificationQueueService.stopQueue();
     }
 
     @Override
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
index 277cadf..d56023c 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/DefaultNotificationQueueService.java
@@ -30,7 +30,7 @@ public class DefaultNotificationQueueService extends NotificationQueueServiceBas
     private final IDBI dbi;
 
     @Inject
-    public DefaultNotificationQueueService(final IDBI dbi, final Clock clock, final NotificationConfig config,
+    public DefaultNotificationQueueService(final IDBI dbi, final Clock clock, final NotificationQueueConfig config,
                                            final InternalCallContextFactory internalCallContextFactory) {
         super(clock, config, dbi, internalCallContextFactory);
         this.dbi = dbi;
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueConfig.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueConfig.java
new file mode 100644
index 0000000..512b19d
--- /dev/null
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueConfig.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2010-2012 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.util.notificationq;
+
+import org.skife.config.Config;
+import org.skife.config.Default;
+
+import com.ning.billing.util.config.NotificationConfig;
+
+public interface NotificationQueueConfig extends NotificationConfig {
+
+    @Override
+    @Config("killbill.billing.util.notificationq.sleep")
+    @Default("500")
+    public long getSleepTimeMs();
+
+    @Config("killbill.billing.util.notificationq.notification.off")
+    @Default("false")
+    @Override
+    public boolean isNotificationProcessingOff();
+
+}
diff --git a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueDispatcher.java b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueDispatcher.java
index 1535f87..a4170bd 100644
--- a/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueDispatcher.java
+++ b/util/src/main/java/com/ning/billing/util/notificationq/NotificationQueueDispatcher.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2010-2011 Ning, Inc.
+ * Copyright 2010-2012 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
@@ -65,7 +65,7 @@ public class NotificationQueueDispatcher extends PersistentQueueBase {
     private AtomicBoolean isStarted;
 
     // Package visibility on purpose
-    NotificationQueueDispatcher(final Clock clock, final NotificationConfig config, final IDBI dbi, final InternalCallContextFactory internalCallContextFactory) {
+    NotificationQueueDispatcher(final Clock clock, final NotificationQueueConfig config, final IDBI dbi, final InternalCallContextFactory internalCallContextFactory) {
         super("NotificationQ", Executors.newFixedThreadPool(1, new ThreadFactory() {
             @Override
             public Thread newThread(final Runnable r) {
@@ -83,7 +83,7 @@ public class NotificationQueueDispatcher extends PersistentQueueBase {
 
         this.clock = clock;
         this.config = config;
-        this.dao = dbi.onDemand(NotificationSqlDao.class);
+        this.dao = (dbi != null) ? dbi.onDemand(NotificationSqlDao.class) : null;
         this.internalCallContextFactory = internalCallContextFactory;
         this.hostname = Hostname.get();
         this.nbProcessedEvents = new AtomicLong();
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 f5f493d..f62d2be 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
@@ -59,12 +59,11 @@ public interface NotificationQueueService extends QueueLifecycle {
      * @param svcName   the name of the service using that queue
      * @param queueName a name for that queue (unique per service)
      * @param handler   the handler required for notifying the caller of state change
-     * @param config    the notification queue configuration
      * @return a new NotificationQueue
      * @throws com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueAlreadyExists
      *          is the queue associated with that service and name already exits
      */
-    public NotificationQueue createNotificationQueue(final String svcName, final String queueName, final NotificationQueueHandler handler, final NotificationConfig config)
+    public NotificationQueue createNotificationQueue(final String svcName, final String queueName, final NotificationQueueHandler handler)
             throws NotificationQueueAlreadyExists;
 
     /**
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 4ad413c..99dd74f 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
@@ -17,38 +17,29 @@
 package com.ning.billing.util.notificationq;
 
 import java.util.ArrayList;
-import java.util.LinkedList;
 import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
 
 import org.skife.jdbi.v2.IDBI;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 import com.ning.billing.util.callcontext.InternalCallContextFactory;
-import com.ning.billing.util.config.NotificationConfig;
 import com.ning.billing.util.clock.Clock;
-import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
 
-import com.google.common.base.Joiner;
 import com.google.inject.Inject;
 
 public abstract class NotificationQueueServiceBase extends NotificationQueueDispatcher implements NotificationQueueService {
 
 
     @Inject
-    public NotificationQueueServiceBase(final Clock clock, final NotificationConfig config, final IDBI dbi,
+    public NotificationQueueServiceBase(final Clock clock, final NotificationQueueConfig config, final IDBI dbi,
                                         final InternalCallContextFactory internalCallContextFactory) {
-        super(clock, config, dbi,  internalCallContextFactory);
+        super(clock, config, dbi, internalCallContextFactory);
     }
 
     @Override
     public NotificationQueue createNotificationQueue(final String svcName,
                                                      final String queueName,
-                                                     final NotificationQueueHandler handler,
-                                                     final NotificationConfig config) throws NotificationQueueAlreadyExists {
-        if (svcName == null || queueName == null || handler == null || config == null) {
+                                                     final NotificationQueueHandler handler) throws NotificationQueueAlreadyExists {
+        if (svcName == null || queueName == null || handler == null) {
             throw new RuntimeException("Need to specify all parameters");
         }
 
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 3382bb1..d90ab6b 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
@@ -47,16 +47,18 @@ public class MockNotificationQueue implements NotificationQueue {
     private final String svcName;
     private final String queueName;
     private final NotificationQueueHandler handler;
+    private final MockNotificationQueueService queueService;
 
     private volatile boolean isStarted;
 
-    public MockNotificationQueue(final Clock clock, final String svcName, final String queueName, final NotificationQueueHandler handler) {
+    public MockNotificationQueue(final Clock clock, final String svcName, final String queueName, final NotificationQueueHandler handler, final MockNotificationQueueService mockNotificationQueueService) {
 
         this.svcName = svcName;
         this.queueName = queueName;
         this.handler = handler;
         this.clock = clock;
         this.hostname = Hostname.get();
+        this.queueService = mockNotificationQueueService;
 
         notifications = new TreeSet<Notification>(new Comparator<Notification>() {
             @Override
@@ -154,11 +156,13 @@ public class MockNotificationQueue implements NotificationQueue {
     @Override
     public void startQueue() {
         isStarted = true;
+        queueService.startQueue();
     }
 
     @Override
     public void stopQueue() {
         isStarted = false;
+        queueService.stopQueue();
     }
 
     @Override
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueueService.java b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueueService.java
index 45acc5b..feeea9b 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueueService.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/MockNotificationQueueService.java
@@ -30,7 +30,7 @@ import com.google.inject.Inject;
 public class MockNotificationQueueService extends NotificationQueueServiceBase {
 
     @Inject
-    public MockNotificationQueueService(final Clock clock, final NotificationConfig config) {
+    public MockNotificationQueueService(final Clock clock, final NotificationQueueConfig config) {
         super(clock, config, null, null);
     }
 
@@ -38,7 +38,7 @@ public class MockNotificationQueueService extends NotificationQueueServiceBase {
     @Override
     protected NotificationQueue createNotificationQueueInternal(final String svcName, final String queueName,
                                                                 final NotificationQueueHandler handler) {
-        return new MockNotificationQueue(clock, svcName, queueName, handler);
+        return new MockNotificationQueue(clock, svcName, queueName, handler, this);
     }
 
 
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 b54cac3..548c6e5 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
@@ -85,11 +85,6 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
     @Inject
     NotificationQueueService queueService;
 
-    @Inject
-    NotificationConfig config;
-
-    private DummySqlTest dao;
-
     private int eventsReceived;
 
     private static final class TestNotificationKey implements NotificationKey, Comparable<TestNotificationKey> {
@@ -123,7 +118,6 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
     public void setup() throws Exception {
         final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
         helper.initDb(testDdl);
-        dao = dbi.onDemand(DummySqlTest.class);
         entitySqlDaoTransactionalJdbiWrapper = new EntitySqlDaoTransactionalJdbiWrapper(dbi);
     }
 
@@ -167,9 +161,7 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
                                                                                          expectedNotifications.notify();
                                                                                      }
                                                                                  }
-                                                                             },
-                                                                             config);
-
+                                                                             });
 
         queue.startQueue();
 
@@ -226,8 +218,7 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
                                                                                          expectedNotifications.notify();
                                                                                      }
                                                                                  }
-                                                                             },
-                                                                             config);
+                                                                             });
 
         queue.startQueue();
 
@@ -307,29 +298,24 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
         final Map<NotificationKey, Boolean> expectedNotificationsBarney = new TreeMap<NotificationKey, Boolean>();
 
 
-        final NotificationQueueService notificationQueueService = new DefaultNotificationQueueService(dbi, clock, config, new InternalCallContextFactory(dbi, clock));
-
 
-        final NotificationQueue queueFred = notificationQueueService.createNotificationQueue("UtilTest", "Fred", new NotificationQueueHandler() {
+        final NotificationQueue queueFred = queueService.createNotificationQueue("UtilTest", "Fred", new NotificationQueueHandler() {
             @Override
             public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime, final Long accountRecordId, final Long tenantRecordId) {
                 log.info("Fred received key: " + notificationKey);
                 expectedNotificationsFred.put(notificationKey, Boolean.TRUE);
                 eventsReceived++;
             }
-        },
-                                                                                             config);
+        });
 
-        final NotificationQueue queueBarney = notificationQueueService.createNotificationQueue("UtilTest", "Barney", new NotificationQueueHandler() {
+        final NotificationQueue queueBarney = queueService.createNotificationQueue("UtilTest", "Barney", new NotificationQueueHandler() {
             @Override
             public void handleReadyNotification(final NotificationKey notificationKey, final DateTime eventDateTime, final Long accountRecordId, final Long tenantRecordId) {
                 log.info("Barney received key: " + notificationKey);
                 expectedNotificationsBarney.put(notificationKey, Boolean.TRUE);
                 eventsReceived++;
             }
-        },
-                                                                                               config);
-
+        });
         queueFred.startQueue();
         //		We don't start Barney so it can never pick up notifications
 
@@ -399,10 +385,7 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
                                                                                          eventsReceived++;
                                                                                      }
                                                                                  }
-                                                                             },
-                                                                             config);
-
-
+                                                                             });
         queue.startQueue();
 
         final DateTime start = clock.getUTCNow().plusHours(1);
@@ -441,8 +424,8 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
     }
 
 
-    static NotificationConfig getNotificationConfig(final boolean off, final long sleepTime) {
-        return new NotificationConfig() {
+    static NotificationQueueConfig getNotificationConfig(final boolean off, final long sleepTime) {
+        return new NotificationQueueConfig() {
             @Override
             public boolean isNotificationProcessingOff() {
                 return off;
@@ -468,7 +451,7 @@ public class TestNotificationQueue extends UtilTestSuiteWithEmbeddedDB {
             final IDBI otherDbi = helper.getDBI();
             bind(IDBI.class).annotatedWith(Names.named("global-lock")).toInstance(otherDbi);
             bind(NotificationQueueService.class).to(DefaultNotificationQueueService.class).asEagerSingleton();
-            bind(NotificationConfig.class).toInstance(getNotificationConfig(false, 100));
+            bind(NotificationQueueConfig.class).toInstance(getNotificationConfig(false, 100));
         }
     }
 }