use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig in project Payara by payara.
the class ConfigOverrideTest method assertOverridden.
private <T, A extends Annotation> void assertOverridden(Class<A> annotationType, String propertyName, T annotated, T overridden, BiFunction<FaultToleranceConfig, A, T> property) {
Method annotatedMethod = getAnnotatedMethod();
FaultToleranceConfig config = configFactory.bindTo(new StaticAnalysisContext(getClass(), annotatedMethod));
A annotation = config.getAnnotation(annotationType);
// check we get the expected annotated value
T actual = property.apply(config, annotation);
assertEqualValue(annotated, actual);
// make the override
overrides.override(annotatedMethod, annotationType, propertyName, overridden);
// now check that we get the expected overridden value
actual = property.apply(config, annotation);
assertEqualValue(overridden, actual);
}
use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig 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.FaultToleranceConfig in project Payara by payara.
the class ConfigOverridePriorityTest method enabledIsIndependentOfPresentAnnotations.
@Test
public void enabledIsIndependentOfPresentAnnotations() {
Method annotatedMethod = TestUtils.getAnnotatedMethod();
FaultToleranceConfig config = configFactory.bindTo(new StaticAnalysisContext(getClass(), annotatedMethod));
assertTrue("should be: present annotation is enabled by default", config.isEnabled(Asynchronous.class));
assertTrue("should be: not present annotation is enabled by default", config.isEnabled(Retry.class));
overrides.override(Asynchronous.class, "enabled", false);
overrides.override(Retry.class, "enabled", false);
assertFalse("should be: global override for present annotation has effect", config.isEnabled(Asynchronous.class));
assertFalse("should be: global override for not present annotation has effect", config.isEnabled(Retry.class));
overrides.override(getClass(), Asynchronous.class, "enabled", true);
overrides.override(getClass(), Retry.class, "enabled", true);
assertTrue("should be: class level override for present annotation has effect", config.isEnabled(Asynchronous.class));
assertTrue("should be: class level override for not present annotation has effect", config.isEnabled(Retry.class));
overrides.override(annotatedMethod, Asynchronous.class, "enabled", false);
overrides.override(annotatedMethod, Retry.class, "enabled", false);
assertFalse("should be: method level override for present annotation has effect", config.isEnabled(Asynchronous.class));
assertFalse("should be: method level override for not present annotation has effect", config.isEnabled(Retry.class));
}
use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig in project Payara by payara.
the class ConfigOverridePriorityTest method onlyClassLevelAnnotationPresent.
@Test
public void onlyClassLevelAnnotationPresent() {
Method annotatedMethod = TestUtils.getAnnotatedMethod();
FaultToleranceConfig config = configFactory.bindTo(new StaticAnalysisContext(getClass(), annotatedMethod));
Retry annotation = config.getAnnotation(Retry.class);
assertEquals(ChronoUnit.MINUTES, config.delayUnit(annotation));
overrides.override(Retry.class, "delayUnit", ChronoUnit.CENTURIES);
assertEquals("should be: global override effective", ChronoUnit.CENTURIES, config.delayUnit(annotation));
overrides.override(getClass(), Retry.class, "delayUnit", ChronoUnit.DAYS);
assertEquals("should be: class level override effective because annotation present on class level", ChronoUnit.DAYS, config.delayUnit(annotation));
overrides.override(annotatedMethod, Retry.class, "delayUnit", ChronoUnit.HOURS);
assertEquals("should be: method level override ineffective because no method level annotation present", ChronoUnit.DAYS, config.delayUnit(annotation));
}
use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig in project Payara by payara.
the class ConfigScopeTest method isNonFallbackEnabledOnlyResolvedOnce.
@Test
public void isNonFallbackEnabledOnlyResolvedOnce() {
FaultToleranceConfig config = new BindableFaultToleranceConfig(overrides, null);
assertTrue("default should be true", config.isNonFallbackEnabled());
overrides.override(BindableFaultToleranceConfig.NON_FALLBACK_ENABLED_PROPERTY, false);
assertTrue("should still be true since it has been resolved already", config.isNonFallbackEnabled());
assertFalse("should be false since property was set before it was resolved", new BindableFaultToleranceConfig(overrides, null).isNonFallbackEnabled());
}
Aggregations