use of org.killbill.billing.payment.core.sm.payments.PaymentOperation in project killbill by killbill.
the class TestPluginOperation method testOperationThrowsRuntimeException.
@Test(groups = "fast")
public void testOperationThrowsRuntimeException() throws Exception {
final CallbackTest callback = new CallbackTest(new NullPointerException("Expected for the test"));
final PaymentOperation pluginOperation = getPluginOperation();
try {
pluginOperation.dispatchWithAccountLockAndTimeout(PLUGIN_NAME_PLACEHOLDER, callback);
Assert.fail();
} catch (final OperationException e) {
Assert.assertEquals(e.getOperationResult(), OperationResult.EXCEPTION);
Assert.assertTrue(e.getCause() instanceof PaymentApiException);
Assert.assertTrue(e.getCause().getCause() instanceof NullPointerException);
}
}
use of org.killbill.billing.payment.core.sm.payments.PaymentOperation in project killbill by killbill.
the class TestPluginOperation method testLocking.
private void testLocking() throws Exception {
final Semaphore available = new Semaphore(1, true);
final CallbackTest callback = new CallbackTest(available);
final PaymentOperation pluginOperation = getPluginOperation(true);
// Take the only permit
available.acquire();
// Start the plugin operation in the background (will block)
runPluginOperationInBackground(pluginOperation, callback, false);
Awaitility.await().until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return callback.getStartCount() == 1;
}
});
// The operation should be blocked here because we have the semaphore
Assert.assertEquals(callback.getRunCount(), 0);
// Trying to run the operation again will throw LockFailedException
Awaitility.await().atMost(2 * TIMEOUT, TimeUnit.SECONDS).untilTrue(runPluginOperationInBackground(pluginOperation, callback, true));
Assert.assertEquals(callback.getRunCount(), 0);
// Release the semaphore
available.release();
// Give some time for the operation to run
Awaitility.await().until(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return callback.getRunCount() == 1;
}
});
// Verify the final state
Assert.assertEquals(available.availablePermits(), 1);
}
use of org.killbill.billing.payment.core.sm.payments.PaymentOperation in project killbill by killbill.
the class TestPluginOperation method testOperationThrowsPaymentApiException.
@Test(groups = "fast")
public void testOperationThrowsPaymentApiException() throws Exception {
final CallbackTest callback = new CallbackTest(new PaymentApiException(ErrorCode.__UNKNOWN_ERROR_CODE));
final PaymentOperation pluginOperation = getPluginOperation();
try {
pluginOperation.dispatchWithAccountLockAndTimeout(PLUGIN_NAME_PLACEHOLDER, callback);
Assert.fail();
} catch (final OperationException e) {
Assert.assertEquals(e.getOperationResult(), OperationResult.EXCEPTION);
Assert.assertTrue(e.getCause() instanceof PaymentApiException);
}
}
Aggregations