killbill-aplcache

Details

util/pom.xml 5(+5 -0)

diff --git a/util/pom.xml b/util/pom.xml
index da7e452..018647e 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -78,6 +78,11 @@
             <artifactId>stringtemplate</artifactId>
             <scope>runtime</scope>
         </dependency>
+        <dependency>
+            <groupId>com.mysql</groupId>
+            <artifactId>management-dbfiles</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     <build>
         <plugins>
diff --git a/util/src/test/java/com/ning/billing/util/eventbus/TestEventBus.java b/util/src/test/java/com/ning/billing/util/eventbus/TestEventBus.java
index 47691be..4b0f4a2 100644
--- a/util/src/test/java/com/ning/billing/util/eventbus/TestEventBus.java
+++ b/util/src/test/java/com/ning/billing/util/eventbus/TestEventBus.java
@@ -71,7 +71,7 @@ public class TestEventBus {
         @Subscribe
         public synchronized void processEvent(MyEvent event) {
             gotEvents++;
-            log.info("Got event {} {}", event.name, event.value);
+            //log.debug("Got event {} {}", event.name, event.value);
         }
 
         public synchronized boolean waitForCompletion(long timeoutMs) {
diff --git a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
index bfd29ef..89dfd76 100644
--- a/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
+++ b/util/src/test/java/com/ning/billing/util/notificationq/dao/TestNotificationSqlDao.java
@@ -20,10 +20,13 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 import static org.testng.Assert.assertNull;
 
+import java.io.IOException;
+import java.sql.SQLException;
 import java.util.List;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.commons.io.IOUtils;
 import org.joda.time.DateTime;
 import org.joda.time.DateTimeZone;
 import org.skife.config.ConfigurationObjectFactory;
@@ -31,7 +34,10 @@ import org.skife.jdbi.v2.DBI;
 import org.skife.jdbi.v2.Handle;
 import org.skife.jdbi.v2.tweak.HandleCallback;
 import org.testng.Assert;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.AfterSuite;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
@@ -40,6 +46,7 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
 import com.ning.billing.dbi.DBIProvider;
 import com.ning.billing.dbi.DbiConfig;
+import com.ning.billing.dbi.MysqlTestingHelper;
 import com.ning.billing.util.notificationq.DefaultNotification;
 import com.ning.billing.util.notificationq.Notification;
 import com.ning.billing.util.notificationq.NotificationLifecycle.NotificationLifecycleState;
@@ -53,11 +60,33 @@ public class TestNotificationSqlDao {
     @Inject
     private DBI dbi;
 
+    @Inject
+    MysqlTestingHelper helper;
+
     private NotificationSqlDao dao;
 
-    @BeforeClass(alwaysRun = true)
-    public void setup() {
-       dao = dbi.onDemand(NotificationSqlDao.class);
+    private void startMysql() throws IOException, ClassNotFoundException, SQLException {
+
+
+        final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
+        helper.startMysql();
+        helper.initDb(ddl);
+    }
+
+    @BeforeSuite(alwaysRun = true)
+    public void setup()  {
+        try {
+            startMysql();
+            dao = dbi.onDemand(NotificationSqlDao.class);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    @AfterSuite(alwaysRun = true)
+    public void stopMysql()
+    {
+        helper.stopMysql();
     }
 
 
@@ -167,9 +196,17 @@ public class TestNotificationSqlDao {
     public static class TestNotificationSqlDaoModule extends AbstractModule {
         @Override
         protected void configure() {
+
+            final MysqlTestingHelper helper = new MysqlTestingHelper();
+            bind(MysqlTestingHelper.class).toInstance(helper);
+            DBI dbi = helper.getDBI();
+            bind(DBI.class).toInstance(dbi);
+
+            /*
             bind(DBI.class).toProvider(DBIProvider.class).asEagerSingleton();
             final DbiConfig config = new ConfigurationObjectFactory(System.getProperties()).build(DbiConfig.class);
             bind(DbiConfig.class).toInstance(config);
+            */
         }
     }
 }
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 5703da1..7129351 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
@@ -19,11 +19,14 @@ package com.ning.billing.util.notificationq;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
+import java.io.IOException;
+import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
 
+import org.apache.commons.io.IOUtils;
 import org.joda.time.DateTime;
 import org.skife.config.ConfigurationObjectFactory;
 import org.skife.jdbi.v2.DBI;
@@ -34,8 +37,10 @@ import org.skife.jdbi.v2.tweak.HandleCallback;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.testng.annotations.AfterSuite;
 import org.testng.annotations.AfterTest;
 import org.testng.annotations.BeforeClass;
+import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.Guice;
 import org.testng.annotations.Test;
@@ -46,9 +51,11 @@ import com.google.inject.AbstractModule;
 import com.google.inject.Inject;
 import com.ning.billing.dbi.DBIProvider;
 import com.ning.billing.dbi.DbiConfig;
+import com.ning.billing.dbi.MysqlTestingHelper;
 import com.ning.billing.util.clock.Clock;
 import com.ning.billing.util.clock.ClockMock;
 import com.ning.billing.util.notificationq.NotificationQueueService.NotificationQueueHandler;
+import com.ning.billing.util.notificationq.dao.NotificationSqlDao;
 
 @Guice(modules = TestNotificationQueue.TestNotificationQueueModule.class)
 public class TestNotificationQueue {
@@ -59,15 +66,26 @@ public class TestNotificationQueue {
     private DBI dbi;
 
     @Inject
+    MysqlTestingHelper helper;
+
+    @Inject
     private Clock clock;
 
     private DummySqlTest dao;
 
    // private NotificationQueue queue;
 
+    private void startMysql() throws IOException, ClassNotFoundException, SQLException {
+        final String ddl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl.sql"));
+        final String testDdl = IOUtils.toString(NotificationSqlDao.class.getResourceAsStream("/com/ning/billing/util/ddl_test.sql"));
+        helper.startMysql();
+        helper.initDb(ddl);
+        helper.initDb(testDdl);
+    }
 
-    @BeforeClass(alwaysRun = true)
-    public void setup() {
+    @BeforeSuite(alwaysRun = true)
+    public void setup() throws Exception {
+        startMysql();
         dao = dbi.onDemand(DummySqlTest.class);
     }
 
@@ -87,10 +105,7 @@ public class TestNotificationQueue {
         ((ClockMock) clock).resetDeltaFromReality();
     }
 
-    @AfterTest
-    public void afterTest() {
 
-    }
 
     /**
      * Verify that we can call start/stop on a disabled queue and that both start/stop callbacks are called
@@ -394,10 +409,18 @@ public class TestNotificationQueue {
     public static class TestNotificationQueueModule extends AbstractModule {
         @Override
         protected void configure() {
+
+            bind(Clock.class).to(ClockMock.class);
+
+            final MysqlTestingHelper helper = new MysqlTestingHelper();
+            bind(MysqlTestingHelper.class).toInstance(helper);
+            DBI dbi = helper.getDBI();
+            bind(DBI.class).toInstance(dbi);
+            /*
             bind(DBI.class).toProvider(DBIProvider.class).asEagerSingleton();
             final DbiConfig config = new ConfigurationObjectFactory(System.getProperties()).build(DbiConfig.class);
             bind(DbiConfig.class).toInstance(config);
-            bind(Clock.class).to(ClockMock.class);
+            */
         }
     }