public T dispatchWithAccountLock(final Callable<T> task) throws PaymentApiException, TimeoutException { return dispatchWithAccountLockAndTimeout(task, timeoutSeconds, DEEFAULT_PLUGIN_TIMEOUT_UNIT); }
@Inject public PaymentProcessor(final OSGIServiceRegistration<PaymentPluginApi> pluginRegistry, final PaymentMethodProcessor paymentMethodProcessor, final AccountInternalApi accountUserApi, final InvoiceInternalApi invoiceApi, final TagInternalApi tagUserApi, final FailedPaymentRetryServiceScheduler failedPaymentRetryService, final PluginFailureRetryServiceScheduler pluginFailureRetryService, final AutoPayRetryServiceScheduler autoPayoffRetryService, final PaymentDao paymentDao, final NonEntityDao nonEntityDao, final PersistentBus eventBus, final Clock clock, final GlobalLocker locker, final PaymentConfig paymentConfig, @Named(PLUGIN_EXECUTOR_NAMED) final ExecutorService executor) { super(pluginRegistry, accountUserApi, eventBus, paymentDao, nonEntityDao, tagUserApi, locker, executor, invoiceApi); this.paymentMethodProcessor = paymentMethodProcessor; this.failedPaymentRetryService = failedPaymentRetryService; this.pluginFailureRetryService = pluginFailureRetryService; this.autoPayoffRetryService = autoPayoffRetryService; this.clock = clock; this.paymentConfig = paymentConfig; final long paymentPluginTimeoutSec = TimeUnit.SECONDS.convert(paymentConfig.getPaymentPluginTimeout().getPeriod(), paymentConfig.getPaymentPluginTimeout().getUnit()); this.paymentPluginDispatcher = new PluginDispatcher<Payment>(paymentPluginTimeoutSec, executor); this.voidPluginDispatcher = new PluginDispatcher<Void>(paymentPluginTimeoutSec, executor); }
public void process_AUTO_PAY_OFF_removal(final Account account, final InternalCallContext context) throws PaymentApiException { voidPluginDispatcher.dispatchWithAccountLock(new CallableWithAccountLock<Void>(locker, account.getExternalKey(), new WithAccountLockCallback<Void>() {
@Test(groups = "fast") public void testDispatchWithPaymentApiException() throws TimeoutException, PaymentApiException { boolean gotIt = false; try { voidPluginDispatcher.dispatchWithAccountLockAndTimeout(new Callable<Void>() { @Override public Void call() throws Exception { throw new PaymentApiException(ErrorCode.PAYMENT_ADD_PAYMENT_METHOD, "foo", "foo"); } }, 100, TimeUnit.MILLISECONDS); Assert.fail("Failed : should have had Timeout exception"); } catch (TimeoutException e) { Assert.fail("Failed : should have had PaymentApiException exception"); } catch (PaymentApiException e) { gotIt = true; } Assert.assertTrue(gotIt); }
final PaymentPluginApi plugin = getPaymentProviderPlugin(account, context); voidPluginDispatcher.dispatchWithAccountLock(new CallableWithAccountLock<Void>(locker, account.getExternalKey(), new WithAccountLockCallback<Void>() {
@Test(groups = "fast") public void testDispatchWithRuntimeExceptionWrappedInPaymentApiException() throws TimeoutException, PaymentApiException { boolean gotIt = false; try { voidPluginDispatcher.dispatchWithAccountLockAndTimeout(new Callable<Void>() { @Override public Void call() throws Exception { throw new RuntimeException("whatever"); } }, 100, TimeUnit.MILLISECONDS); Assert.fail("Failed : should have had Timeout exception"); } catch (TimeoutException e) { Assert.fail("Failed : should have had RuntimeException exception"); } catch (PaymentApiException e) { gotIt = true; } catch (RuntimeException e) { } Assert.assertTrue(gotIt); } }
return paymentPluginDispatcher.dispatchWithAccountLock(new CallableWithAccountLock<Payment>(locker, account.getExternalKey(), new WithAccountLockCallback<Payment>() {
@Test(groups = "fast") public void testDispatchWithTimeout() throws TimeoutException, PaymentApiException { boolean gotIt = false; try { voidPluginDispatcher.dispatchWithAccountLockAndTimeout(new Callable<Void>() { @Override public Void call() throws Exception { Thread.sleep(1000); return null; } }, 100, TimeUnit.MILLISECONDS); Assert.fail("Failed : should have had Timeout exception"); } catch (TimeoutException e) { gotIt = true; } catch (PaymentApiException e) { Assert.fail("Failed : should have had Timeout exception"); } Assert.assertTrue(gotIt); }