Search in sources :

Example 1 with TimeSpan

use of org.skife.config.TimeSpan in project killbill by killbill.

the class PushNotificationListener method getNextNotificationTime.

private DateTime getNextNotificationTime(final int attemptNumber, final InternalTenantContext tenantContext) {
    final List<TimeSpan> retries = notificationConfig.getPushNotificationsRetries(tenantContext);
    if (attemptNumber > retries.size()) {
        return null;
    }
    final TimeSpan nextDelay = retries.get(attemptNumber - 1);
    return clock.getUTCNow().plusMillis((int) nextDelay.getMillis());
}
Also used : TimeSpan(org.skife.config.TimeSpan)

Example 2 with TimeSpan

use of org.skife.config.TimeSpan in project killbill by killbill.

the class IncompletePaymentTransactionTask method getNextNotificationTime.

@VisibleForTesting
DateTime getNextNotificationTime(final Integer attemptNumber, final InternalTenantContext tenantContext) {
    final List<TimeSpan> retries = paymentConfig.getIncompleteTransactionsRetries(tenantContext);
    if (attemptNumber > retries.size()) {
        return null;
    }
    final TimeSpan nextDelay = retries.get(attemptNumber - 1);
    return clock.getUTCNow().plusMillis((int) nextDelay.getMillis());
}
Also used : TimeSpan(org.skife.config.TimeSpan) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with TimeSpan

use of org.skife.config.TimeSpan in project killbill by killbill.

the class TestJanitor method testPendingEntriesThatDontMove.

// The test will check that when a PENDING entry stays PENDING, we go through all our retries and eventually give up (no infinite loop of retries)
@Test(groups = "slow")
public void testPendingEntriesThatDontMove() throws Exception {
    final BigDecimal requestedAmount = BigDecimal.TEN;
    final String paymentExternalKey = "haha";
    final String transactionExternalKey = "hoho!";
    testListener.pushExpectedEvent(NextEvent.PAYMENT);
    final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, requestedAmount, account.getCurrency(), paymentExternalKey, transactionExternalKey, ImmutableList.<PluginProperty>of(), callContext);
    testListener.assertListenerStatus();
    // Artificially move the transaction status to PENDING AND update state on the plugin as well
    final List<PaymentTransactionInfoPlugin> paymentTransactions = mockPaymentProviderPlugin.getPaymentInfo(account.getId(), payment.getId(), ImmutableList.<PluginProperty>of(), callContext);
    final PaymentTransactionInfoPlugin oTx = paymentTransactions.remove(0);
    final PaymentTransactionInfoPlugin updatePaymentTransaction = new DefaultNoOpPaymentInfoPlugin(oTx.getKbPaymentId(), oTx.getKbTransactionPaymentId(), oTx.getTransactionType(), oTx.getAmount(), oTx.getCurrency(), oTx.getCreatedDate(), oTx.getCreatedDate(), PaymentPluginStatus.PENDING, null, null);
    paymentTransactions.add(updatePaymentTransaction);
    mockPaymentProviderPlugin.updatePaymentTransactions(payment.getId(), paymentTransactions);
    final String paymentStateName = paymentSMHelper.getPendingStateForTransaction(TransactionType.AUTHORIZE).toString();
    testListener.pushExpectedEvent(NextEvent.PAYMENT);
    paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, paymentStateName, paymentStateName, payment.getTransactions().get(0).getId(), TransactionStatus.PENDING, requestedAmount, account.getCurrency(), "loup", "chat", internalCallContext);
    testListener.assertListenerStatus();
    // 15s,1m,3m,1h,1d,1d,1d,1d,1d
    for (final TimeSpan cur : paymentConfig.getIncompleteTransactionsRetries(internalCallContext)) {
        // Verify there is a notification to retry updating the value
        assertEquals(getPendingNotificationCnt(internalCallContext), 1);
        clock.addDeltaFromReality(cur.getMillis() + 1);
        assertNotificationsCompleted(internalCallContext, 5);
        // We add a sleep here to make sure the notification gets processed. Note that calling assertNotificationsCompleted alone would not work
        // because there is a point in time where the notification queue is empty (showing notification was processed), but the processing of the notification
        // will itself enter a new notification, and so the synchronization is difficult without writing *too much code*.
        Thread.sleep(1000);
        assertNotificationsCompleted(internalCallContext, 5);
        final Payment updatedPayment = paymentApi.getPayment(payment.getId(), false, false, ImmutableList.<PluginProperty>of(), callContext);
        Assert.assertEquals(updatedPayment.getTransactions().get(0).getTransactionStatus(), TransactionStatus.PENDING);
    }
    await().atMost(TIMEOUT, TimeUnit.SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            return getPendingNotificationCnt(internalCallContext) == 0;
        }
    });
}
Also used : TimeSpan(org.skife.config.TimeSpan) Payment(org.killbill.billing.payment.api.Payment) DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) BigDecimal(java.math.BigDecimal) InvoiceApiException(org.killbill.billing.invoice.api.InvoiceApiException) PaymentApiException(org.killbill.billing.payment.api.PaymentApiException) EventBusException(org.killbill.bus.api.PersistentBus.EventBusException) Test(org.testng.annotations.Test)

Aggregations

TimeSpan (org.skife.config.TimeSpan)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BigDecimal (java.math.BigDecimal)1 InvoiceApiException (org.killbill.billing.invoice.api.InvoiceApiException)1 Payment (org.killbill.billing.payment.api.Payment)1 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)1 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)1 DefaultNoOpPaymentInfoPlugin (org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin)1 EventBusException (org.killbill.bus.api.PersistentBus.EventBusException)1 Test (org.testng.annotations.Test)1