public T dispatchWithAccountLock(final Callable<T> task) throws PaymentApiException, TimeoutException { return dispatchWithAccountLockAndTimeout(task, timeoutSeconds, DEEFAULT_PLUGIN_TIMEOUT_UNIT); }
@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); }
@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); }
@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); } }