killbill-aplcache
Changes
payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentAutomatonRunner.java 6(+3 -3)
payment/src/main/java/org/killbill/billing/payment/core/sm/PluginControlledDirectPaymentAutomatonRunner.java 7(+4 -3)
Details
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/PaymentGatewayProcessor.java b/payment/src/main/java/org/killbill/billing/payment/core/PaymentGatewayProcessor.java
index 250ec49..9fdf44a 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/PaymentGatewayProcessor.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/PaymentGatewayProcessor.java
@@ -95,7 +95,7 @@ public class PaymentGatewayProcessor extends ProcessorBase {
try {
return plugin.buildFormDescriptor(account.getId(), customFields, properties, callContext);
} catch (final RuntimeException e) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} catch (final PaymentPluginApiException e) {
throw new PaymentApiException(ErrorCode.PAYMENT_PLUGIN_EXCEPTION, e.getErrorMessage());
}
@@ -128,7 +128,7 @@ public class PaymentGatewayProcessor extends ProcessorBase {
throw new PaymentApiException(ErrorCode.PAYMENT_PLUGIN_TIMEOUT, accountId, null);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
- throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} catch (final ExecutionException e) {
if (e.getCause() instanceof PaymentApiException) {
throw (PaymentApiException) e.getCause();
@@ -137,7 +137,7 @@ public class PaymentGatewayProcessor extends ProcessorBase {
log.error(String.format(format), e);
throw new PaymentApiException(ErrorCode.PAYMENT_INTERNAL_ERROR, format);
} else {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
}
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/PaymentMethodProcessor.java b/payment/src/main/java/org/killbill/billing/payment/core/PaymentMethodProcessor.java
index f1913f4..f190ce2 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/PaymentMethodProcessor.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/PaymentMethodProcessor.java
@@ -61,6 +61,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
+import com.google.common.base.Objects;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableList;
import com.google.inject.Inject;
@@ -121,7 +122,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
}
});
} catch (Exception e) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
@@ -340,7 +341,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
}
});
} catch (Exception e) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
@@ -370,7 +371,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
}
});
} catch (Exception e) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
@@ -464,7 +465,7 @@ public class PaymentMethodProcessor extends ProcessorBase {
}
});
} catch (Exception e) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR);
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentAutomatonRunner.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentAutomatonRunner.java
index 4934bba..0cccbef 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentAutomatonRunner.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentAutomatonRunner.java
@@ -258,14 +258,14 @@ public class DirectPaymentAutomatonRunner {
initialState.runOperation(operation, operationCallback, enteringStateCallback, leavingStateCallback);
} catch (final MissingEntryException e) {
- throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} catch (final OperationException e) {
if (e.getCause() == null) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} else if (e.getCause() instanceof PaymentApiException) {
throw (PaymentApiException) e.getCause();
} else {
- throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
}
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentOperation.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentOperation.java
index 9187437..bf999b3 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentOperation.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/DirectPaymentOperation.java
@@ -31,6 +31,7 @@ import org.killbill.billing.payment.plugin.api.PaymentPluginApi;
import org.killbill.billing.payment.plugin.api.PaymentPluginApiException;
import org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin;
import org.killbill.commons.locker.GlobalLocker;
+import org.killbill.commons.locker.LockFailedException;
import com.google.common.base.Objects;
@@ -58,10 +59,14 @@ public abstract class DirectPaymentOperation extends OperationCallbackBase imple
@Override
protected OperationException rewrapExecutionException(final DirectPaymentStateContext directPaymentStateContext, final ExecutionException e) {
+ final Throwable realException = Objects.firstNonNull(e.getCause(), e);
if (e.getCause() instanceof PaymentPluginApiException) {
- final Throwable realException = Objects.firstNonNull(e.getCause(), e);
logger.warn("Unsuccessful plugin call for account {}", directPaymentStateContext.getAccount().getExternalKey(), realException);
return new OperationException(realException, OperationResult.FAILURE);
+ } else if (e.getCause() instanceof LockFailedException) {
+ final String format = String.format("Failed to lock account %s", directPaymentStateContext.getAccount().getExternalKey());
+ logger.error(String.format(format), e);
+ return new OperationException(realException, OperationResult.FAILURE);
} else /* if (e instanceof RuntimeException) */ {
logger.warn("Plugin call threw an exception for account {}", directPaymentStateContext.getAccount().getExternalKey(), e);
return new OperationException(e, OperationResult.EXCEPTION);
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginControlledDirectPaymentAutomatonRunner.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginControlledDirectPaymentAutomatonRunner.java
index 090431b..f3af2a9 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginControlledDirectPaymentAutomatonRunner.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/PluginControlledDirectPaymentAutomatonRunner.java
@@ -55,6 +55,7 @@ import org.killbill.clock.Clock;
import org.killbill.commons.locker.GlobalLocker;
import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Objects;
import static org.killbill.billing.payment.glue.PaymentModule.PLUGIN_EXECUTOR_NAMED;
import static org.killbill.billing.payment.glue.PaymentModule.RETRYABLE_NAMED;
@@ -131,14 +132,14 @@ public class PluginControlledDirectPaymentAutomatonRunner extends DirectPaymentA
state.runOperation(retryOperation, callback, enteringStateCallback, leavingStateCallback);
} catch (MissingEntryException e) {
- throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} catch (OperationException e) {
if (e.getCause() == null) {
- throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e, ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
} else if (e.getCause() instanceof PaymentApiException) {
throw (PaymentApiException) e.getCause();
} else {
- throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, e.getMessage());
+ throw new PaymentApiException(e.getCause(), ErrorCode.PAYMENT_INTERNAL_ERROR, Objects.firstNonNull(e.getMessage(), ""));
}
}
return directPaymentStateContext.getResult();
diff --git a/payment/src/main/java/org/killbill/billing/payment/core/sm/RetryOperationCallback.java b/payment/src/main/java/org/killbill/billing/payment/core/sm/RetryOperationCallback.java
index 3330cd6..25d8c92 100644
--- a/payment/src/main/java/org/killbill/billing/payment/core/sm/RetryOperationCallback.java
+++ b/payment/src/main/java/org/killbill/billing/payment/core/sm/RetryOperationCallback.java
@@ -47,6 +47,7 @@ import org.killbill.billing.retry.plugin.api.PaymentControlPluginApi;
import org.killbill.billing.retry.plugin.api.PriorPaymentControlResult;
import org.killbill.billing.util.callcontext.CallContext;
import org.killbill.commons.locker.GlobalLocker;
+import org.killbill.commons.locker.LockFailedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -150,6 +151,10 @@ public abstract class RetryOperationCallback extends OperationCallbackBase imple
protected OperationException rewrapExecutionException(final DirectPaymentStateContext directPaymentStateContext, final ExecutionException e) {
if (e.getCause() instanceof OperationException) {
return (OperationException) e.getCause();
+ } else if (e.getCause() instanceof LockFailedException) {
+ final String format = String.format("Failed to lock account %s", directPaymentStateContext.getAccount().getExternalKey());
+ logger.error(String.format(format), e);
+ return new OperationException(e, getOperationResultOnException(directPaymentStateContext));
} else /* most probably RuntimeException */ {
logger.warn("RetryOperationCallback failed for account {}", directPaymentStateContext.getAccount().getExternalKey(), e);
return new OperationException(e, getOperationResultOnException(directPaymentStateContext));
diff --git a/payment/src/test/java/org/killbill/billing/payment/core/sm/TestRetryableDirectPayment.java b/payment/src/test/java/org/killbill/billing/payment/core/sm/TestRetryableDirectPayment.java
index b10934d..13874a0 100644
--- a/payment/src/test/java/org/killbill/billing/payment/core/sm/TestRetryableDirectPayment.java
+++ b/payment/src/test/java/org/killbill/billing/payment/core/sm/TestRetryableDirectPayment.java
@@ -132,6 +132,13 @@ public class TestRetryableDirectPayment extends PaymentTestSuiteNoDB {
return MockPaymentControlProviderPlugin.PLUGIN_NAME;
}
}, mockRetryProviderPlugin);
+ }
+
+ @BeforeMethod(groups = "fast")
+ public void beforeMethod() throws Exception {
+ super.beforeMethod();
+ ((MockPaymentDao) paymentDao).reset();
+ this.utcNow = clock.getUTCNow();
runner = new MockRetryableDirectPaymentAutomatonRunner(
stateMachineConfig,
@@ -185,13 +192,6 @@ public class TestRetryableDirectPayment extends PaymentTestSuiteNoDB {
}
- @BeforeMethod(groups = "fast")
- public void beforeMethod() throws Exception {
- super.beforeMethod();
- ((MockPaymentDao) paymentDao).reset();
- this.utcNow = clock.getUTCNow();
- }
-
@Test(groups = "fast")
public void testInitToAborted() throws PaymentApiException {
@@ -400,7 +400,7 @@ public class TestRetryableDirectPayment extends PaymentTestSuiteNoDB {
} catch (PaymentApiException e) {
final PaymentAttemptModelDao pa = ((MockPaymentDao) paymentDao).getPaymentAttemptByExternalKey(directPaymentTransactionExternalKey, internalCallContext);
assertEquals(pa.getTransactionExternalKey(), directPaymentTransactionExternalKey);
- assertEquals(pa.getStateName(), "ABORTED");
+ assertEquals(pa.getStateName(), "RETRIED");
assertEquals(pa.getOperationName(), "AUTHORIZE");
}
}
@@ -667,7 +667,7 @@ public class TestRetryableDirectPayment extends PaymentTestSuiteNoDB {
final PaymentAttemptModelDao pa = ((MockPaymentDao) paymentDao).getPaymentAttemptByExternalKey(directPaymentTransactionExternalKey, internalCallContext);
assertEquals(pa.getTransactionExternalKey(), directPaymentTransactionExternalKey);
- assertEquals(pa.getStateName(), "RETRIED");
+ assertEquals(pa.getStateName(), "ABORTED");
assertEquals(pa.getOperationName(), "AUTHORIZE");
} finally {
diff --git a/payment/src/test/java/org/killbill/billing/payment/provider/MockPaymentProviderPlugin.java b/payment/src/test/java/org/killbill/billing/payment/provider/MockPaymentProviderPlugin.java
index 18c3649..26c7e29 100644
--- a/payment/src/test/java/org/killbill/billing/payment/provider/MockPaymentProviderPlugin.java
+++ b/payment/src/test/java/org/killbill/billing/payment/provider/MockPaymentProviderPlugin.java
@@ -181,6 +181,9 @@ public class MockPaymentProviderPlugin implements NoOpPaymentPluginApi {
makeNextInvoiceFailWithException.set(false);
makeAllInvoicesFailWithError.set(false);
makeNextInvoiceFailWithError.set(false);
+ paymentMethods.clear();
+ payments.clear();
+ paymentMethodsInfo.clear();
}
@Override
diff --git a/payment/src/test/java/org/killbill/billing/payment/TestRetryService.java b/payment/src/test/java/org/killbill/billing/payment/TestRetryService.java
index 0b5b7ee..08d3cd6 100644
--- a/payment/src/test/java/org/killbill/billing/payment/TestRetryService.java
+++ b/payment/src/test/java/org/killbill/billing/payment/TestRetryService.java
@@ -83,7 +83,7 @@ public class TestRetryService extends PaymentTestSuiteNoDB {
}
@Test(groups = "fast")
- public void testFailedPpluginWithLastRetrySuccess() throws Exception {
+ public void testFailedPluginWithLastRetrySuccess() throws Exception {
testSchedulesRetryInternal(paymentConfig.getPluginFailureRetryMaxAttempts(), true, FailureType.PLUGIN_EXCEPTION);
}