killbill-aplcache

server: iteration on tests stability, pass 5 Signed-off-by:

5/3/2018 8:55:07 AM

Details

diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
index ead1a09..732e860 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/KillbillClient.java
@@ -305,18 +305,4 @@ public abstract class KillbillClient extends GuicyKillbillTestSuiteWithEmbeddedD
         return new Account(accountId, name, length, externalKey, email, null, currency, parentAccountId, isPaymentDelegatedToParent, null, null, timeZone,
                            address1, address2, postalCode, company, city, state, country, locale, phone, notes, false, false, null, null);
     }
-
-    /**
-     * We could implement a ClockResource in jaxrs with the ability to sync on user token
-     * but until we have a strong need for it, this is in the TODO list...
-     */
-    protected void crappyWaitForLackOfProperSynchonization() throws Exception {
-        crappyWaitForLackOfProperSynchonization(5000);
-    }
-
-
-    private void crappyWaitForLackOfProperSynchonization(int sleepValueMSec) throws Exception {
-        Thread.sleep(sleepValueMSec);
-    }
-
 }
diff --git a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
index 9576d36..0c8124e 100644
--- a/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
+++ b/profiles/killbill/src/test/java/org/killbill/billing/jaxrs/TestOverdue.java
@@ -88,17 +88,19 @@ public class TestOverdue extends TestJaxrsBase {
         }).reverse().sortedCopy(invoicesForAccount);
         for (final Invoice invoice : mostRecentInvoiceFirst) {
             if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0) {
-
                 final InvoicePayment invoicePayment = new InvoicePayment();
                 invoicePayment.setPurchasedAmount(invoice.getAmount());
                 invoicePayment.setAccountId(accountJson.getAccountId());
                 invoicePayment.setTargetInvoiceId(invoice.getInvoiceId());
+                callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
                 killBillClient.createInvoicePayment(invoicePayment, true, requestOptions);
+                callbackServlet.assertListenerStatus();
             }
         }
 
         // Wait a bit for overdue to pick up the payment events...
-        crappyWaitForLackOfProperSynchonization();
+        callbackServlet.pushExpectedEvents(ExtBusEventType.TAG_DELETION, ExtBusEventType.BLOCKING_STATE, ExtBusEventType.OVERDUE_CHANGE);
+        callbackServlet.assertListenerStatus();
 
         // Verify we're in clear state
         Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
@@ -173,8 +175,14 @@ public class TestOverdue extends TestJaxrsBase {
 
         // move a month a wait for invoicing
         // No payment will be triggered as the account doesn't have a payment method
+        callbackServlet.pushExpectedEvents(ExtBusEventType.SUBSCRIPTION_PHASE,
+                                           ExtBusEventType.INVOICE_CREATION,
+                                           ExtBusEventType.INVOICE_PAYMENT_FAILED,
+                                           ExtBusEventType.SUBSCRIPTION_PHASE,
+                                           ExtBusEventType.INVOICE_CREATION,
+                                           ExtBusEventType.INVOICE_PAYMENT_FAILED);
         clock.addMonths(1);
-        crappyWaitForLackOfProperSynchonization();
+        callbackServlet.assertListenerStatus();
 
         // Get the invoices
         final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
@@ -189,8 +197,14 @@ public class TestOverdue extends TestJaxrsBase {
         Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
         Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
 
+        callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_CREATION,
+                                           ExtBusEventType.INVOICE_CREATION,
+                                           ExtBusEventType.INVOICE_PAYMENT_FAILED,
+                                           ExtBusEventType.INVOICE_PAYMENT_FAILED,
+                                           ExtBusEventType.BLOCKING_STATE,
+                                           ExtBusEventType.OVERDUE_CHANGE);
         clock.addDays(30);
-        crappyWaitForLackOfProperSynchonization();
+        callbackServlet.assertListenerStatus();
 
         // This account is not expected to move to OD1 state because it does not match with exclusion controlTag defined
         Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());