use of fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext in project Payara by payara.
the class ConfigAlternativeAsynchronousAnnotationsTest method getPolicy.
private FaultTolerancePolicy getPolicy() {
Method annotatedMethod = TestUtils.getAnnotatedMethod();
StaticAnalysisContext context = new StaticAnalysisContext(getClass(), annotatedMethod);
return FaultTolerancePolicy.get(context, () -> configFactory.bindTo(context));
}
use of fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext 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.policy.StaticAnalysisContext 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.policy.StaticAnalysisContext 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.policy.StaticAnalysisContext in project Payara by payara.
the class ConfigOverridePriorityTest method methodAndClassLevelAnnotationPresent.
@Test
public void methodAndClassLevelAnnotationPresent() {
Method annotatedMethod = TestUtils.getAnnotatedMethod();
FaultToleranceConfig config = configFactory.bindTo(new StaticAnalysisContext(getClass(), annotatedMethod));
Retry retry = config.getAnnotation(Retry.class);
assertEquals(ChronoUnit.WEEKS, config.delayUnit(retry));
overrides.override(Retry.class, "delayUnit", ChronoUnit.ERAS);
assertEquals("should be: global override effective", ChronoUnit.ERAS, config.delayUnit(retry));
overrides.override(getClass(), Retry.class, "delayUnit", ChronoUnit.MICROS);
assertEquals("should be: class level annotation present but override ineffective because method level annotation is present", ChronoUnit.ERAS, config.delayUnit(retry));
overrides.override(annotatedMethod, Retry.class, "delayUnit", ChronoUnit.YEARS);
assertEquals("should be: method level override effective", ChronoUnit.YEARS, config.delayUnit(retry));
}
Aggregations