use of fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy in project Payara by payara.
the class TestUtils method assertAnnotationInvalid.
public static void assertAnnotationInvalid(String expectedErrorMessage) {
try {
Method annotatedMethod = getAnnotatedMethod();
FaultTolerancePolicy policy = FaultTolerancePolicy.asAnnotated(annotatedMethod.getDeclaringClass(), annotatedMethod);
fail("Annotation should be invalid for " + annotatedMethod + " but got: " + policy);
} catch (FaultToleranceDefinitionException ex) {
String message = ex.getMessage();
int endGeneralPart = message.indexOf(" annotated with ");
assertTrue(endGeneralPart > 0);
assertEquals(expectedErrorMessage, message.substring(endGeneralPart + 16));
}
}
use of fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy in project Payara by payara.
the class FaultToleranceInterceptor method intercept.
public Object intercept(InvocationContext context) throws Exception {
if (!shouldIntercept(context)) {
return context.proceed();
}
context.getContextData().put(PAYARA_FAULT_TOLERANCE_INTERCEPTOR_EXECUTED, Boolean.TRUE);
try {
initialize();
AtomicReference<FaultToleranceConfig> lazyConfig = new AtomicReference<>();
Supplier<FaultToleranceConfig> configSupplier = () -> lazyConfig.updateAndGet(value -> value != null ? value : faultToleranceService.getConfig(context, this));
FaultTolerancePolicy policy = FaultTolerancePolicy.get(context, configSupplier);
if (policy.isPresent) {
return policy.proceed(context, () -> faultToleranceService.getMethodContext(context, policy, getRequestContextController()));
}
} catch (FaultToleranceDefinitionException e) {
logger.log(Level.SEVERE, "Effective FT policy contains illegal values, fault tolerance cannot be applied," + " falling back to plain method invocation.", e);
// fall-through to normal proceed
}
return context.proceed();
}
use of fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy in project Payara by payara.
the class ConfigAlternativeAsynchronousAnnotationsTest method userDefinedAsynchronousAnnotation.
/**
* Tests with two alternative annotations, one of which is a user defined one {@link OurAsynchronous}.
*/
@Test
public void userDefinedAsynchronousAnnotation() {
config.override(ALTERNATIVE_ASYNCHRONOUS_ANNNOTATIONS_PROPERTY, javax.ejb.Asynchronous.class.getName() + "," + OurAsynchronous.class.getName());
FaultTolerancePolicy policy = getPolicy();
assertNotNull(policy.asynchronous);
assertFalse("Should be COMPLETION_STAGE", policy.asynchronous.isSuccessWhenCompletedExceptionally());
}
use of fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy in project Payara by payara.
the class ConfigAlternativeAsynchronousAnnotationsTest method javaxEjbAsynchronous.
/**
* Test with a single alternative annotation of type {@link javax.ejb.Asynchronous} set.
*/
@Test
public void javaxEjbAsynchronous() {
config.override(ALTERNATIVE_ASYNCHRONOUS_ANNNOTATIONS_PROPERTY, javax.ejb.Asynchronous.class.getName());
FaultTolerancePolicy policy = getPolicy();
assertNotNull(policy.asynchronous);
assertTrue("Should be FUTURE", policy.asynchronous.isSuccessWhenCompletedExceptionally());
}
use of fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy in project Payara by payara.
the class ConfigAlternativeAsynchronousAnnotationsTest method asynchronousStillRecognisedWhenSettingAlternativeAnnotations.
/**
* Again two alternative annotations are set but the FT {@link Asynchronous} annotation is used and should still
* work (even when not in the list configured).
*/
@Test
public void asynchronousStillRecognisedWhenSettingAlternativeAnnotations() {
config.override(ALTERNATIVE_ASYNCHRONOUS_ANNNOTATIONS_PROPERTY, javax.ejb.Asynchronous.class.getName() + "," + OurAsynchronous.class.getName());
FaultTolerancePolicy policy = getPolicy();
assertNotNull(policy.asynchronous);
assertTrue("Should be FUTURE", policy.asynchronous.isSuccessWhenCompletedExceptionally());
}
Aggregations