killbill-memoizeit
Changes
account/pom.xml 15(+0 -15)
beatrix/pom.xml 16(+0 -16)
beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestJrubyNotificationPlugin.java 5(+1 -4)
beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java 4(+1 -3)
currency/pom.xml 15(+0 -15)
entitlement/pom.xml 15(+0 -15)
entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestListenerStatus.java 59(+0 -59)
entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java 17(+4 -13)
entitlement/src/test/java/com/ning/billing/entitlement/glue/TestEntitlementModuleWithEmbeddedDB.java 3(+0 -3)
invoice/pom.xml 15(+0 -15)
junction/pom.xml 15(+0 -15)
junction/src/test/java/com/ning/billing/junction/glue/TestJunctionModuleWithEmbeddedDB.java 3(+0 -3)
osgi-bundles/bundles/meter/pom.xml 15(+0 -15)
overdue/pom.xml 15(+0 -15)
payment/pom.xml 16(+0 -16)
pom.xml 2(+1 -1)
server/pom.xml 11(+0 -11)
subscription/pom.xml 15(+0 -15)
subscription/src/main/java/com/ning/billing/subscription/engine/dao/DefaultSubscriptionDao.java 9(+7 -2)
subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg 18(+4 -14)
subscription/src/test/java/com/ning/billing/subscription/api/user/TestSubscriptionHelper.java 11(+2 -9)
subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiChangePlan.java 36(+7 -29)
subscription/src/test/java/com/ning/billing/subscription/DefaultSubscriptionTestInitializer.java 7(+2 -5)
subscription/src/test/java/com/ning/billing/subscription/glue/TestDefaultSubscriptionModule.java 3(+0 -3)
subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestListenerStatus.java 59(+0 -59)
subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteWithEmbeddedDB.java 10(+2 -8)
tenant/pom.xml 15(+0 -15)
usage/pom.xml 15(+0 -15)
util/pom.xml 27(+11 -16)
Details
account/pom.xml 15(+0 -15)
diff --git a/account/pom.xml b/account/pom.xml
index 7759bc4..6173621 100644
--- a/account/pom.xml
+++ b/account/pom.xml
@@ -49,11 +49,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.ning.billing</groupId>
<artifactId>killbill-api</artifactId>
</dependency>
@@ -100,16 +95,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/account/src/main/java/com/ning/billing/account/dao/AccountSqlDao.java b/account/src/main/java/com/ning/billing/account/dao/AccountSqlDao.java
index dd1d652..8dcaa59 100644
--- a/account/src/main/java/com/ning/billing/account/dao/AccountSqlDao.java
+++ b/account/src/main/java/com/ning/billing/account/dao/AccountSqlDao.java
@@ -16,14 +16,12 @@
package com.ning.billing.account.dao;
-import java.util.Iterator;
import java.util.UUID;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.account.api.Account;
import com.ning.billing.callcontext.InternalCallContext;
@@ -41,16 +39,6 @@ public interface AccountSqlDao extends EntitySqlDao<AccountModelDao, Account> {
@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
- public Iterator<AccountModelDao> searchAccounts(@Bind("searchKey") final String searchKey,
- @Bind("likeSearchKey") final String likeSearchKey,
- @Bind("offset") final Long offset,
- @Bind("rowCount") final Long rowCount,
- @BindBean final InternalTenantContext context);
-
- @SqlQuery
public UUID getIdFromKey(@Bind("externalKey") final String key,
@BindBean final InternalTenantContext context);
diff --git a/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java b/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
index ea710c3..f0dbd25 100644
--- a/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
+++ b/account/src/main/java/com/ning/billing/account/dao/DefaultAccountDao.java
@@ -111,8 +111,13 @@ public class DefaultAccountDao extends EntityDaoBase<AccountModelDao, Account, A
return paginationHelper.getPagination(AccountSqlDao.class,
new PaginationIteratorBuilder<AccountModelDao, Account, AccountSqlDao>() {
@Override
- public Iterator<AccountModelDao> build(final AccountSqlDao accountSqlDao, final Long limit) {
- return accountSqlDao.searchAccounts(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
+ public Long getCount(final AccountSqlDao accountSqlDao, final InternalTenantContext context) {
+ return accountSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context);
+ }
+
+ @Override
+ public Iterator<AccountModelDao> build(final AccountSqlDao accountSqlDao, final Long limit, final InternalTenantContext context) {
+ return accountSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
}
},
offset,
diff --git a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
index c1e5255..0f5bb37 100644
--- a/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
+++ b/account/src/main/resources/com/ning/billing/account/dao/AccountSqlDao.sql.stg
@@ -86,22 +86,12 @@ getAccountByKey() ::= <<
where external_key = :externalKey <AND_CHECK_TENANT()>;
>>
-searchAccounts() ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields("t.")>
-from <tableName()> t
-where 1 = 1
-and (
- <idField("t.")> = :searchKey
- or t.name like :likeSearchKey
- or t.email like :likeSearchKey
- or t.external_key like :likeSearchKey
- or t.company_name like :likeSearchKey
-)
-<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
-limit :offset, :rowCount
-;
+searchQuery(prefix) ::= <<
+ <idField(prefix)> = :searchKey
+ or <prefix>name like :likeSearchKey
+ or <prefix>email like :likeSearchKey
+ or <prefix>external_key like :likeSearchKey
+ or <prefix>company_name like :likeSearchKey
>>
getIdFromKey() ::= <<
diff --git a/account/src/main/resources/com/ning/billing/account/ddl.sql b/account/src/main/resources/com/ning/billing/account/ddl.sql
index a22edb1..caf11d2 100644
--- a/account/src/main/resources/com/ning/billing/account/ddl.sql
+++ b/account/src/main/resources/com/ning/billing/account/ddl.sql
@@ -29,7 +29,7 @@ CREATE TABLE accounts (
updated_by varchar(50) DEFAULT NULL,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX accounts_id ON accounts(id);
CREATE UNIQUE INDEX accounts_external_key ON accounts(external_key);
CREATE INDEX accounts_tenant_record_id ON accounts(tenant_record_id);
@@ -65,7 +65,7 @@ CREATE TABLE account_history (
updated_date datetime NOT NULL,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX account_history_target_record_id ON account_history(target_record_id);
CREATE INDEX account_history_tenant_record_id ON account_history(tenant_record_id);
@@ -83,7 +83,7 @@ CREATE TABLE account_emails (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX account_email_id ON account_emails(id);
CREATE INDEX account_email_account_id_email ON account_emails(account_id, email);
CREATE INDEX account_emails_tenant_account_record_id ON account_emails(tenant_record_id, account_record_id);
@@ -104,6 +104,6 @@ CREATE TABLE account_email_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX account_email_target_record_id ON account_email_history(target_record_id);
CREATE INDEX account_email_history_tenant_account_record_id ON account_email_history(tenant_record_id, account_record_id);
beatrix/pom.xml 16(+0 -16)
diff --git a/beatrix/pom.xml b/beatrix/pom.xml
index 44b3a14..78d291e 100644
--- a/beatrix/pom.xml
+++ b/beatrix/pom.xml
@@ -36,11 +36,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -186,17 +181,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.5</version>
diff --git a/beatrix/src/main/resources/com/ning/billing/beatrix/ddl.sql b/beatrix/src/main/resources/com/ning/billing/beatrix/ddl.sql
index 61c0e1c..2783fc6 100644
--- a/beatrix/src/main/resources/com/ning/billing/beatrix/ddl.sql
+++ b/beatrix/src/main/resources/com/ning/billing/beatrix/ddl.sql
@@ -15,7 +15,7 @@ CREATE TABLE bus_ext_events (
search_key1 int(11) unsigned default null,
search_key2 int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX `idx_bus_ext_where` ON bus_ext_events (`processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX bus_ext_events_tenant_account_record_id ON bus_ext_events(search_key2, search_key1);
@@ -34,4 +34,4 @@ CREATE TABLE bus_ext_events_history (
search_key1 int(11) unsigned default null,
search_key2 int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
index 3dca515..e24b566 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/BeatrixIntegrationModule.java
@@ -22,9 +22,11 @@ import java.util.Set;
import org.skife.config.ConfigSource;
+import com.ning.billing.DBTestingHelper;
import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
import com.ning.billing.account.api.AccountService;
import com.ning.billing.account.glue.DefaultAccountModule;
+import com.ning.billing.api.TestApiListener;
import com.ning.billing.beatrix.DefaultBeatrixService;
import com.ning.billing.beatrix.glue.BeatrixModule;
import com.ning.billing.beatrix.integration.overdue.IntegrationTestOverdueModule;
@@ -38,6 +40,7 @@ import com.ning.billing.beatrix.util.RefundChecker;
import com.ning.billing.beatrix.util.SubscriptionChecker;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.catalog.glue.CatalogModule;
+import com.ning.billing.commons.embeddeddb.EmbeddedDB;
import com.ning.billing.currency.glue.CurrencyModule;
import com.ning.billing.entitlement.EntitlementService;
import com.ning.billing.entitlement.glue.DefaultEntitlementModule;
@@ -47,6 +50,7 @@ import com.ning.billing.invoice.generator.InvoiceGenerator;
import com.ning.billing.invoice.glue.DefaultInvoiceModule;
import com.ning.billing.junction.glue.DefaultJunctionModule;
import com.ning.billing.lifecycle.KillbillService;
+import com.ning.billing.mock.glue.MockGlobalLockerModule;
import com.ning.billing.osgi.DefaultOSGIService;
import com.ning.billing.osgi.glue.DefaultOSGIModule;
import com.ning.billing.overdue.OverdueService;
@@ -96,12 +100,15 @@ public class BeatrixIntegrationModule extends AbstractModule {
@Override
protected void configure() {
-
loadSystemPropertiesFromClasspath("/beatrix.properties");
install(new GuicyKillbillTestWithEmbeddedDBModule());
- install(new GlobalLockerModule());
+ if (EmbeddedDB.DBEngine.MYSQL.equals(DBTestingHelper.get().getDBEngine())) {
+ install(new GlobalLockerModule());
+ } else {
+ install(new MockGlobalLockerModule());
+ }
install(new CacheModule(configSource));
install(new EmailModule(configSource));
install(new CallContextModule());
@@ -135,6 +142,8 @@ public class BeatrixIntegrationModule extends AbstractModule {
bind(PaymentChecker.class).asEagerSingleton();
bind(RefundChecker.class).asEagerSingleton();
bind(AuditChecker.class).asEagerSingleton();
+
+ bind(TestApiListener.class).asEagerSingleton();
}
private static final class DefaultInvoiceModuleWithSwitchRepairLogic extends DefaultInvoiceModule {
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestJrubyNotificationPlugin.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestJrubyNotificationPlugin.java
index 1f12d13..fa22e11 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestJrubyNotificationPlugin.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestJrubyNotificationPlugin.java
@@ -27,8 +27,6 @@ import com.ning.billing.api.TestApiListener.NextEvent;
import com.ning.billing.beatrix.osgi.SetupBundleWithAssertion;
import com.ning.billing.util.tag.Tag;
-import static org.testng.Assert.assertTrue;
-
public class TestJrubyNotificationPlugin extends TestOSGIBase {
private final String BUNDLE_TEST_RESOURCE_PREFIX = "killbill-notification-test";
@@ -55,11 +53,10 @@ public class TestJrubyNotificationPlugin extends TestOSGIBase {
// We wait for all that to occur and declare victory if we see the TagDefinition/Tag creation.
busHandler.pushExpectedEvents(NextEvent.TAG_DEFINITION, NextEvent.TAG);
final Account account = createAccountWithNonOsgiPaymentMethod(getAccountData(4));
- assertTrue(busHandler.isCompleted(2 * DELAY));
+ assertListenerStatus();
final List<Tag> tags = tagUserApi.getTagsForAccount(account.getId(), false, callContext);
Assert.assertEquals(tags.size(), 1);
//final Tag tag = tags.get(0);
}
-
}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIBase.java
index eca30ee..0b2f418 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/osgi/TestOSGIBase.java
@@ -19,5 +19,4 @@ package com.ning.billing.beatrix.integration.osgi;
import com.ning.billing.beatrix.integration.TestIntegrationBase;
public class TestOSGIBase extends TestIntegrationBase {
-
}
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
index b7250c1..4228be5 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/overdue/TestOverdueWithSubscriptionCancellation.java
@@ -128,7 +128,7 @@ public class TestOverdueWithSubscriptionCancellation extends TestOverdueBase {
final DefaultEntitlement baseEntitlement3 = createBaseEntitlementAndCheckForCompletion(account.getId(), "externalKey3", productName, ProductCategory.BASE, term, NextEvent.CREATE, NextEvent.INVOICE);
final SubscriptionBundle bundle3 = subscriptionApi.getSubscriptionBundle(baseEntitlement.getBundleId(), callContext);
- // Cancel addOn1 one day after
+ // Cancel bundle 2 one day after
clock.addDays(1);
cancelEntitlementAndCheckForCompletion(baseEntitlement2, clock.getUTCNow(), NextEvent.BLOCK, NextEvent.CANCEL);
@@ -137,11 +137,9 @@ public class TestOverdueWithSubscriptionCancellation extends TestOverdueBase {
invoiceChecker.checkChargedThroughDate(baseEntitlement.getId(), new LocalDate(2012, 6, 30), callContext);
-
// Should still be in clear state
checkODState(DefaultBlockingState.CLEAR_STATE_NAME);
-
// DAY 36 -- RIGHT AFTER OD1 (two block events, for the cancellation and the OD1 state)
// One BLOCK event is for the overdue state transition
// The 2 other BLOCK are for the entitlement blocking states for both base plan and baseEntitlement3
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 dcb5bc2..b2e0fc2 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
@@ -501,7 +501,6 @@ public class TestIntegration extends TestIntegrationBase {
//
// VERIFY CTD HAS BEEN SET
//
- busHandler.reset();
DefaultSubscriptionBase subscription = (DefaultSubscriptionBase) baseEntitlement.getSubscriptionBase();
final DateTime startDate = subscription.getCurrentPhaseStart();
final BigDecimal rate = subscription.getCurrentPhase().getFixedPrice().getPrice(Currency.USD);
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
index 77104d0..2b845da 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestIntegrationBase.java
@@ -44,7 +44,6 @@ import com.ning.billing.account.api.AccountService;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.api.TestApiListener;
import com.ning.billing.api.TestApiListener.NextEvent;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.beatrix.BeatrixTestSuiteWithEmbeddedDB;
import com.ning.billing.beatrix.glue.BeatrixModule;
import com.ning.billing.beatrix.lifecycle.Lifecycle;
@@ -104,15 +103,13 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
-public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implements TestListenerStatus {
+public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB {
protected static final DateTimeZone testTimeZone = DateTimeZone.UTC;
protected static final Logger log = LoggerFactory.getLogger(TestIntegrationBase.class);
protected static long AT_LEAST_ONE_MONTH_MS = 32L * 24L * 3600L * 1000L;
- protected static final long DELAY = 10000; // * 100000;
-
@Inject
protected Lifecycle lifecycle;
@@ -202,36 +199,17 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
@Inject
protected CacheControllerDispatcher controlCacheDispatcher;
+ @Inject
protected TestApiListener busHandler;
- private boolean isListenerFailed;
- private String listenerFailedMsg;
-
- @Override
- public void failed(final String msg) {
- isListenerFailed = true;
- listenerFailedMsg = msg;
- }
-
- @Override
- public void resetTestListenerStatus() {
- isListenerFailed = false;
- listenerFailedMsg = null;
- }
-
protected void assertListenerStatus() {
- assertTrue(busHandler.isCompleted(DELAY));
- if (isListenerFailed) {
- log.error(listenerFailedMsg);
- Assert.fail(listenerFailedMsg);
- }
+ busHandler.assertListenerStatus();
}
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {
final Injector g = Guice.createInjector(Stage.PRODUCTION, new BeatrixIntegrationModule(configSource));
g.injectMembers(this);
- busHandler = new TestApiListener(this, idbi);
SetupBundleWithAssertion setupTest = new SetupBundleWithAssertion("whatever", osgiConfig, "whatever");
setupTest.cleanBundleInstallDir();
@@ -249,7 +227,6 @@ public class TestIntegrationBase extends BeatrixTestSuiteWithEmbeddedDB implemen
controlCacheDispatcher.clearAll();
clock.resetDeltaFromReality();
- resetTestListenerStatus();
busHandler.reset();
// Start services
diff --git a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
index 7e62cb7..36dcc45 100644
--- a/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
+++ b/beatrix/src/test/java/com/ning/billing/beatrix/integration/TestPublicBus.java
@@ -64,7 +64,6 @@ public class TestPublicBus extends TestIntegrationBase {
log.debug("RESET TEST FRAMEWORK");
clock.resetDeltaFromReality();
- resetTestListenerStatus();
busHandler.reset();
// Start services
currency/pom.xml 15(+0 -15)
diff --git a/currency/pom.xml b/currency/pom.xml
index 311d8ef..97af4cc 100644
--- a/currency/pom.xml
+++ b/currency/pom.xml
@@ -48,11 +48,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -119,16 +114,6 @@
<artifactId>killbill-plugin-api-payment</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
entitlement/pom.xml 15(+0 -15)
diff --git a/entitlement/pom.xml b/entitlement/pom.xml
index 62cb5e7..3d3f954 100644
--- a/entitlement/pom.xml
+++ b/entitlement/pom.xml
@@ -45,11 +45,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -127,16 +122,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
index 74b2998..e44195e 100644
--- a/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
+++ b/entitlement/src/main/resources/com/ning/billing/entitlement/ddl.sql
@@ -20,6 +20,6 @@ CREATE TABLE blocking_states (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX blocking_states_id ON blocking_states(blockable_id);
CREATE INDEX blocking_states_tenant_account_record_id ON blocking_states(tenant_record_id, account_record_id);
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
index e0396c1..da2e112 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/EntitlementTestSuiteWithEmbeddedDB.java
@@ -33,7 +33,6 @@ import com.ning.billing.account.api.AccountData;
import com.ning.billing.account.api.AccountInternalApi;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.bus.api.PersistentBus;
import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.Catalog;
@@ -69,9 +68,6 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
protected static final Logger log = LoggerFactory.getLogger(EntitlementTestSuiteWithEmbeddedDB.class);
- // Be generous...
- protected static final Long DELAY = 20000L;
-
@Inject
protected AccountUserApi accountApi;
@Inject
@@ -97,8 +93,6 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
@Inject
protected TestApiListener testListener;
@Inject
- protected TestListenerStatus testListenerStatus;
- @Inject
protected BusService busService;
@Inject
protected SubscriptionBaseService subscriptionBaseService;
@@ -132,7 +126,7 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
super.beforeMethod();
- startTestFamework(testListener, testListenerStatus, clock, busService, subscriptionBaseService, entitlementService);
+ startTestFamework(testListener, clock, busService, subscriptionBaseService, entitlementService);
this.catalog = initCatalog(catalogService);
// Make sure we start with a clean state
@@ -157,14 +151,13 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
private void startTestFamework(final TestApiListener testListener,
- final TestListenerStatus testListenerStatus,
final ClockMock clock,
final BusService busService,
final SubscriptionBaseService subscriptionBaseService,
final EntitlementService entitlementService) throws Exception {
log.debug("STARTING TEST FRAMEWORK");
- resetTestListener(testListener, testListenerStatus);
+ resetTestListener(testListener);
resetClockToStartOfTest(clock);
@@ -188,11 +181,10 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
log.debug("STOPPED TEST FRAMEWORK");
}
- private void resetTestListener(final TestApiListener testListener, final TestListenerStatus testListenerStatus) {
+ private void resetTestListener(final TestApiListener testListener) {
// RESET LIST OF EXPECTED EVENTS
if (testListener != null) {
testListener.reset();
- testListenerStatus.resetTestListenerStatus();
}
}
@@ -250,7 +242,6 @@ public class EntitlementTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWi
}
protected void assertListenerStatus() {
- assertTrue(testListener.isCompleted(DELAY));
- ((EntitlementTestListenerStatus) testListenerStatus).assertListenerStatus();
+ testListener.assertListenerStatus();
}
}
diff --git a/entitlement/src/test/java/com/ning/billing/entitlement/glue/TestEntitlementModuleWithEmbeddedDB.java b/entitlement/src/test/java/com/ning/billing/entitlement/glue/TestEntitlementModuleWithEmbeddedDB.java
index 0b40737..9945069 100644
--- a/entitlement/src/test/java/com/ning/billing/entitlement/glue/TestEntitlementModuleWithEmbeddedDB.java
+++ b/entitlement/src/test/java/com/ning/billing/entitlement/glue/TestEntitlementModuleWithEmbeddedDB.java
@@ -21,9 +21,7 @@ import org.skife.config.ConfigSource;
import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
import com.ning.billing.account.glue.DefaultAccountModule;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.glue.CatalogModule;
-import com.ning.billing.entitlement.EntitlementTestListenerStatus;
import com.ning.billing.subscription.glue.DefaultSubscriptionModule;
import com.ning.billing.util.glue.AuditModule;
import com.ning.billing.util.glue.BusModule;
@@ -52,7 +50,6 @@ public class TestEntitlementModuleWithEmbeddedDB extends TestEntitlementModule {
install(new DefaultSubscriptionModule(configSource));
install(new AuditModule());
- bind(TestListenerStatus.class).to(EntitlementTestListenerStatus.class).asEagerSingleton();
bind(TestApiListener.class).asEagerSingleton();
}
}
invoice/pom.xml 15(+0 -15)
diff --git a/invoice/pom.xml b/invoice/pom.xml
index c841124..b5232a7 100644
--- a/invoice/pom.xml
+++ b/invoice/pom.xml
@@ -46,11 +46,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -118,16 +113,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
index 441eba2..678df99 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/DefaultInvoiceDao.java
@@ -58,6 +58,7 @@ import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
+import com.google.common.collect.Iterators;
import com.google.common.collect.Ordering;
import com.google.inject.Inject;
@@ -252,11 +253,29 @@ public class DefaultInvoiceDao extends EntityDaoBase<InvoiceModelDao, Invoice, I
@Override
public Pagination<InvoiceModelDao> searchInvoices(final String searchKey, final Long offset, final Long limit, final InternalTenantContext context) {
+ Integer invoiceNumberParsed = null;
+ try {
+ invoiceNumberParsed = Integer.parseInt(searchKey);
+ } catch (final NumberFormatException ignored) {
+ }
+
+ final Integer invoiceNumber = invoiceNumberParsed;
return paginationHelper.getPagination(InvoiceSqlDao.class,
new PaginationIteratorBuilder<InvoiceModelDao, Invoice, InvoiceSqlDao>() {
@Override
- public Iterator<InvoiceModelDao> build(final InvoiceSqlDao invoiceSqlDao, final Long limit) {
- return invoiceSqlDao.searchInvoices(searchKey, offset, limit, context);
+ public Long getCount(final InvoiceSqlDao invoiceSqlDao, final InternalTenantContext context) {
+ return invoiceNumber != null ? 1L : invoiceSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context);
+ }
+
+ @Override
+ public Iterator<InvoiceModelDao> build(final InvoiceSqlDao invoiceSqlDao, final Long limit, final InternalTenantContext context) {
+ try {
+ return invoiceNumber != null ?
+ ImmutableList.<InvoiceModelDao>of(getByNumber(invoiceNumber, context)).iterator() :
+ invoiceSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
+ } catch (final InvoiceApiException ignored) {
+ return Iterators.<InvoiceModelDao>emptyIterator();
+ }
}
},
offset,
diff --git a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceSqlDao.java b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceSqlDao.java
index a0824db..aebd7ab 100644
--- a/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceSqlDao.java
+++ b/invoice/src/main/java/com/ning/billing/invoice/dao/InvoiceSqlDao.java
@@ -16,14 +16,12 @@
package com.ning.billing.invoice.dao;
-import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalTenantContext;
import com.ning.billing.invoice.api.Invoice;
@@ -38,15 +36,6 @@ public interface InvoiceSqlDao extends EntitySqlDao<InvoiceModelDao, Invoice> {
@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
- public Iterator<InvoiceModelDao> searchInvoices(@Bind("searchKey") final String searchKey,
- @Bind("offset") final Long offset,
- @Bind("rowCount") final Long rowCount,
- @BindBean final InternalTenantContext context);
-
- @SqlQuery
UUID getInvoiceIdByPaymentId(@Bind("paymentId") final String paymentId,
@BindBean final InternalTenantContext context);
}
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
index 304da69..8daa8b1 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
+++ b/invoice/src/main/resources/com/ning/billing/invoice/dao/InvoiceSqlDao.sql.stg
@@ -36,21 +36,10 @@ getInvoicesBySubscription() ::= <<
;
>>
-searchInvoices() ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields("t.")>
-from <tableName()> t
-where 1 = 1
-and (
- <idField("t.")> = :searchKey
- or <recordIdField("t.")> = :searchKey
- or t.account_id = :searchKey
- or t.currency = :searchKey
-)
-<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
-limit :offset, :rowCount
-;
+searchQuery(prefix) ::= <<
+ <idField(prefix)> = :searchKey
+ or <prefix>account_id = :searchKey
+ or <prefix>currency = :searchKey
>>
getInvoiceIdByPaymentId() ::= <<
diff --git a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
index b8542c1..beb05f1 100644
--- a/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
+++ b/invoice/src/main/resources/com/ning/billing/invoice/ddl.sql
@@ -22,7 +22,7 @@ CREATE TABLE invoice_items (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoice_items_id ON invoice_items(id);
CREATE INDEX invoice_items_subscription_id ON invoice_items(subscription_id ASC);
CREATE INDEX invoice_items_invoice_id ON invoice_items(invoice_id ASC);
@@ -43,7 +43,7 @@ CREATE TABLE invoices (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoices_id ON invoices(id);
CREATE INDEX invoices_account_target ON invoices(account_id ASC, target_date);
CREATE INDEX invoices_tenant_account_record_id ON invoices(tenant_record_id, account_record_id);
@@ -66,7 +66,7 @@ CREATE TABLE invoice_payments (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX invoice_payments_id ON invoice_payments(id);
CREATE INDEX invoice_payments ON invoice_payments(payment_id);
CREATE INDEX invoice_payments_invoice_id ON invoice_payments(invoice_id);
junction/pom.xml 15(+0 -15)
diff --git a/junction/pom.xml b/junction/pom.xml
index a240110..d3b6691 100644
--- a/junction/pom.xml
+++ b/junction/pom.xml
@@ -45,11 +45,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -134,16 +129,6 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
</dependency>
diff --git a/junction/src/test/java/com/ning/billing/junction/glue/TestJunctionModuleWithEmbeddedDB.java b/junction/src/test/java/com/ning/billing/junction/glue/TestJunctionModuleWithEmbeddedDB.java
index 32dff2d..aa477d3 100644
--- a/junction/src/test/java/com/ning/billing/junction/glue/TestJunctionModuleWithEmbeddedDB.java
+++ b/junction/src/test/java/com/ning/billing/junction/glue/TestJunctionModuleWithEmbeddedDB.java
@@ -21,10 +21,8 @@ import org.skife.config.ConfigSource;
import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
import com.ning.billing.account.glue.DefaultAccountModule;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.glue.CatalogModule;
import com.ning.billing.entitlement.glue.DefaultEntitlementModule;
-import com.ning.billing.junction.JunctionTestListenerStatus;
import com.ning.billing.subscription.glue.DefaultSubscriptionModule;
import com.ning.billing.util.glue.BusModule;
import com.ning.billing.util.glue.MetricsModule;
@@ -53,7 +51,6 @@ public class TestJunctionModuleWithEmbeddedDB extends TestJunctionModule {
install(new MetricsModule());
install(new TagStoreModule());
- bind(TestListenerStatus.class).to(JunctionTestListenerStatus.class).asEagerSingleton();
bind(TestApiListener.class).asEagerSingleton();
}
}
diff --git a/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java
index 20750d0..baec0b4 100644
--- a/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java
+++ b/junction/src/test/java/com/ning/billing/junction/JunctionTestSuiteWithEmbeddedDB.java
@@ -32,7 +32,6 @@ import com.ning.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.bus.api.PersistentBus;
import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.Catalog;
@@ -62,9 +61,6 @@ public abstract class JunctionTestSuiteWithEmbeddedDB extends GuicyKillbillTestS
protected static final Logger log = LoggerFactory.getLogger(JunctionTestSuiteWithEmbeddedDB.class);
- // Be generous...
- protected static final Long DELAY = 20000L;
-
@Inject
protected AccountUserApi accountApi;
@Inject
@@ -82,8 +78,6 @@ public abstract class JunctionTestSuiteWithEmbeddedDB extends GuicyKillbillTestS
@Inject
protected TestApiListener testListener;
@Inject
- protected TestListenerStatus testListenerStatus;
- @Inject
protected BusService busService;
@Inject
protected SubscriptionBaseService subscriptionBaseService;
@@ -136,7 +130,7 @@ public abstract class JunctionTestSuiteWithEmbeddedDB extends GuicyKillbillTestS
private void startTestFamework() throws Exception {
log.debug("STARTING TEST FRAMEWORK");
- resetTestListener(testListener, testListenerStatus);
+ resetTestListener(testListener);
resetClockToStartOfTest(clock);
@@ -156,11 +150,10 @@ public abstract class JunctionTestSuiteWithEmbeddedDB extends GuicyKillbillTestS
log.debug("STOPPED TEST FRAMEWORK");
}
- private void resetTestListener(final TestApiListener testListener, final TestListenerStatus testListenerStatus) {
+ private void resetTestListener(final TestApiListener testListener) {
// RESET LIST OF EXPECTED EVENTS
if (testListener != null) {
testListener.reset();
- testListenerStatus.resetTestListenerStatus();
}
}
@@ -218,7 +211,6 @@ public abstract class JunctionTestSuiteWithEmbeddedDB extends GuicyKillbillTestS
}
protected void assertListenerStatus() {
- assertTrue(testListener.isCompleted(DELAY));
- ((JunctionTestListenerStatus) testListenerStatus).assertListenerStatus();
+ testListener.assertListenerStatus();
}
}
osgi-bundles/bundles/meter/pom.xml 15(+0 -15)
diff --git a/osgi-bundles/bundles/meter/pom.xml b/osgi-bundles/bundles/meter/pom.xml
index 0bc7acc..6c71b00 100644
--- a/osgi-bundles/bundles/meter/pom.xml
+++ b/osgi-bundles/bundles/meter/pom.xml
@@ -57,11 +57,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
</dependency>
@@ -103,16 +98,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
overdue/pom.xml 15(+0 -15)
diff --git a/overdue/pom.xml b/overdue/pom.xml
index 2242c44..7e320c6 100644
--- a/overdue/pom.xml
+++ b/overdue/pom.xml
@@ -41,11 +41,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -114,16 +109,6 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.jdbi</groupId>
<artifactId>jdbi</artifactId>
</dependency>
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 00e18f0..eae6a0f 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
@@ -151,14 +151,16 @@ public class OverdueStateApplicator {
return;
}
- storeNewState(account, nextOverdueState, context);
-
cancelSubscriptionsIfRequired(account, nextOverdueState, context);
sendEmailIfRequired(billingState, account, nextOverdueState, context);
avoid_extra_credit_by_toggling_AUTO_INVOICE_OFF(account, previousOverdueState, nextOverdueState, context);
+ // Make sure to store the new state last here: the entitlement DAO will send a BlockingTransitionInternalEvent
+ // on the bus to which invoice will react. We need the latest state (including AUTO_INVOICE_OFF tag for example)
+ // to be present in the database first.
+ storeNewState(account, nextOverdueState, context);
} catch (OverdueApiException e) {
if (e.getCode() != ErrorCode.OVERDUE_NO_REEVALUATION_INTERVAL.getCode()) {
throw new OverdueException(e);
payment/pom.xml 16(+0 -16)
diff --git a/payment/pom.xml b/payment/pom.xml
index 3bd84aa..76e401b 100644
--- a/payment/pom.xml
+++ b/payment/pom.xml
@@ -47,11 +47,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -125,17 +120,6 @@
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
-
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java b/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
index 0aedc0c..e6c87d1 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/DefaultPaymentDao.java
@@ -170,7 +170,12 @@ public class DefaultPaymentDao implements PaymentDao {
return paginationHelper.getPagination(RefundSqlDao.class,
new PaginationIteratorBuilder<RefundModelDao, Refund, RefundSqlDao>() {
@Override
- public Iterator<RefundModelDao> build(final RefundSqlDao refundSqlDao, final Long limit) {
+ public Long getCount(final RefundSqlDao refundSqlDao, final InternalTenantContext context) {
+ return refundSqlDao.getCountByPluginName(pluginName, context);
+ }
+
+ @Override
+ public Iterator<RefundModelDao> build(final RefundSqlDao refundSqlDao, final Long limit, final InternalTenantContext context) {
return refundSqlDao.getByPluginName(pluginName, offset, limit, context);
}
},
@@ -244,7 +249,12 @@ public class DefaultPaymentDao implements PaymentDao {
return paginationHelper.getPagination(PaymentMethodSqlDao.class,
new PaginationIteratorBuilder<PaymentMethodModelDao, PaymentMethod, PaymentMethodSqlDao>() {
@Override
- public Iterator<PaymentMethodModelDao> build(final PaymentMethodSqlDao paymentMethodSqlDao, final Long limit) {
+ public Long getCount(final PaymentMethodSqlDao paymentMethodSqlDao, final InternalTenantContext context) {
+ return paymentMethodSqlDao.getCountByPluginName(pluginName, context);
+ }
+
+ @Override
+ public Iterator<PaymentMethodModelDao> build(final PaymentMethodSqlDao paymentMethodSqlDao, final Long limit, final InternalTenantContext context) {
return paymentMethodSqlDao.getByPluginName(pluginName, offset, limit, context);
}
},
@@ -309,7 +319,12 @@ public class DefaultPaymentDao implements PaymentDao {
return paginationHelper.getPagination(PaymentSqlDao.class,
new PaginationIteratorBuilder<PaymentModelDao, Payment, PaymentSqlDao>() {
@Override
- public Iterator<PaymentModelDao> build(final PaymentSqlDao paymentSqlDao, final Long limit) {
+ public Long getCount(final PaymentSqlDao paymentSqlDao, final InternalTenantContext context) {
+ return paymentSqlDao.getCountByPluginName(pluginName, context);
+ }
+
+ @Override
+ public Iterator<PaymentModelDao> build(final PaymentSqlDao paymentSqlDao, final Long limit, final InternalTenantContext context) {
return paymentSqlDao.getByPluginName(pluginName, offset, limit, context);
}
},
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/PaymentMethodSqlDao.java b/payment/src/main/java/com/ning/billing/payment/dao/PaymentMethodSqlDao.java
index 3ad3b72..95cc60f 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/PaymentMethodSqlDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/PaymentMethodSqlDao.java
@@ -23,10 +23,10 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
+import com.ning.billing.commons.jdbi.statement.SmartFetchSize;
import com.ning.billing.payment.api.PaymentMethod;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.entity.dao.Audited;
@@ -57,11 +57,13 @@ public interface PaymentMethodSqlDao extends EntitySqlDao<PaymentMethodModelDao,
List<PaymentMethodModelDao> getByAccountIdIncludedDelete(@Bind("accountId") final String accountId, @BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<PaymentMethodModelDao> getByPluginName(@Bind("pluginName") final String pluginName,
@Bind("offset") final Long offset,
@Bind("rowCount") final Long rowCount,
@BindBean final InternalTenantContext context);
+
+ @SqlQuery
+ public Long getCountByPluginName(@Bind("pluginName") final String pluginName,
+ @BindBean final InternalTenantContext context);
}
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 e234194..6a213d7 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
@@ -25,11 +25,11 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.commons.jdbi.statement.SmartFetchSize;
import com.ning.billing.payment.api.Payment;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.entity.dao.Audited;
@@ -69,12 +69,14 @@ public interface PaymentSqlDao extends EntitySqlDao<PaymentModelDao, Payment> {
@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<PaymentModelDao> getByPluginName(@Bind("pluginName") final String pluginName,
@Bind("offset") final Long offset,
@Bind("rowCount") final Long rowCount,
@BindBean final InternalTenantContext context);
+
+ @SqlQuery
+ public Long getCountByPluginName(@Bind("pluginName") final String pluginName,
+ @BindBean final InternalTenantContext context);
}
diff --git a/payment/src/main/java/com/ning/billing/payment/dao/RefundSqlDao.java b/payment/src/main/java/com/ning/billing/payment/dao/RefundSqlDao.java
index 4c3d5cb..62c2ef7 100644
--- a/payment/src/main/java/com/ning/billing/payment/dao/RefundSqlDao.java
+++ b/payment/src/main/java/com/ning/billing/payment/dao/RefundSqlDao.java
@@ -24,11 +24,11 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
import com.ning.billing.catalog.api.Currency;
+import com.ning.billing.commons.jdbi.statement.SmartFetchSize;
import com.ning.billing.payment.api.Refund;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.entity.dao.Audited;
@@ -55,11 +55,13 @@ public interface RefundSqlDao extends EntitySqlDao<RefundModelDao, Refund> {
@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<RefundModelDao> getByPluginName(@Bind("pluginName") final String pluginName,
@Bind("offset") final Long offset,
@Bind("rowCount") final Long rowCount,
@BindBean final InternalTenantContext context);
+
+ @SqlQuery
+ public Long getCountByPluginName(@Bind("pluginName") final String pluginName,
+ @BindBean final InternalTenantContext context);
}
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
index 1096c6a..a4135fb 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/PaymentMethodSqlDao.sql.stg
@@ -73,13 +73,22 @@ where account_id = :accountId
;
>>
-getByPluginName(pluginName, offset, rowCount) ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields()>
-from <tableName()>
-where plugin_name = :pluginName
-and is_active = 1
-order by record_id
+getByPluginName() ::= <<
+select
+<allTableFields("t.")>
+from <tableName()> t
+where t.plugin_name = :pluginName
+and t.is_active = 1
+order by t.record_id
limit :offset, :rowCount
;
>>
+
+getCountByPluginName() ::= <<
+select
+ count(1) as count
+from <tableName()> t
+where t.plugin_name = :pluginName
+and t.is_active = 1
+;
+>>
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 1d0ac63..88bb4b0 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
@@ -104,8 +104,8 @@ where id = :id
;
>>
-getByPluginName(pluginName, offset, rowCount) ::= <<
-select SQL_CALC_FOUND_ROWS
+getByPluginName() ::= <<
+select
<allTableFields("t.")>
from <tableName()> t
join payment_methods pm on pm.id = t.payment_method_id
@@ -114,3 +114,12 @@ order by record_id
limit :offset, :rowCount
;
>>
+
+getCountByPluginName() ::= <<
+select
+ count(1) as count
+from <tableName()> t
+join payment_methods pm on pm.id = t.payment_method_id
+where pm.plugin_name = :pluginName
+;
+>>
diff --git a/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg b/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
index 9e381f2..ff82e80 100644
--- a/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
+++ b/payment/src/main/resources/com/ning/billing/payment/dao/RefundSqlDao.sql.stg
@@ -64,8 +64,8 @@ where account_id = :accountId
;
>>
-getByPluginName(pluginName, offset, rowCount) ::= <<
-select SQL_CALC_FOUND_ROWS
+getByPluginName() ::= <<
+select
<allTableFields("t.")>
from <tableName()> t
join payments p on p.id = t.payment_id
@@ -75,3 +75,13 @@ order by record_id
limit :offset, :rowCount
;
>>
+
+getCountByPluginName() ::= <<
+select
+ count(1) as count
+from <tableName()> t
+join payments p on p.id = t.payment_id
+join payment_methods pm on pm.id = p.payment_method_id
+where pm.plugin_name = :pluginName
+;
+>>
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 d37c010..cbeda72 100644
--- a/payment/src/main/resources/com/ning/billing/payment/ddl.sql
+++ b/payment/src/main/resources/com/ning/billing/payment/ddl.sql
@@ -20,7 +20,7 @@ CREATE TABLE payments (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY (record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payments_id ON payments(id);
CREATE INDEX payments_inv ON payments(invoice_id);
CREATE INDEX payments_accnt ON payments(account_id);
@@ -50,7 +50,7 @@ CREATE TABLE payment_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_history_target_record_id ON payment_history(target_record_id);
CREATE INDEX payment_history_tenant_account_record_id ON payment_history(tenant_record_id, account_record_id);
@@ -72,7 +72,7 @@ CREATE TABLE payment_attempts (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY (record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payment_attempts_id ON payment_attempts(id);
CREATE INDEX payment_attempts_payment ON payment_attempts(payment_id);
CREATE INDEX payment_attempts_tenant_account_record_id ON payment_attempts(tenant_record_id, account_record_id);
@@ -97,7 +97,7 @@ CREATE TABLE payment_attempt_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_attempt_history_target_record_id ON payment_attempt_history(target_record_id);
CREATE INDEX payment_attempt_history_tenant_account_record_id ON payment_attempt_history(tenant_record_id, account_record_id);
@@ -115,7 +115,7 @@ CREATE TABLE payment_methods (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY (record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX payment_methods_id ON payment_methods(id);
CREATE INDEX payment_methods_active_accnt ON payment_methods(is_active, account_id);
CREATE INDEX payment_methods_tenant_account_record_id ON payment_methods(tenant_record_id, account_record_id);
@@ -136,7 +136,7 @@ CREATE TABLE payment_method_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX payment_method_history_target_record_id ON payment_method_history(target_record_id);
CREATE INDEX payment_method_history_tenant_account_record_id ON payment_method_history(tenant_record_id, account_record_id);
@@ -159,7 +159,7 @@ CREATE TABLE refunds (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY (record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX refunds_id ON refunds(id);
CREATE INDEX refunds_pay ON refunds(payment_id);
CREATE INDEX refunds_accnt ON refunds(account_id);
@@ -186,7 +186,7 @@ CREATE TABLE refund_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX refund_history_target_record_id ON refund_history(target_record_id);
CREATE INDEX refund_history_tenant_account_record_id ON refund_history(tenant_record_id, account_record_id);
pom.xml 2(+1 -1)
diff --git a/pom.xml b/pom.xml
index 5a30c75..f87e772 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>killbill-oss-parent</artifactId>
<groupId>com.ning.billing</groupId>
- <version>0.5.24</version>
+ <version>0.5.26-SNAPSHOT</version>
</parent>
<artifactId>killbill</artifactId>
<version>0.9.0-SNAPSHOT</version>
server/pom.xml 11(+0 -11)
diff --git a/server/pom.xml b/server/pom.xml
index c363832..dab1e28 100644
--- a/server/pom.xml
+++ b/server/pom.xml
@@ -68,7 +68,6 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <scope>test</scope>
</dependency>
<dependency>
<groupId>com.ning</groupId>
@@ -212,16 +211,6 @@
<scope>runtime</scope>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/server/src/main/java/com/ning/billing/server/updatechecker/UpdateChecker.java b/server/src/main/java/com/ning/billing/server/updatechecker/UpdateChecker.java
index 970341e..4910459 100644
--- a/server/src/main/java/com/ning/billing/server/updatechecker/UpdateChecker.java
+++ b/server/src/main/java/com/ning/billing/server/updatechecker/UpdateChecker.java
@@ -51,7 +51,7 @@ public class UpdateChecker {
}
};
t.setDaemon(true);
- t.run();
+ t.start();
}
private void doCheck(final ServletContext servletContext) throws IOException {
diff --git a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
index c65501a..b730844 100644
--- a/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
+++ b/server/src/test/java/com/ning/billing/jaxrs/TestJaxrsBase.java
@@ -97,8 +97,6 @@ public class TestJaxrsBase extends KillbillClient {
protected static final String PLUGIN_NAME = "noop";
- protected static final int DEFAULT_HTTP_TIMEOUT_SEC = 50000;
-
@Inject
protected OSGIServiceRegistration<Servlet> servletRouter;
@@ -111,11 +109,13 @@ public class TestJaxrsBase extends KillbillClient {
@Inject
protected PersistentBus internalBus;
+ @Inject
+ protected TestApiListener busHandler;
+
protected static TestKillbillGuiceListener listener;
protected CoreConfig config;
private HttpServer server;
- protected TestApiListener busHandler;
public static void loadSystemPropertiesFromClasspath(final String resource) {
final URL url = TestJaxrsBase.class.getResource(resource);
@@ -293,8 +293,6 @@ public class TestJaxrsBase extends KillbillClient {
loadConfig();
listener.getInstantiatedInjector().injectMembers(this);
-
- busHandler = new TestApiListener(null, dbi);
}
protected void loadConfig() {
subscription/pom.xml 15(+0 -15)
diff --git a/subscription/pom.xml b/subscription/pom.xml
index 849be09..2c4a44a 100644
--- a/subscription/pom.xml
+++ b/subscription/pom.xml
@@ -45,11 +45,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -118,16 +113,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/subscription/src/main/java/com/ning/billing/subscription/engine/dao/BundleSqlDao.java b/subscription/src/main/java/com/ning/billing/subscription/engine/dao/BundleSqlDao.java
index 7746e81..2e86a92 100644
--- a/subscription/src/main/java/com/ning/billing/subscription/engine/dao/BundleSqlDao.java
+++ b/subscription/src/main/java/com/ning/billing/subscription/engine/dao/BundleSqlDao.java
@@ -17,14 +17,12 @@
package com.ning.billing.subscription.engine.dao;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
@@ -62,13 +60,4 @@ public interface BundleSqlDao extends EntitySqlDao<SubscriptionBundleModelDao, S
@SqlQuery
public List<SubscriptionBundleModelDao> getBundlesForKey(@Bind("externalKey") String externalKey,
@BindBean final InternalTenantContext context);
-
- @SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
- public Iterator<SubscriptionBundleModelDao> searchBundles(@Bind("searchKey") final String searchKey,
- @Bind("offset") final Long offset,
- @Bind("rowCount") final Long rowCount,
- @BindBean final InternalTenantContext context);
}
diff --git a/subscription/src/main/java/com/ning/billing/subscription/engine/dao/DefaultSubscriptionDao.java b/subscription/src/main/java/com/ning/billing/subscription/engine/dao/DefaultSubscriptionDao.java
index 3c876f8..b28efea 100644
--- a/subscription/src/main/java/com/ning/billing/subscription/engine/dao/DefaultSubscriptionDao.java
+++ b/subscription/src/main/java/com/ning/billing/subscription/engine/dao/DefaultSubscriptionDao.java
@@ -194,8 +194,13 @@ public class DefaultSubscriptionDao extends EntityDaoBase<SubscriptionBundleMode
return paginationHelper.getPagination(BundleSqlDao.class,
new PaginationIteratorBuilder<SubscriptionBundleModelDao, SubscriptionBaseBundle, BundleSqlDao>() {
@Override
- public Iterator<SubscriptionBundleModelDao> build(final BundleSqlDao bundleSqlDao, final Long limit) {
- return bundleSqlDao.searchBundles(searchKey, offset, limit, context);
+ public Long getCount(final BundleSqlDao bundleSqlDao, final InternalTenantContext context) {
+ return bundleSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context);
+ }
+
+ @Override
+ public Iterator<SubscriptionBundleModelDao> build(final BundleSqlDao bundleSqlDao, final Long limit, final InternalTenantContext context) {
+ return bundleSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
}
},
offset,
diff --git a/subscription/src/main/resources/com/ning/billing/subscription/ddl.sql b/subscription/src/main/resources/com/ning/billing/subscription/ddl.sql
index 1cc4b77..6d5b7c7 100644
--- a/subscription/src/main/resources/com/ning/billing/subscription/ddl.sql
+++ b/subscription/src/main/resources/com/ning/billing/subscription/ddl.sql
@@ -21,7 +21,7 @@ CREATE TABLE subscription_events (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX subscription_events_id ON subscription_events(id);
CREATE INDEX idx_ent_1 ON subscription_events(subscription_id, is_active, effective_date);
CREATE INDEX idx_ent_2 ON subscription_events(subscription_id, effective_date, created_date, requested_date,id);
@@ -44,7 +44,7 @@ CREATE TABLE subscriptions (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX subscriptions_id ON subscriptions(id);
CREATE INDEX subscriptions_bundle_id ON subscriptions(bundle_id);
CREATE INDEX subscriptions_tenant_account_record_id ON subscriptions(tenant_record_id, account_record_id);
@@ -64,7 +64,7 @@ CREATE TABLE bundles (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX bundles_id ON bundles(id);
CREATE INDEX bundles_key ON bundles(external_key);
CREATE INDEX bundles_account ON bundles(account_id);
diff --git a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
index f5f9ade..c85a7f0 100644
--- a/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
+++ b/subscription/src/main/resources/com/ning/billing/subscription/engine/dao/BundleSqlDao.sql.stg
@@ -78,18 +78,8 @@ account_id = :accountId
;
>>
-searchBundles() ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields("t.")>
-from <tableName()> t
-where 1 = 1
-and (
- <idField("t.")> = :searchKey
- or t.external_key = :searchKey
- or t.account_id = :searchKey
-)
-<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
-limit :offset, :rowCount
-;
+searchQuery(prefix) ::= <<
+ <idField(prefix)> = :searchKey
+ or <prefix>external_key = :searchKey
+ or <prefix>account_id = :searchKey
>>
diff --git a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestSubscriptionHelper.java b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestSubscriptionHelper.java
index 522a48e..d4571a8 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestSubscriptionHelper.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestSubscriptionHelper.java
@@ -35,7 +35,6 @@ import org.testng.Assert;
import com.ning.billing.ErrorCode;
import com.ning.billing.api.TestApiListener;
import com.ning.billing.api.TestApiListener.NextEvent;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.catalog.api.BillingPeriod;
import com.ning.billing.catalog.api.Duration;
@@ -46,8 +45,6 @@ import com.ning.billing.catalog.api.ProductCategory;
import com.ning.billing.catalog.api.TimeUnit;
import com.ning.billing.clock.Clock;
import com.ning.billing.events.EffectiveSubscriptionInternalEvent;
-import com.ning.billing.subscription.SubscriptionTestListenerStatus;
-import com.ning.billing.subscription.SubscriptionTestSuiteWithEmbeddedDB;
import com.ning.billing.subscription.api.SubscriptionBaseInternalApi;
import com.ning.billing.subscription.api.SubscriptionBaseTransitionType;
import com.ning.billing.subscription.api.migration.SubscriptionBaseMigrationApi.AccountMigration;
@@ -83,17 +80,14 @@ public class TestSubscriptionHelper {
private final TestApiListener testListener;
- private final TestListenerStatus testListenerStatus;
-
private final SubscriptionDao dao;
@Inject
- public TestSubscriptionHelper(final SubscriptionBaseInternalApi subscriptionApi, final Clock clock, final InternalCallContext callContext, final TestApiListener testListener, final TestListenerStatus testListenerStatus, final SubscriptionDao dao) {
+ public TestSubscriptionHelper(final SubscriptionBaseInternalApi subscriptionApi, final Clock clock, final InternalCallContext callContext, final TestApiListener testListener, final SubscriptionDao dao) {
this.subscriptionApi = subscriptionApi;
this.clock = clock;
this.callContext = callContext;
this.testListener = testListener;
- this.testListenerStatus = testListenerStatus;
this.dao = dao;
}
@@ -115,8 +109,7 @@ public class TestSubscriptionHelper {
requestedDate == null ? clock.getUTCNow() : requestedDate, callContext);
assertNotNull(subscription);
- assertTrue(testListener.isCompleted(SubscriptionTestSuiteWithEmbeddedDB.DELAY));
- ((SubscriptionTestListenerStatus) testListenerStatus).assertListenerStatus();
+ testListener.assertListenerStatus();
return subscription;
}
diff --git a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiAddOn.java b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiAddOn.java
index e04b4d2..27f083b 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiAddOn.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiAddOn.java
@@ -161,7 +161,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -187,7 +186,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertTrue(aoSubscription.isSubscriptionFutureCancelled());
// MOVE AFTER CANCELLATION
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.CANCEL);
testListener.pushExpectedEvent(NextEvent.CANCEL);
@@ -217,7 +215,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -242,7 +239,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(aoSubscription.getState(), EntitlementState.ACTIVE);
assertTrue(aoSubscription.isSubscriptionFutureCancelled());
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.UNCANCEL);
baseSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(baseSubscription.getId(), internalCallContext);
baseSubscription.uncancel(callContext);
@@ -283,7 +279,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -314,7 +309,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(aoStatus.get(0).getPriceList(), aoSubscription.getCurrentPriceList().getName());
assertEquals(aoStatus.get(0).getReason(), DryRunChangeReason.AO_INCLUDED_IN_NEW_PLAN);
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.CHANGE);
testListener.pushExpectedEvent(NextEvent.CANCEL);
baseSubscription.changePlan(newBaseProduct, newBaseTerm, newBasePriceList, callContext);
@@ -340,9 +334,9 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
final BillingPeriod aoTerm = BillingPeriod.MONTHLY;
final String aoPriceList = PriceListSet.DEFAULT_PRICELIST_NAME;
+ // CREATE AO
DefaultSubscriptionBase aoSubscription = testUtil.createSubscription(bundle, aoProduct, aoTerm, aoPriceList);
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -381,7 +375,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertTrue(aoSubscription.isSubscriptionFutureCancelled());
// MOVE AFTER CHANGE
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.CHANGE);
testListener.pushExpectedEvent(NextEvent.CANCEL);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
@@ -410,8 +403,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(alignement, PlanAlignmentCreate.START_OF_BUNDLE);
testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignement);
-
- assertListenerStatus();
}
@Test(groups = "slow")
@@ -429,8 +420,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(alignement, PlanAlignmentCreate.START_OF_SUBSCRIPTION);
testAddonCreateInternal(aoProduct, aoTerm, aoPriceList, alignement);
-
- assertListenerStatus();
}
private void testAddonCreateInternal(final String aoProduct, final BillingPeriod aoTerm, final String aoPriceList, final PlanAlignmentCreate expAlignement) throws SubscriptionBaseApiException {
@@ -473,7 +462,6 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
}
// ADD TWO PHASE EVENTS (BP + AO)
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.PHASE);
testListener.pushExpectedEvent(NextEvent.PHASE);
@@ -498,5 +486,7 @@ public class TestUserApiAddOn extends SubscriptionTestSuiteWithEmbeddedDB {
aoSubscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(aoSubscription.getId(), internalCallContext);
aoPendingTranstion = aoSubscription.getPendingTransition();
assertNull(aoPendingTranstion);
+
+ assertListenerStatus();
}
}
diff --git a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiCancel.java b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiCancel.java
index dd7d8d3..2731c83 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiCancel.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiCancel.java
@@ -33,7 +33,6 @@ import com.ning.billing.subscription.SubscriptionTestSuiteWithEmbeddedDB;
import com.ning.billing.subscription.api.SubscriptionBillingApiException;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
@@ -67,7 +66,7 @@ public class TestUserApiCancel extends SubscriptionTestSuiteWithEmbeddedDB {
// CANCEL in trial period to get IMM policy
subscription.cancel(callContext);
currentPhase = subscription.getCurrentPhase();
- testListener.isCompleted(3000);
+ assertListenerStatus();
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
@@ -116,11 +115,8 @@ public class TestUserApiCancel extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(subscription.getLastActiveCategory(), ProductCategory.BASE);
// CANCEL
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CANCEL);
subscription.cancel(callContext);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
assertEquals(subscription.getLastActiveProduct().getName(), prod);
assertEquals(subscription.getLastActivePriceList().getName(), planSet);
diff --git a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiChangePlan.java b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiChangePlan.java
index 4e43b10..3c2bc16 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiChangePlan.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/api/user/TestUserApiChangePlan.java
@@ -38,7 +38,6 @@ import com.ning.billing.subscription.events.SubscriptionBaseEvent;
import com.ning.billing.subscription.events.user.ApiEvent;
import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
@@ -123,12 +122,9 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
subscriptionInternalApi.setChargedThroughDate(subscription.getId(), newChargedThroughDate, internalCallContext);
// RE READ SUBSCRIPTION + CHANGE PLAN
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
subscription.changePlan(toProd, toTerm, toPlanSet, callContext);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
// CHECK CHANGE PLAN
currentPhase = subscription.getCurrentPhase();
@@ -229,10 +225,7 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
checkChangePlan(subscription, fromProd, ProductCategory.BASE, fromTerm, PhaseType.EVERGREEN);
// CHECK CHANGE DID NOT KICK IN YET
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CHANGE);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
// MOVE TO AFTER CTD
testListener.pushExpectedEvent(NextEvent.CHANGE);
@@ -250,13 +243,10 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
// MOVE TIME ABOUT ONE MONTH BEFORE NEXT EXPECTED PHASE CHANGE
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.PHASE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(11));
clock.addDeltaFromReality(it.toDurationMillis());
currentTime = clock.getUTCNow();
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
final DateTime nextExpectedPhaseChange = TestSubscriptionHelper.addDuration(newChargedThroughDate, currentPhase.getDuration());
testUtil.checkNextPhaseChange(subscription, 1, nextExpectedPhaseChange);
@@ -296,11 +286,8 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
// CHANGE EOT
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription.changePlan("Pistol", BillingPeriod.MONTHLY, "gunclubDiscount", callContext);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
// CHANGE
testListener.pushExpectedEvent(NextEvent.CHANGE);
@@ -341,18 +328,12 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
subscription = (DefaultSubscriptionBase) subscriptionInternalApi.getSubscriptionFromId(subscription.getId(), internalCallContext);
// CHANGE EOT
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription.changePlan("Shotgun", BillingPeriod.MONTHLY, "gunclubDiscount", callContext);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
// CHANGE EOT
- testListener.setNonExpectedMode();
- testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription.changePlan("Pistol", BillingPeriod.ANNUAL, "gunclubDiscount", callContext);
- assertFalse(testListener.isCompleted(3000));
- testListener.reset();
+ assertListenerStatus();
// CHECK NO CHANGE OCCURED YET
Plan currentPlan = subscription.getCurrentPlan();
@@ -365,11 +346,10 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
assertNotNull(currentPhase);
assertEquals(currentPhase.getPhaseType(), PhaseType.DISCOUNT);
- // ACTIVATE CHNAGE BY MOVING AFTER CTD
+ // ACTIVATE CHANGE BY MOVING AFTER CTD
testListener.pushExpectedEvent(NextEvent.CHANGE);
it = new Interval(clock.getUTCNow(), clock.getUTCNow().plusMonths(1));
clock.addDeltaFromReality(it.toDurationMillis());
-
assertListenerStatus();
currentPlan = subscription.getCurrentPlan();
@@ -413,11 +393,9 @@ public class TestUserApiChangePlan extends SubscriptionTestSuiteWithEmbeddedDB {
clock.addDeltaFromReality(it.toDurationMillis());
// CHANGE IMMEDIATE TO A 3 PHASES PLAN
- testListener.reset();
testListener.pushExpectedEvent(NextEvent.CHANGE);
subscription.changePlan("Assault-Rifle", BillingPeriod.ANNUAL, "gunclubDiscount", callContext);
assertListenerStatus();
- testListener.reset();
// CHECK EVERYTHING LOOKS CORRECT
final Plan currentPlan = subscription.getCurrentPlan();
diff --git a/subscription/src/test/java/com/ning/billing/subscription/DefaultSubscriptionTestInitializer.java b/subscription/src/test/java/com/ning/billing/subscription/DefaultSubscriptionTestInitializer.java
index 0bbc2b1..c48e9ba 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/DefaultSubscriptionTestInitializer.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/DefaultSubscriptionTestInitializer.java
@@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.catalog.DefaultCatalogService;
import com.ning.billing.catalog.api.Catalog;
@@ -85,13 +84,12 @@ public class DefaultSubscriptionTestInitializer implements SubscriptionTestIniti
}
public void startTestFamework(final TestApiListener testListener,
- final TestListenerStatus testListenerStatus,
final ClockMock clock,
final BusService busService,
final SubscriptionBaseService subscriptionBaseService) throws Exception {
log.debug("STARTING TEST FRAMEWORK");
- resetTestListener(testListener, testListenerStatus);
+ resetTestListener(testListener);
resetClockToStartOfTest(clock);
@@ -113,11 +111,10 @@ public class DefaultSubscriptionTestInitializer implements SubscriptionTestIniti
log.debug("STOPPED TEST FRAMEWORK");
}
- private void resetTestListener(final TestApiListener testListener, final TestListenerStatus testListenerStatus) {
+ private void resetTestListener(final TestApiListener testListener) {
// RESET LIST OF EXPECTED EVENTS
if (testListener != null) {
testListener.reset();
- testListenerStatus.resetTestListenerStatus();
}
}
diff --git a/subscription/src/test/java/com/ning/billing/subscription/glue/TestDefaultSubscriptionModule.java b/subscription/src/test/java/com/ning/billing/subscription/glue/TestDefaultSubscriptionModule.java
index c4a1020..93ad00f 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/glue/TestDefaultSubscriptionModule.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/glue/TestDefaultSubscriptionModule.java
@@ -21,11 +21,9 @@ import org.skife.config.ConfigSource;
import com.ning.billing.account.api.AccountUserApi;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.glue.CatalogModule;
import com.ning.billing.subscription.DefaultSubscriptionTestInitializer;
import com.ning.billing.subscription.SubscriptionTestInitializer;
-import com.ning.billing.subscription.SubscriptionTestListenerStatus;
import com.ning.billing.subscription.api.user.TestSubscriptionHelper;
import com.ning.billing.util.glue.CacheModule;
import com.ning.billing.util.glue.CallContextModule;
@@ -46,7 +44,6 @@ public class TestDefaultSubscriptionModule extends DefaultSubscriptionModule {
bind(AccountUserApi.class).toInstance(Mockito.mock(AccountUserApi.class));
bind(TestSubscriptionHelper.class).asEagerSingleton();
- bind(TestListenerStatus.class).to(SubscriptionTestListenerStatus.class).asEagerSingleton();
bind(TestApiListener.class).asEagerSingleton();
bind(SubscriptionTestInitializer.class).to(DefaultSubscriptionTestInitializer.class).asEagerSingleton();
}
diff --git a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestInitializer.java b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestInitializer.java
index da76f3b..001f093 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestInitializer.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestInitializer.java
@@ -18,14 +18,13 @@ package com.ning.billing.subscription;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
+import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.catalog.api.Catalog;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.clock.ClockMock;
+import com.ning.billing.subscription.api.SubscriptionBaseInternalApi;
import com.ning.billing.subscription.api.SubscriptionBaseService;
import com.ning.billing.subscription.api.user.SubscriptionBaseBundle;
-import com.ning.billing.callcontext.InternalCallContext;
-import com.ning.billing.subscription.api.SubscriptionBaseInternalApi;
import com.ning.billing.util.svcsapi.bus.BusService;
public interface SubscriptionTestInitializer {
@@ -37,7 +36,6 @@ public interface SubscriptionTestInitializer {
public SubscriptionBaseBundle initBundle(final SubscriptionBaseInternalApi subscriptionApi, final InternalCallContext callContext) throws Exception;
public void startTestFamework(final TestApiListener testListener,
- final TestListenerStatus testListenerStatus,
final ClockMock clock,
final BusService busService,
final SubscriptionBaseService subscriptionBaseService) throws Exception;
diff --git a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteNoDB.java b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteNoDB.java
index 9028afc..2ba7c8d 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteNoDB.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteNoDB.java
@@ -33,7 +33,6 @@ import org.testng.annotations.BeforeMethod;
import com.ning.billing.GuicyKillbillTestSuiteNoDB;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.api.Catalog;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.clock.ClockMock;
@@ -88,8 +87,6 @@ public class SubscriptionTestSuiteNoDB extends GuicyKillbillTestSuiteNoDB {
protected TestSubscriptionHelper testUtil;
@Inject
protected TestApiListener testListener;
- @Inject
- protected TestListenerStatus testListenerStatus;
@Inject
protected SubscriptionTestInitializer subscriptionTestInitializer;
@@ -122,7 +119,7 @@ public class SubscriptionTestSuiteNoDB extends GuicyKillbillTestSuiteNoDB {
// CLEANUP ALL DB TABLES OR IN MEMORY STRUCTURES
((MockSubscriptionDaoMemory) dao).reset();
- subscriptionTestInitializer.startTestFamework(testListener, testListenerStatus, clock, busService, subscriptionBaseService);
+ subscriptionTestInitializer.startTestFamework(testListener, clock, busService, subscriptionBaseService);
this.catalog = subscriptionTestInitializer.initCatalog(catalogService);
this.accountData = subscriptionTestInitializer.initAccountData();
@@ -135,6 +132,6 @@ public class SubscriptionTestSuiteNoDB extends GuicyKillbillTestSuiteNoDB {
}
protected void assertListenerStatus() {
- ((SubscriptionTestListenerStatus) testListenerStatus).assertListenerStatus();
+ testListener.assertListenerStatus();
}
}
diff --git a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteWithEmbeddedDB.java b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteWithEmbeddedDB.java
index e6da5ea..89e53d9 100644
--- a/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteWithEmbeddedDB.java
+++ b/subscription/src/test/java/com/ning/billing/subscription/SubscriptionTestSuiteWithEmbeddedDB.java
@@ -30,7 +30,6 @@ import org.testng.annotations.BeforeMethod;
import com.ning.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.account.api.AccountData;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.catalog.api.Catalog;
import com.ning.billing.catalog.api.CatalogService;
import com.ning.billing.clock.ClockMock;
@@ -50,8 +49,6 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-import static org.testng.Assert.assertTrue;
-
public class SubscriptionTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWithEmbeddedDB {
protected static final Logger log = LoggerFactory.getLogger(SubscriptionTestSuiteWithEmbeddedDB.class);
@@ -86,8 +83,6 @@ public class SubscriptionTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteW
@Inject
protected TestApiListener testListener;
@Inject
- protected TestListenerStatus testListenerStatus;
- @Inject
protected SubscriptionTestInitializer subscriptionTestInitializer;
protected Catalog catalog;
@@ -113,7 +108,7 @@ public class SubscriptionTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteW
@BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
super.beforeMethod();
- subscriptionTestInitializer.startTestFamework(testListener, testListenerStatus, clock, busService, subscriptionBaseService);
+ subscriptionTestInitializer.startTestFamework(testListener, clock, busService, subscriptionBaseService);
this.catalog = subscriptionTestInitializer.initCatalog(catalogService);
this.accountData = subscriptionTestInitializer.initAccountData();
@@ -132,7 +127,6 @@ public class SubscriptionTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteW
}
protected void assertListenerStatus() {
- assertTrue(testListener.isCompleted(DELAY));
- ((SubscriptionTestListenerStatus) testListenerStatus).assertListenerStatus();
+ testListener.assertListenerStatus();
}
}
tenant/pom.xml 15(+0 -15)
diff --git a/tenant/pom.xml b/tenant/pom.xml
index 8ec6759..41552d1 100644
--- a/tenant/pom.xml
+++ b/tenant/pom.xml
@@ -41,11 +41,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.ning.billing</groupId>
<artifactId>killbill-api</artifactId>
</dependency>
@@ -83,16 +78,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/tenant/src/main/resources/com/ning/billing/tenant/ddl.sql b/tenant/src/main/resources/com/ning/billing/tenant/ddl.sql
index 807620d..40d439a 100644
--- a/tenant/src/main/resources/com/ning/billing/tenant/ddl.sql
+++ b/tenant/src/main/resources/com/ning/billing/tenant/ddl.sql
@@ -13,7 +13,7 @@ CREATE TABLE tenants (
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tenants_id ON tenants(id);
CREATE UNIQUE INDEX tenants_api_key ON tenants(api_key);
@@ -31,5 +31,5 @@ CREATE TABLE tenant_kvs (
updated_date datetime DEFAULT NULL,
updated_by varchar(50) DEFAULT NULL,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX tenant_kvs_key ON tenant_kvs(tenant_key);
usage/pom.xml 15(+0 -15)
diff --git a/usage/pom.xml b/usage/pom.xml
index a273359..5d0e778 100644
--- a/usage/pom.xml
+++ b/usage/pom.xml
@@ -36,11 +36,6 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.ning.billing</groupId>
<artifactId>killbill-api</artifactId>
</dependency>
@@ -78,16 +73,6 @@
<artifactId>joda-time</artifactId>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>org.antlr</groupId>
<artifactId>stringtemplate</artifactId>
<scope>runtime</scope>
diff --git a/usage/src/main/resources/com/ning/billing/usage/ddl.sql b/usage/src/main/resources/com/ning/billing/usage/ddl.sql
index c9c9011..aa1bd96 100644
--- a/usage/src/main/resources/com/ning/billing/usage/ddl.sql
+++ b/usage/src/main/resources/com/ning/billing/usage/ddl.sql
@@ -14,7 +14,7 @@ CREATE TABLE rolled_up_usage (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX rolled_up_usage_id ON rolled_up_usage(id);
CREATE INDEX rolled_up_usage_subscription_id ON rolled_up_usage(subscription_id ASC);
CREATE INDEX rolled_up_usage_tenant_account_record_id ON rolled_up_usage(tenant_record_id, account_record_id);
util/pom.xml 27(+11 -16)
diff --git a/util/pom.xml b/util/pom.xml
index f8efff6..ca76f02 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -56,11 +56,6 @@
<artifactId>guice-multibindings</artifactId>
</dependency>
<dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>com.jayway.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
@@ -93,7 +88,17 @@
</dependency>
<dependency>
<groupId>com.ning.billing.commons</groupId>
- <artifactId>killbill-embeddeddb</artifactId>
+ <artifactId>killbill-embeddeddb-common</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing.commons</groupId>
+ <artifactId>killbill-embeddeddb-h2</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.ning.billing.commons</groupId>
+ <artifactId>killbill-embeddeddb-mysql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -141,16 +146,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-mxj-db-files</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<type>jar</type>
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
index c257b74..d0755f1 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.java
@@ -16,7 +16,6 @@
package com.ning.billing.util.customfield.dao;
-import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@@ -24,7 +23,6 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.ObjectType;
import com.ning.billing.callcontext.InternalCallContext;
@@ -47,14 +45,4 @@ public interface CustomFieldSqlDao extends EntitySqlDao<CustomFieldModelDao, Cus
List<CustomFieldModelDao> getCustomFieldsForObject(@Bind("objectId") UUID objectId,
@Bind("objectType") ObjectType objectType,
@BindBean InternalTenantContext internalTenantContext);
-
- @SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
- public Iterator<CustomFieldModelDao> searchCustomFields(@Bind("searchKey") final String searchKey,
- @Bind("likeSearchKey") final String likeSearchKey,
- @Bind("offset") final Long offset,
- @Bind("rowCount") final Long rowCount,
- @BindBean final InternalTenantContext context);
}
diff --git a/util/src/main/java/com/ning/billing/util/customfield/dao/DefaultCustomFieldDao.java b/util/src/main/java/com/ning/billing/util/customfield/dao/DefaultCustomFieldDao.java
index 092d95a..b18fc41 100644
--- a/util/src/main/java/com/ning/billing/util/customfield/dao/DefaultCustomFieldDao.java
+++ b/util/src/main/java/com/ning/billing/util/customfield/dao/DefaultCustomFieldDao.java
@@ -147,8 +147,13 @@ public class DefaultCustomFieldDao extends EntityDaoBase<CustomFieldModelDao, Cu
return paginationHelper.getPagination(CustomFieldSqlDao.class,
new PaginationIteratorBuilder<CustomFieldModelDao, CustomField, CustomFieldSqlDao>() {
@Override
- public Iterator<CustomFieldModelDao> build(final CustomFieldSqlDao customFieldSqlDao, final Long limit) {
- return customFieldSqlDao.searchCustomFields(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
+ public Long getCount(final CustomFieldSqlDao customFieldSqlDao, final InternalTenantContext context) {
+ return customFieldSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context);
+ }
+
+ @Override
+ public Iterator<CustomFieldModelDao> build(final CustomFieldSqlDao customFieldSqlDao, final Long limit, final InternalTenantContext context) {
+ return customFieldSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
}
},
offset,
diff --git a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
index 7f91aac..ee475f1 100644
--- a/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/dao/AuditSqlDao.java
@@ -24,10 +24,10 @@ import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
import org.skife.jdbi.v2.sqlobject.customizers.Define;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
+import com.ning.billing.commons.jdbi.statement.SmartFetchSize;
import com.ning.billing.util.audit.dao.AuditLogModelDao;
import com.ning.billing.util.cache.Cachable;
import com.ning.billing.util.cache.Cachable.CacheType;
@@ -52,15 +52,11 @@ public interface AuditSqlDao {
@BindBean final InternalCallContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<AuditLogModelDao> getAuditLogsForAccountRecordId(@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<AuditLogModelDao> getAuditLogsForTableNameAndAccountRecordId(@Bind("tableName") final String tableName,
@BindBean final InternalTenantContext context);
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/DefaultPaginationSqlDaoHelper.java b/util/src/main/java/com/ning/billing/util/entity/dao/DefaultPaginationSqlDaoHelper.java
index e245ffd..de81a5b 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/DefaultPaginationSqlDaoHelper.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/DefaultPaginationSqlDaoHelper.java
@@ -39,18 +39,12 @@ public class DefaultPaginationSqlDaoHelper {
// Note: the connection will be busy as we stream the results out: hence we cannot use
// SQL_CALC_FOUND_ROWS / FOUND_ROWS on the actual query.
// We still need to know the actual number of results, mainly for the UI so that it knows if it needs to fetch
- // more pages. To do that, we perform a dummy search query with SQL_CALC_FOUND_ROWS (but limit 1).
+ // more pages.
final Long count = transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Long>() {
@Override
public Long inTransaction(final EntitySqlDaoWrapperFactory<EntitySqlDao> entitySqlDaoWrapperFactory) throws Exception {
final EntitySqlDao<M, E> sqlDao = entitySqlDaoWrapperFactory.become(sqlDaoClazz);
- // TODO lame cast, but couldn't make sqlDaoClazz a Class<? extends S>
- final Iterator<M> dumbIterator = paginationIteratorBuilder.build((S) sqlDao, 1L);
- // Make sure to go through the results to close the connection
- while (dumbIterator.hasNext()) {
- dumbIterator.next();
- }
- return sqlDao.getFoundRows(context);
+ return paginationIteratorBuilder.getCount((S) sqlDao, context);
}
});
@@ -58,14 +52,15 @@ public class DefaultPaginationSqlDaoHelper {
// Since we want to stream the results out, we don't want to auto-commit when this method returns.
final EntitySqlDao<M, E> sqlDao = transactionalSqlDao.onDemand(sqlDaoClazz);
final Long totalCount = sqlDao.getCount(context);
- final Iterator<M> results = paginationIteratorBuilder.build((S) sqlDao, limit);
+ final Iterator<M> results = paginationIteratorBuilder.build((S) sqlDao, limit, context);
return new DefaultPagination<M>(offset, limit, count, totalCount, results);
}
public abstract static class PaginationIteratorBuilder<M extends EntityModelDao<E>, E extends Entity, S extends EntitySqlDao<M, E>> {
- public abstract Iterator<M> build(final S sqlDao,
- final Long limit);
+ public abstract Long getCount(final S sqlDao, final InternalTenantContext context);
+
+ public abstract Iterator<M> build(final S sqlDao, final Long limit, final InternalTenantContext context);
}
}
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/EntityDaoBase.java b/util/src/main/java/com/ning/billing/util/entity/dao/EntityDaoBase.java
index a0721bc..61ae426 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/EntityDaoBase.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/EntityDaoBase.java
@@ -77,7 +77,7 @@ public abstract class EntityDaoBase<M extends EntityModelDao<E>, E extends Entit
protected abstract U generateAlreadyExistsException(final M entity, final InternalCallContext context);
protected String getNaturalOrderingColumns() {
- return "recordId";
+ return "record_id";
}
@Override
@@ -124,7 +124,7 @@ public abstract class EntityDaoBase<M extends EntityModelDao<E>, E extends Entit
// Note: we need to perform the count before streaming the results, as the connection
// will be busy as we stream the results out. This is also why we cannot use
- // SQL_CALC_FOUND_ROWS / FOUND_ROWS (which may ne be faster anyways).
+ // SQL_CALC_FOUND_ROWS / FOUND_ROWS (which may not be faster anyways).
final Long count = sqlDao.getCount(context);
final Iterator<M> results = sqlDao.getAll(context);
@@ -136,7 +136,12 @@ public abstract class EntityDaoBase<M extends EntityModelDao<E>, E extends Entit
return paginationHelper.getPagination(realSqlDao,
new PaginationIteratorBuilder<M, E, EntitySqlDao<M, E>>() {
@Override
- public Iterator<M> build(final EntitySqlDao<M, E> sqlDao, final Long limit) {
+ public Long getCount(final EntitySqlDao<M, E> sqlDao, final InternalTenantContext context) {
+ return sqlDao.getCount(context);
+ }
+
+ @Override
+ public Iterator<M> build(final EntitySqlDao<M, E> sqlDao, final Long limit, final InternalTenantContext context) {
return sqlDao.get(offset, limit, getNaturalOrderingColumns(), context);
}
},
diff --git a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
index 44506de..6f331a6 100644
--- a/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/entity/dao/EntitySqlDao.java
@@ -23,13 +23,14 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
+import org.skife.jdbi.v2.sqlobject.customizers.Define;
import org.skife.jdbi.v2.sqlobject.mixins.CloseMe;
import org.skife.jdbi.v2.sqlobject.mixins.Transactional;
import org.skife.jdbi.v2.sqlobject.mixins.Transmogrifier;
import com.ning.billing.callcontext.InternalCallContext;
import com.ning.billing.callcontext.InternalTenantContext;
+import com.ning.billing.commons.jdbi.statement.SmartFetchSize;
import com.ning.billing.entity.EntityPersistenceException;
import com.ning.billing.util.audit.ChangeType;
import com.ning.billing.util.cache.Cachable;
@@ -70,21 +71,27 @@ public interface EntitySqlDao<M extends EntityModelDao<E>, E extends Entity> ext
@BindBean final InternalTenantContext context);
@SqlQuery
- public Long getFoundRows(@BindBean final InternalTenantContext context);
+ @SmartFetchSize(shouldStream = true)
+ public Iterator<M> search(@Bind("searchKey") final String searchKey,
+ @Bind("likeSearchKey") final String likeSearchKey,
+ @Bind("offset") final Long offset,
+ @Bind("rowCount") final Long rowCount,
+ @BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ public Long getSearchCount(@Bind("searchKey") final String searchKey,
+ @Bind("likeSearchKey") final String likeSearchKey,
+ @BindBean final InternalTenantContext context);
+
+ @SqlQuery
+ @SmartFetchSize(shouldStream = true)
public Iterator<M> getAll(@BindBean final InternalTenantContext context);
@SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
+ @SmartFetchSize(shouldStream = true)
public Iterator<M> get(@Bind("offset") final Long offset,
@Bind("rowCount") final Long rowCount,
- @Bind("orderBy") final String orderBy,
+ @Define("orderBy") final String orderBy,
@BindBean final InternalTenantContext context);
@SqlQuery
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDao.java
index 4a4abaa..caf92b0 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/DefaultTagDao.java
@@ -222,8 +222,13 @@ public class DefaultTagDao extends EntityDaoBase<TagModelDao, Tag, TagApiExcepti
return paginationHelper.getPagination(TagSqlDao.class,
new PaginationIteratorBuilder<TagModelDao, Tag, TagSqlDao>() {
@Override
- public Iterator<TagModelDao> build(final TagSqlDao tagSqlDao, final Long limit) {
- return tagSqlDao.searchTags(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
+ public Long getCount(final TagSqlDao tagSqlDao, final InternalTenantContext context) {
+ return tagSqlDao.getSearchCount(searchKey, String.format("%%%s%%", searchKey), context);
+ }
+
+ @Override
+ public Iterator<TagModelDao> build(final TagSqlDao tagSqlDao, final Long limit, final InternalTenantContext context) {
+ return tagSqlDao.search(searchKey, String.format("%%%s%%", searchKey), offset, limit, context);
}
},
offset,
diff --git a/util/src/main/java/com/ning/billing/util/tag/dao/TagSqlDao.java b/util/src/main/java/com/ning/billing/util/tag/dao/TagSqlDao.java
index 668553b..26caab0 100644
--- a/util/src/main/java/com/ning/billing/util/tag/dao/TagSqlDao.java
+++ b/util/src/main/java/com/ning/billing/util/tag/dao/TagSqlDao.java
@@ -16,7 +16,6 @@
package com.ning.billing.util.tag.dao;
-import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@@ -24,7 +23,6 @@ import org.skife.jdbi.v2.sqlobject.Bind;
import org.skife.jdbi.v2.sqlobject.BindBean;
import org.skife.jdbi.v2.sqlobject.SqlQuery;
import org.skife.jdbi.v2.sqlobject.SqlUpdate;
-import org.skife.jdbi.v2.sqlobject.customizers.FetchSize;
import com.ning.billing.ObjectType;
import com.ning.billing.callcontext.InternalCallContext;
@@ -52,14 +50,4 @@ public interface TagSqlDao extends EntitySqlDao<TagModelDao, Tag> {
List<TagModelDao> getTagsForObjectIncludedDeleted(@Bind("objectId") UUID objectId,
@Bind("objectType") ObjectType objectType,
@BindBean InternalTenantContext internalTenantContext);
-
- @SqlQuery
- // Magic value to force MySQL to stream from the database
- // See http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-implementation-notes.html (ResultSet)
- @FetchSize(Integer.MIN_VALUE)
- public Iterator<TagModelDao> searchTags(@Bind("searchKey") final String searchKey,
- @Bind("likeSearchKey") final String likeSearchKey,
- @Bind("offset") final Long offset,
- @Bind("rowCount") final Long rowCount,
- @BindBean final InternalTenantContext context);
}
diff --git a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
index 1d01add..8bc1d99 100644
--- a/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/customfield/dao/CustomFieldSqlDao.sql.stg
@@ -52,19 +52,9 @@ and is_active
;
>>
-searchCustomFields() ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields("t.")>
-from <tableName()> t
-where 1 = 1
-and (
- <idField("t.")> = :searchKey
- or t.object_type like :likeSearchKey
- or t.field_name like :likeSearchKey
- or t.field_value like :likeSearchKey
-)
-<AND_CHECK_TENANT("t.")>
-order by <recordIdField("t.")> ASC
-limit :offset, :rowCount
-;
+searchQuery(prefix) ::= <<
+ <idField(prefix)> = :searchKey
+ or <prefix>object_type like :likeSearchKey
+ or <prefix>field_name like :likeSearchKey
+ or <prefix>field_value like :likeSearchKey
>>
diff --git a/util/src/main/resources/com/ning/billing/util/ddl.sql b/util/src/main/resources/com/ning/billing/util/ddl.sql
index c32c386..2704dc9 100644
--- a/util/src/main/resources/com/ning/billing/util/ddl.sql
+++ b/util/src/main/resources/com/ning/billing/util/ddl.sql
@@ -16,7 +16,7 @@ CREATE TABLE custom_fields (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX custom_fields_id ON custom_fields(id);
CREATE INDEX custom_fields_object_id_object_type ON custom_fields(object_id, object_type);
CREATE INDEX custom_fields_tenant_account_record_id ON custom_fields(tenant_record_id, account_record_id);
@@ -39,7 +39,7 @@ CREATE TABLE custom_field_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX custom_field_history_target_record_id ON custom_field_history(target_record_id);
CREATE INDEX custom_field_history_object_id_object_type ON custom_fields(object_id, object_type);
CREATE INDEX custom_field_history_tenant_account_record_id ON custom_field_history(tenant_record_id, account_record_id);
@@ -57,7 +57,7 @@ CREATE TABLE tag_definitions (
updated_date datetime NOT NULL,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tag_definitions_id ON tag_definitions(id);
CREATE INDEX tag_definitions_tenant_record_id ON tag_definitions(tenant_record_id);
@@ -77,7 +77,7 @@ CREATE TABLE tag_definition_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX tag_definition_history_id ON tag_definition_history(id);
CREATE INDEX tag_definition_history_target_record_id ON tag_definition_history(target_record_id);
CREATE INDEX tag_definition_history_name ON tag_definition_history(name);
@@ -98,7 +98,7 @@ CREATE TABLE tags (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE UNIQUE INDEX tags_id ON tags(id);
CREATE INDEX tags_by_object ON tags(object_id);
CREATE INDEX tags_tenant_account_record_id ON tags(tenant_record_id, account_record_id);
@@ -120,7 +120,7 @@ CREATE TABLE tag_history (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX tag_history_target_record_id ON tag_history(target_record_id);
CREATE INDEX tag_history_by_object ON tags(object_id);
CREATE INDEX tag_history_tenant_account_record_id ON tag_history(tenant_record_id, account_record_id);
@@ -140,7 +140,7 @@ CREATE TABLE audit_log (
account_record_id int(11) unsigned default null,
tenant_record_id int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX audit_log_fetch_target_record_id ON audit_log(table_name, target_record_id);
CREATE INDEX audit_log_user_name ON audit_log(created_by);
CREATE INDEX audit_log_tenant_account_record_id ON audit_log(tenant_record_id, account_record_id);
@@ -166,7 +166,7 @@ CREATE TABLE notifications (
effective_date datetime NOT NULL,
future_user_token char(36),
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX `idx_comp_where` ON notifications (`effective_date`, `processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX `idx_update` ON notifications (`processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX `idx_get_ready` ON notifications (`effective_date`,`created_date`);
@@ -190,7 +190,7 @@ CREATE TABLE notifications_history (
effective_date datetime NOT NULL,
future_user_token char(36),
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
DROP TABLE IF EXISTS bus_events;
CREATE TABLE bus_events (
@@ -207,7 +207,7 @@ CREATE TABLE bus_events (
search_key1 int(11) unsigned default null,
search_key2 int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
CREATE INDEX `idx_bus_where` ON bus_events (`processing_state`,`processing_owner`,`processing_available_date`);
CREATE INDEX bus_events_tenant_account_record_id ON bus_events(search_key2, search_key1);
@@ -226,7 +226,7 @@ CREATE TABLE bus_events_history (
search_key1 int(11) unsigned default null,
search_key2 int(11) unsigned default null,
PRIMARY KEY(record_id)
-) CHARACTER SET utf8 COLLATE utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
drop table if exists sessions;
create table sessions (
@@ -237,4 +237,4 @@ create table sessions (
, host varchar(100) default null
, session_data mediumblob default null
, primary key(record_id)
-) character set utf8 collate utf8_bin;
+) /*! CHARACTER SET utf8 COLLATE utf8_bin */;
diff --git a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
index 6214825..85031cd 100644
--- a/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/entity/dao/EntitySqlDao.sql.stg
@@ -137,10 +137,6 @@ allHistoryTableValues() ::= <<
CHECK_TENANT(prefix) ::= "<prefix>tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT(prefix) ::= "and <CHECK_TENANT(prefix)>"
-getFoundRows() ::= <<
-select FOUND_ROWS();
->>
-
getAll() ::= <<
select
<allTableFields("t.")>
@@ -152,12 +148,12 @@ where <CHECK_TENANT("t.")>
>>
get(offset, rowCount, orderBy) ::= <<
-select SQL_CALC_FOUND_ROWS
+select
<allTableFields("t.")>
from <tableName()> t
where <CHECK_TENANT("t.")>
<andCheckSoftDeletionWithComma("t.")>
-order by :orderBy
+order by t.<orderBy>
limit :offset, :rowCount
;
>>
@@ -191,12 +187,12 @@ where <recordIdField("t.")> = :recordId
;
>>
-/** Use NULL-safe equal to operator in case account_record_id is NULL **/
+/** Note: account_record_id can be NULL **/
getByAccountRecordId(accountRecordId) ::= <<
select
<allTableFields("t.")>
from <tableName()> t
-where <accountRecordIdField("t.")> \<=\> :accountRecordId
+where (<accountRecordIdField("t.")> = :accountRecordId or (<accountRecordIdField("t.")> is null and :accountRecordId is null))
<andCheckSoftDeletionWithComma("t.")>
<AND_CHECK_TENANT("t.")>
<defaultOrderBy("t.")>
@@ -207,7 +203,7 @@ getByAccountRecordIdIncludedDeleted(accountRecordId) ::= <<
select
<allTableFields("t.")>
from <tableName()> t
-where <accountRecordIdField("t.")> \<=\> :accountRecordId
+where (<accountRecordIdField("t.")> = :accountRecordId or (<accountRecordIdField("t.")> is null and :accountRecordId is null))
<AND_CHECK_TENANT("t.")>
<defaultOrderBy("t.")>
;
@@ -223,7 +219,6 @@ where <recordIdField("t.")> = :recordId
;
>>
-
getRecordId(id) ::= <<
select
<recordIdField("t.")>
@@ -254,7 +249,6 @@ where <targetRecordIdField("t.")> = :targetRecordId
;
>>
-
getHistoryRecordIdsForTable(historyTableName) ::= <<
select
<recordIdField("t.")>
@@ -265,6 +259,29 @@ where <targetRecordIdField("t.")> = :targetRecordId
;
>>
+searchQuery(prefix) ::= <<
+1 = 1
+>>
+
+search() ::= <<
+select
+<allTableFields("t.")>
+from <tableName()> t
+where (<searchQuery("t.")>)
+<AND_CHECK_TENANT("t.")>
+order by <recordIdField("t.")> ASC
+limit :offset, :rowCount
+;
+>>
+
+getSearchCount() ::= <<
+select
+ count(1) as count
+from <tableName()> t
+where (<searchQuery("t.")>)
+<AND_CHECK_TENANT("t.")>
+;
+>>
create() ::= <<
insert into <tableName()> (
diff --git a/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg b/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
index 8dbc6dc..efdc434 100644
--- a/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
+++ b/util/src/main/resources/com/ning/billing/util/tag/dao/TagSqlDao.sql.stg
@@ -58,11 +58,7 @@ and t.object_type = :objectType
;
>>
-searchTags() ::= <<
-select SQL_CALC_FOUND_ROWS
-<allTableFields("t.")>
-from <tableName()> t
-join (
+userAndSystemTagDefinitions() ::= <<
select
id
, name
@@ -75,7 +71,7 @@ join (
, \'Suspends payments until removed.\' description
union
select
- \'00000000-0000-0000-0000-000000000001\' id
+ \'00000000-0000-0000-0000-000000000002\' id
, \'AUTO_INVOICING_OFF\' name
, \'Suspends invoicing until removed.\' description
union
@@ -92,7 +88,7 @@ join (
select
\'00000000-0000-0000-0000-000000000005\' id
, \'MANUAL_PAY\' name
- , \'Indicates that Killbill doesn\\\\\'t process payments for that account (external payments only)\' description
+ , \'Indicates that Killbill doesn\\'\\'t process payments for that account (external payments only)\' description
union
select
\'00000000-0000-0000-0000-000000000006\' id
@@ -103,16 +99,33 @@ join (
\'00000000-0000-0000-0000-000000000007\' id
, \'PARTNER\' name
, \'Indicates that this is a partner account\' description
-) td on td.id = t.tag_definition_id
-where 1 = 1
-and (
- <idField("t.")> = :searchKey
- or t.object_type like :likeSearchKey
- or td.name like :likeSearchKey
- or td.description like :likeSearchKey
-)
+>>
+
+searchQuery(tagAlias, tagDefinitionAlias) ::= <<
+ <idField(tagAlias)> = :searchKey
+ or <tagAlias>object_type like :likeSearchKey
+ or <tagDefinitionAlias>name like :likeSearchKey
+ or <tagDefinitionAlias>description like :likeSearchKey
+>>
+
+search() ::= <<
+select
+<allTableFields("t.")>
+from <tableName()> t
+join (<userAndSystemTagDefinitions()>) td on td.id = t.tag_definition_id
+where (<searchQuery(tagAlias="t.", tagDefinitionAlias="td.")>)
<AND_CHECK_TENANT("t.")>
order by <recordIdField("t.")> ASC
limit :offset, :rowCount
;
>>
+
+getSearchCount() ::= <<
+select
+ count(1) as count
+from <tableName()> t
+join (<userAndSystemTagDefinitions()>) td on td.id = t.tag_definition_id
+where (<searchQuery(tagAlias="t.", tagDefinitionAlias="td.")>)
+<AND_CHECK_TENANT("t.")>
+;
+>>
diff --git a/util/src/test/java/com/ning/billing/api/TestApiListener.java b/util/src/test/java/com/ning/billing/api/TestApiListener.java
index 1f8aacf..3cd1d49 100644
--- a/util/src/test/java/com/ning/billing/api/TestApiListener.java
+++ b/util/src/test/java/com/ning/billing/api/TestApiListener.java
@@ -20,6 +20,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Stack;
import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
@@ -29,6 +30,7 @@ import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.tweak.HandleCallback;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.testng.Assert;
import com.ning.billing.events.BlockingTransitionInternalEvent;
import com.ning.billing.events.CustomFieldEvent;
@@ -47,30 +49,45 @@ import com.google.common.base.Joiner;
import com.google.common.eventbus.Subscribe;
import static com.jayway.awaitility.Awaitility.await;
-import static java.util.concurrent.TimeUnit.SECONDS;
+import static org.testng.Assert.assertTrue;
+import static org.testng.Assert.fail;
public class TestApiListener {
- protected static final Logger log = LoggerFactory.getLogger(TestApiListener.class);
+ private static final Logger log = LoggerFactory.getLogger(TestApiListener.class);
- private final List<NextEvent> nextExpectedEvent;
+ private static final Joiner SPACE_JOINER = Joiner.on(" ");
+
+ private static final long DELAY = 25000;
- private final TestListenerStatus testStatus;
+ private final List<NextEvent> nextExpectedEvent;
private final IDBI idbi;
- private boolean nonExpectedMode;
+ private boolean isListenerFailed = false;
+ private String listenerFailedMsg;
private volatile boolean completed;
@Inject
- public TestApiListener(final TestListenerStatus testStatus, final IDBI idbi) {
+ public TestApiListener(final IDBI idbi) {
nextExpectedEvent = new Stack<NextEvent>();
this.completed = false;
- this.testStatus = testStatus;
- this.nonExpectedMode = false;
this.idbi = idbi;
}
+ public void assertListenerStatus() {
+ try {
+ assertTrue(isCompleted(DELAY));
+ } catch (final Exception e) {
+ fail("assertListenerStatus didn't complete", e);
+ }
+
+ if (isListenerFailed) {
+ log.error(listenerFailedMsg);
+ Assert.fail(listenerFailedMsg);
+ }
+ }
+
public enum NextEvent {
MIGRATE_ENTITLEMENT,
MIGRATE_BILLING,
@@ -95,12 +112,6 @@ public class TestApiListener {
CUSTOM_FIELD,
}
- public void setNonExpectedMode() {
- synchronized (this) {
- this.nonExpectedMode = true;
- }
- }
-
@Subscribe
public void handleRepairSubscriptionEvents(final RepairSubscriptionInternalEvent event) {
log.info(String.format("Got RepairSubscriptionEvent event %s", event.toString()));
@@ -189,7 +200,6 @@ public class TestApiListener {
notifyIfStackEmpty();
}
-
@Subscribe
public synchronized void processTagDefinitonEvent(final TagDefinitionInternalEvent event) {
log.info(String.format("Got TagDefinitionInternalEvent event %s", event.toString()));
@@ -236,7 +246,9 @@ public class TestApiListener {
synchronized (this) {
nextExpectedEvent.clear();
completed = true;
- nonExpectedMode = false;
+
+ isListenerFailed = false;
+ listenerFailedMsg = null;
}
}
@@ -248,9 +260,8 @@ public class TestApiListener {
public void pushExpectedEvent(final NextEvent next) {
synchronized (this) {
- final Joiner joiner = Joiner.on(" ");
nextExpectedEvent.add(next);
- log.debug("Stacking expected event {}, got [{}]", next, joiner.join(nextExpectedEvent));
+ log.debug("Stacking expected event {}, got [{}]", next, SPACE_JOINER.join(nextExpectedEvent));
completed = false;
}
}
@@ -271,7 +282,7 @@ public class TestApiListener {
// all expected events. But other handlers might still be processing them.
// Since there is only one bus thread, and that the test thread waits for all events to be processed,
// we're guaranteed that all are processed when the bus events table is empty.
- await().atMost(10, SECONDS).until(new Callable<Boolean>() {
+ await().atMost(timeout, TimeUnit.MILLISECONDS).until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
final long inProcessingBusEvents = idbi.withHandle(new HandleCallback<Long>() {
@@ -288,16 +299,18 @@ public class TestApiListener {
}
final DateTime after = new DateTime();
waitTimeMs -= after.getMillis() - before.getMillis();
- } catch (Exception ignore) {
+ } catch (final Exception ignore) {
log.error("isCompleted got interrupted ", ignore);
return false;
}
} while (waitTimeMs > 0 && !completed);
}
- if (!completed && !nonExpectedMode) {
+
+ if (!completed) {
final Joiner joiner = Joiner.on(" ");
log.error("TestApiListener did not complete in " + timeout + " ms, remaining events are " + joiner.join(nextExpectedEvent));
}
+
return completed;
}
@@ -323,21 +336,19 @@ public class TestApiListener {
if (ev == received) {
it.remove();
foundIt = true;
- if (!nonExpectedMode) {
- log.debug("Found expected event {}. Yeah!", received);
- } else {
- log.error("Found non expected event {}. Boohh! ", received);
- }
+ log.debug("Found expected event {}. Yeah!", received);
break;
}
}
- if (!foundIt && !nonExpectedMode) {
- final Joiner joiner = Joiner.on(" ");
- log.error("Received unexpected event " + received + "; remaining expected events [" + joiner.join(nextExpectedEvent) + "]");
- if (testStatus != null) {
- testStatus.failed("TestApiListener [ApiListenerStatus]: Received unexpected event " + received + "; remaining expected events [" + joiner.join(nextExpectedEvent) + "]");
- }
+ if (!foundIt) {
+ log.error("Received unexpected event " + received + "; remaining expected events [" + SPACE_JOINER.join(nextExpectedEvent) + "]");
+ failed("TestApiListener [ApiListenerStatus]: Received unexpected event " + received + "; remaining expected events [" + SPACE_JOINER.join(nextExpectedEvent) + "]");
}
}
}
+
+ private void failed(final String msg) {
+ this.isListenerFailed = true;
+ this.listenerFailedMsg = msg;
+ }
}
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java
index 1ac9403..12cbf65 100644
--- a/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestSuiteWithEmbeddedDB.java
@@ -41,20 +41,20 @@ public class GuicyKillbillTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
@Inject
protected IDBI dbi;
- @BeforeSuite(groups = {"slow", "mysql"})
+ @BeforeSuite(groups = "slow")
public void beforeSuite() throws Exception {
DBTestingHelper.start();
}
- @BeforeMethod(groups = {"slow", "mysql"})
+ @BeforeMethod(groups = "slow")
public void beforeMethod() throws Exception {
try {
DBTestingHelper.get().cleanupAllTables();
- } catch (Exception ignored) {
+ } catch (final Exception ignored) {
}
}
- @AfterSuite(groups = {"slow", "mysql"})
+ @AfterSuite(groups = "slow")
public void afterSuite() throws Exception {
if (hasFailed()) {
log.error("**********************************************************************************************");
@@ -66,7 +66,7 @@ public class GuicyKillbillTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
try {
DBTestingHelper.get().stop();
- } catch (Exception ignored) {
+ } catch (final Exception ignored) {
}
}
}
diff --git a/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java b/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java
index 43810bd..4575117 100644
--- a/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java
+++ b/util/src/test/java/com/ning/billing/GuicyKillbillTestWithEmbeddedDBModule.java
@@ -37,7 +37,7 @@ public class GuicyKillbillTestWithEmbeddedDBModule extends GuicyKillbillTestModu
try {
bind(DataSource.class).toInstance(DBTestingHelper.get().getDataSource());
bind(IDBI.class).toInstance(DBTestingHelper.getDBI());
- } catch (IOException e) {
+ } catch (final IOException e) {
Assert.fail(e.toString());
}
}
diff --git a/util/src/test/java/com/ning/billing/KillbillTestSuiteWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/KillbillTestSuiteWithEmbeddedDB.java
index 0ac8b85..c0d79e9 100644
--- a/util/src/test/java/com/ning/billing/KillbillTestSuiteWithEmbeddedDB.java
+++ b/util/src/test/java/com/ning/billing/KillbillTestSuiteWithEmbeddedDB.java
@@ -31,20 +31,20 @@ public class KillbillTestSuiteWithEmbeddedDB extends KillbillTestSuite {
private static final Logger log = LoggerFactory.getLogger(KillbillTestSuiteWithEmbeddedDB.class);
- @BeforeSuite(groups = {"slow", "mysql"})
+ @BeforeSuite(groups = "slow")
public void startMysqlBeforeTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException {
DBTestingHelper.start();
}
- @BeforeMethod(groups = {"slow", "mysql"})
+ @BeforeMethod(groups = "slow")
public void cleanupTablesBetweenMethods() {
try {
DBTestingHelper.get().cleanupAllTables();
- } catch (Exception ignored) {
+ } catch (final Exception ignored) {
}
}
- @AfterSuite(groups = {"slow", "mysql"})
+ @AfterSuite(groups = "slow")
public void shutdownMysqlAfterTestSuite() throws IOException, ClassNotFoundException, SQLException, URISyntaxException {
if (hasFailed()) {
log.error("**********************************************************************************************");
@@ -56,7 +56,7 @@ public class KillbillTestSuiteWithEmbeddedDB extends KillbillTestSuite {
try {
DBTestingHelper.get().stop();
- } catch (Exception ignored) {
+ } catch (final Exception ignored) {
}
}
}
diff --git a/util/src/test/java/com/ning/billing/util/cache/TestCache.java b/util/src/test/java/com/ning/billing/util/cache/TestCache.java
index f1c4570..dba32b3 100644
--- a/util/src/test/java/com/ning/billing/util/cache/TestCache.java
+++ b/util/src/test/java/com/ning/billing/util/cache/TestCache.java
@@ -33,8 +33,7 @@ import com.ning.billing.util.tag.dao.TagSqlDao;
public class TestCache extends UtilTestSuiteWithEmbeddedDB {
- private EntitySqlDaoTransactionalJdbiWrapper transactionalSqlDao;
-
+ private EntitySqlDaoTransactionalJdbiWrapper transactionalSqlDao;
private void insertTag(final TagModelDao modelDao) {
transactionalSqlDao.execute(new EntitySqlDaoTransactionWrapper<Void>() {
@@ -60,7 +59,7 @@ public class TestCache extends UtilTestSuiteWithEmbeddedDB {
return cache != null ? cache.size() : 0;
}
- private Long retrieveRecordIdFromCache(UUID tagId) {
+ private Long retrieveRecordIdFromCache(final UUID tagId) {
final CacheController<Object, Object> cache = controlCacheDispatcher.getCacheController(CacheType.RECORD_ID);
Object result = null;
if (cache != null) {
@@ -72,7 +71,6 @@ public class TestCache extends UtilTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
public void testCacheRecordId() throws Exception {
-
this.transactionalSqlDao = new EntitySqlDaoTransactionalJdbiWrapper(dbi, clock, controlCacheDispatcher, nonEntityDao);
final TagModelDao tag = new TagModelDao(clock.getUTCNow(), UUID.randomUUID(), UUID.randomUUID(), ObjectType.TAG);
diff --git a/util/src/test/java/com/ning/billing/util/dao/TestNonEntityDao.java b/util/src/test/java/com/ning/billing/util/dao/TestNonEntityDao.java
index efbe509..4bad609 100644
--- a/util/src/test/java/com/ning/billing/util/dao/TestNonEntityDao.java
+++ b/util/src/test/java/com/ning/billing/util/dao/TestNonEntityDao.java
@@ -33,20 +33,15 @@ public class TestNonEntityDao extends UtilTestSuiteWithEmbeddedDB {
final Long tenantRecordId = 123123123L;
final UUID tenantId = UUID.fromString("121c59d4-0458-4038-a683-698c9a121c12");
-
final UUID accountId = UUID.fromString("a01c59d4-0458-4038-a683-698c9a121c69");
final Long accountRecordId = 333333L;
- final UUID accountHistoryId = UUID.fromString("2b1c59d4-0458-4038-a683-698c9a121c78");
- final Long accountHistoryRecordId = 777777L;
-
final UUID tagDefinitionId = UUID.fromString("e01c59d4-0458-4038-a683-698c9a121c34");
final Long tagDefinitionRecordId = 44444444L;
final UUID tagId = UUID.fromString("123c59d4-0458-4038-a683-698c9a121456");
final Long tagRecordId = 55555555L;
-
@Test(groups = "slow")
public void testRetrieveRecordIdFromObject() throws IOException {
insertAccount();
@@ -63,7 +58,6 @@ public class TestNonEntityDao extends UtilTestSuiteWithEmbeddedDB {
Assert.assertEquals(resultAccountRecordId, accountRecordId);
}
-
@Test(groups = "slow")
public void testRetrieveAccountRecordIdFromTagDefinitionObject() throws IOException {
insertTagDefinition();
@@ -96,6 +90,7 @@ public class TestNonEntityDao extends UtilTestSuiteWithEmbeddedDB {
final Long resultTenantRecordId = nonEntityDao.retrieveTenantRecordIdFromObject(tenantId, ObjectType.TENANT, null);
Assert.assertEquals(resultTenantRecordId, tenantRecordId);
}
+
private void insertAccount() throws IOException {
dbi.withHandle(new HandleCallback<Void>() {
@Override
@@ -120,7 +115,6 @@ public class TestNonEntityDao extends UtilTestSuiteWithEmbeddedDB {
});
}
-
private void insertTagDefinition() throws IOException {
dbi.withHandle(new HandleCallback<Void>() {
@Override
diff --git a/util/src/test/java/com/ning/billing/util/dao/TestPagination.java b/util/src/test/java/com/ning/billing/util/dao/TestPagination.java
index 01b7b8a..69dcc4d 100644
--- a/util/src/test/java/com/ning/billing/util/dao/TestPagination.java
+++ b/util/src/test/java/com/ning/billing/util/dao/TestPagination.java
@@ -44,12 +44,12 @@ public class TestPagination extends UtilTestSuiteWithEmbeddedDB {
// Tests via SQL dao directly
Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.getAll(internalCallContext)).size(), 10);
- Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 100L, "recordId", internalCallContext)).size(), 10);
- Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 100L, "recordId", internalCallContext)).size(), 5);
- Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 10L, "recordId", internalCallContext)).size(), 5);
- Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 5L, "recordId", internalCallContext)).size(), 5);
+ Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 100L, "record_id", internalCallContext)).size(), 10);
+ Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 100L, "record_id", internalCallContext)).size(), 5);
+ Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(5L, 10L, "record_id", internalCallContext)).size(), 5);
+ Assert.assertEquals(ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, 5L, "record_id", internalCallContext)).size(), 5);
for (int i = 0; i < 10; i++) {
- final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, (long) i, "recordId", internalCallContext));
+ final List<TagDefinitionModelDao> tagDefinitions = ImmutableList.<TagDefinitionModelDao>copyOf(tagDefinitionSqlDao.get(0L, (long) i, "record_id", internalCallContext));
Assert.assertEquals(tagDefinitions.size(), i);
for (int j = 0; j < tagDefinitions.size(); j++) {
diff --git a/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java b/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
index df148e1..7acbe91 100644
--- a/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
+++ b/util/src/test/java/com/ning/billing/util/dao/TestStringTemplateInheritance.java
@@ -114,7 +114,7 @@ public class TestStringTemplateInheritance extends UtilTestSuiteNoDB {
"where t.tenant_record_id = :tenantRecordId\n" +
"order by t.record_id ASC\n" +
";");
- Assert.assertEquals(kombucha.getInstanceOf("get", ImmutableMap.<String, String>of("orderBy", "recordId", "offset", "3", "rowCount", "12")).toString(), "select SQL_CALC_FOUND_ROWS\n" +
+ Assert.assertEquals(kombucha.getInstanceOf("get", ImmutableMap.<String, String>of("orderBy", "record_id", "offset", "3", "rowCount", "12")).toString(), "select\n" +
" t.record_id\n" +
", t.id\n" +
", t.tea\n" +
@@ -124,7 +124,7 @@ public class TestStringTemplateInheritance extends UtilTestSuiteNoDB {
", t.tenant_record_id\n" +
"from kombucha t\n" +
"where t.tenant_record_id = :tenantRecordId\n" +
- "order by :orderBy\n" +
+ "order by t.record_id\n" +
"limit :offset, :rowCount\n" +
";");
Assert.assertEquals(kombucha.getInstanceOf("test").toString(), "select\n" +
diff --git a/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java b/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
index f6d695a..2c2f5de 100644
--- a/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
+++ b/util/src/test/java/com/ning/billing/util/globallocker/TestMysqlGlobalLocker.java
@@ -34,11 +34,10 @@ import com.ning.billing.util.UtilTestSuiteWithEmbeddedDB;
public class TestMysqlGlobalLocker extends UtilTestSuiteWithEmbeddedDB {
// Used as a manual test to validate the simple DAO by stepping through that locking is done and release correctly
- @Test(groups = "mysql")
+ @Test(groups = "slow")
public void testSimpleLocking() throws IOException, LockFailedException {
final String lockName = UUID.randomUUID().toString();
- final GlobalLocker locker = new MySqlGlobalLocker(dataSource);
final GlobalLock lock = locker.lockWithNumberOfTries(LockerType.ACCOUNT_FOR_INVOICE_PAYMENTS.toString(), lockName, 3);
dbi.inTransaction(new TransactionCallback<Void>() {
diff --git a/util/src/test/java/com/ning/billing/util/glue/TestUtilModuleWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
index 71e6fd5..5ed326c 100644
--- a/util/src/test/java/com/ning/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
+++ b/util/src/test/java/com/ning/billing/util/glue/TestUtilModuleWithEmbeddedDB.java
@@ -18,7 +18,10 @@ package com.ning.billing.util.glue;
import org.skife.config.ConfigSource;
+import com.ning.billing.DBTestingHelper;
import com.ning.billing.GuicyKillbillTestWithEmbeddedDBModule;
+import com.ning.billing.api.TestApiListener;
+import com.ning.billing.util.globallocker.TestGlobalLockerModule;
public class TestUtilModuleWithEmbeddedDB extends TestUtilModule {
@@ -38,6 +41,8 @@ public class TestUtilModuleWithEmbeddedDB extends TestUtilModule {
install(new BusModule(configSource));
install(new NotificationQueueModule(configSource));
install(new NonEntityDaoModule());
- install(new GlobalLockerModule());
+ install(new TestGlobalLockerModule(DBTestingHelper.get()));
+
+ bind(TestApiListener.class).asEagerSingleton();
}
}
diff --git a/util/src/test/java/com/ning/billing/util/security/shiro/dao/TestJDBCSessionDao.java b/util/src/test/java/com/ning/billing/util/security/shiro/dao/TestJDBCSessionDao.java
index 1b13ce7..c4f8d3b 100644
--- a/util/src/test/java/com/ning/billing/util/security/shiro/dao/TestJDBCSessionDao.java
+++ b/util/src/test/java/com/ning/billing/util/security/shiro/dao/TestJDBCSessionDao.java
@@ -33,7 +33,7 @@ public class TestJDBCSessionDao extends UtilTestSuiteWithEmbeddedDB {
@Test(groups = "slow")
public void testCRUD() throws Exception {
// Note! We are testing the do* methods here to bypass the caching layer
- final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao((DBI) dbi);
+ final JDBCSessionDao jdbcSessionDao = new JDBCSessionDao(dbi);
// Retrieve
final SimpleSession session = createSession();
diff --git a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
index 6d2fc68..4fd30cf 100644
--- a/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
+++ b/util/src/test/java/com/ning/billing/util/tag/TestTagStore.java
@@ -33,11 +33,9 @@ import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
public class TestTagStore extends UtilTestSuiteWithEmbeddedDB {
-
@Test(groups = "slow")
public void testTagCreationAndRetrieval() throws TagApiException, TagDefinitionApiException {
final UUID accountId = UUID.randomUUID();
diff --git a/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java b/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java
index ad1e535..28d45a0 100644
--- a/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java
+++ b/util/src/test/java/com/ning/billing/util/UtilTestSuiteWithEmbeddedDB.java
@@ -21,15 +21,14 @@ import javax.inject.Inject;
import org.skife.jdbi.v2.IDBI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import com.ning.billing.GuicyKillbillTestSuiteWithEmbeddedDB;
import com.ning.billing.api.TestApiListener;
-import com.ning.billing.api.TestListenerStatus;
import com.ning.billing.bus.api.PersistentBus;
+import com.ning.billing.commons.locker.GlobalLocker;
import com.ning.billing.notificationq.api.NotificationQueueService;
import com.ning.billing.util.audit.dao.AuditDao;
import com.ning.billing.util.cache.CacheControllerDispatcher;
@@ -46,14 +45,10 @@ import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-import static org.testng.Assert.assertTrue;
-
-public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWithEmbeddedDB implements TestListenerStatus {
+public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuiteWithEmbeddedDB {
private static final Logger log = LoggerFactory.getLogger(UtilTestSuiteWithEmbeddedDB.class);
- protected static final long DELAY = 10000;
-
@Inject
protected PersistentBus eventBus;
@Inject
@@ -77,19 +72,16 @@ public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
@Inject
protected AuditDao auditDao;
@Inject
+ protected GlobalLocker locker;
+ @Inject
protected IDBI idbi;
-
+ @Inject
protected TestApiListener eventsListener;
- private boolean isListenerFailed;
- private String listenerFailedMsg;
-
@BeforeClass(groups = "slow")
public void beforeClass() throws Exception {
final Injector g = Guice.createInjector(Stage.PRODUCTION, new TestUtilModuleWithEmbeddedDB(configSource));
g.injectMembers(this);
-
- eventsListener = new TestApiListener(this, idbi);
}
@Override
@@ -97,7 +89,6 @@ public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
public void beforeMethod() throws Exception {
super.beforeMethod();
- resetTestListenerStatus();
eventsListener.reset();
eventBus.start();
@@ -118,23 +109,7 @@ public abstract class UtilTestSuiteWithEmbeddedDB extends GuicyKillbillTestSuite
eventBus.stop();
}
- @Override
- public void failed(final String msg) {
- isListenerFailed = true;
- listenerFailedMsg = msg;
- }
-
- @Override
- public void resetTestListenerStatus() {
- isListenerFailed = false;
- listenerFailedMsg = null;
- }
-
protected void assertListenerStatus() {
- assertTrue(eventsListener.isCompleted(DELAY));
- if (isListenerFailed) {
- log.error(listenerFailedMsg);
- Assert.fail(listenerFailedMsg);
- }
+ eventsListener.assertListenerStatus();
}
}