killbill-aplcache

Details

invoice/pom.xml 6(+5 -1)

diff --git a/invoice/pom.xml b/invoice/pom.xml
index 63a2fba..2fb5e33 100644
--- a/invoice/pom.xml
+++ b/invoice/pom.xml
@@ -98,7 +98,11 @@
             <groupId>com.google.guava</groupId>
             <artifactId>guava</artifactId>
         </dependency>
-        
+        <dependency>
+            <groupId>com.jayway.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
     </build>
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 3cf1386..6036652 100644
--- a/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
+++ b/invoice/src/test/java/com/ning/billing/invoice/notification/TestNextBillingDateNotifier.java
@@ -16,9 +16,13 @@
 
 package com.ning.billing.invoice.notification;
 
+import static com.jayway.awaitility.Awaitility.await;
+import static java.util.concurrent.TimeUnit.MINUTES;
+
 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.UUID;
+import java.util.concurrent.Callable;
 
 import org.apache.commons.io.IOUtils;
 import org.joda.time.DateTime;
@@ -41,7 +45,6 @@ import com.ning.billing.lifecycle.KillbillService.ServiceException;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.eventbus.Bus;
-import com.ning.billing.util.eventbus.Bus.EventBusException;
 import com.ning.billing.util.eventbus.MemoryEventBus;
 import com.ning.billing.util.notificationq.DefaultNotificationQueueService;
 import com.ning.billing.util.notificationq.DummySqlTest;
@@ -62,7 +65,6 @@ public class TestNextBillingDateNotifier {
         final Injector g = Guice.createInjector(Stage.PRODUCTION,  new AbstractModule() {
 			protected void configure() {
 				 bind(Clock.class).to(ClockMock.class).asEagerSingleton();
-				 bind(NextBillingDateNotifier.class).to(DefaultNextBillingDateNotifier.class).asEagerSingleton();
 				 bind(Bus.class).to(MemoryEventBus.class).asEagerSingleton();
 				 bind(NotificationQueueService.class).to(DefaultNotificationQueueService.class).asEagerSingleton();
 				 final InvoiceConfig config = new ConfigurationObjectFactory(System.getProperties()).build(InvoiceConfig.class);
@@ -75,12 +77,12 @@ public class TestNextBillingDateNotifier {
 			}  	
         });
 
-        notifier = (DefaultNextBillingDateNotifier) g.getInstance(NextBillingDateNotifier.class);
         clock = g.getInstance(Clock.class);
         DBI dbi = g.getInstance(DBI.class);
         dao = dbi.onDemand(DummySqlTest.class);
         eventBus = g.getInstance(Bus.class);
         helper = g.getInstance(MysqlTestingHelper.class);
+        notifier = new DefaultNextBillingDateNotifier(g.getInstance(NotificationQueueService.class), eventBus, g.getInstance(InvoiceConfig.class));
         startMysql();
 	}
 	
@@ -107,12 +109,12 @@ public class TestNextBillingDateNotifier {
 	}
 	
 	@Test(enabled=true, groups="slow")
-	public void test() throws EventBusException, InterruptedException {
+	public void test() throws Exception {
 		final UUID subscriptionId = new UUID(0L,1L);
 		final DateTime now = new DateTime();
 		final DateTime readyTime = now.plusMillis(2000);
 
-		NextBillingEventListener listener = new NextBillingEventListener();
+		final NextBillingEventListener listener = new NextBillingEventListener();
 		eventBus.start();
 		notifier.initialize();
 		notifier.start();
@@ -130,8 +132,15 @@ public class TestNextBillingDateNotifier {
 
 		// Move time in the future after the notification effectiveDate
 		((ClockMock) clock).setDeltaFromReality(3000);
-		Thread.sleep(1000); //Ugly - waiting for thread to be scheduled. hmmm.
-		
+
+
+	    await().atMost(1, MINUTES).until(new Callable<Boolean>() {
+	            @Override
+	            public Boolean call() throws Exception {
+	                return listener.getEventCount() == 1;
+	            }
+	        });
+
 		Assert.assertEquals(listener.getEventCount(), 1);
 	}
 }

pom.xml 6(+6 -0)

diff --git a/pom.xml b/pom.xml
index 8c8fbb3..28f48db 100644
--- a/pom.xml
+++ b/pom.xml
@@ -234,6 +234,12 @@
                 <version>6.0</version>
                 <scope>test</scope>
             </dependency>
+             <dependency>
+                <groupId>com.jayway.awaitility</groupId>
+                <artifactId>awaitility</artifactId>
+                <version>1.3.3</version>
+                <scope>test</scope>
+            </dependency>
         </dependencies>
     </dependencyManagement>
     <build>
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 8058561..207a78c 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
@@ -150,18 +150,7 @@ public class TestNotificationQueue {
 		((ClockMock) clock).setDeltaFromReality(3000);
 
 		// Notification should have kicked but give it at least a sec' for thread scheduling
-		int nbTry = 1;
-		boolean success = false;
-		do {
-			synchronized(expectedNotifications) {
-				if (expectedNotifications.get(notificationKey.toString())) {
-					success = true;
-					break;
-				}
-				expectedNotifications.wait(1000);
-			}
-		} while (nbTry-- > 0);
-		assertEquals(success, true);
+		  
 	}
 
 	@Test