Search in sources :

Example 1 with StaticAnalysisContext

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));
}
Also used : StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) Method(java.lang.reflect.Method)

Example 2 with StaticAnalysisContext

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);
}
Also used : StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) TestUtils.getAnnotatedMethod(fish.payara.microprofile.faulttolerance.test.TestUtils.getAnnotatedMethod) Method(java.lang.reflect.Method)

Example 3 with StaticAnalysisContext

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));
}
Also used : Asynchronous(org.eclipse.microprofile.faulttolerance.Asynchronous) StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) Method(java.lang.reflect.Method) Retry(org.eclipse.microprofile.faulttolerance.Retry) Test(org.junit.Test)

Example 4 with StaticAnalysisContext

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));
}
Also used : StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) Method(java.lang.reflect.Method) Retry(org.eclipse.microprofile.faulttolerance.Retry) Test(org.junit.Test)

Example 5 with StaticAnalysisContext

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));
}
Also used : StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) Method(java.lang.reflect.Method) Retry(org.eclipse.microprofile.faulttolerance.Retry) Test(org.junit.Test)

Aggregations

StaticAnalysisContext (fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext)6 Method (java.lang.reflect.Method)6 FaultToleranceConfig (fish.payara.microprofile.faulttolerance.FaultToleranceConfig)5 Test (org.junit.Test)4 Retry (org.eclipse.microprofile.faulttolerance.Retry)3 TestUtils.getAnnotatedMethod (fish.payara.microprofile.faulttolerance.test.TestUtils.getAnnotatedMethod)1 Asynchronous (org.eclipse.microprofile.faulttolerance.Asynchronous)1 Timeout (org.eclipse.microprofile.faulttolerance.Timeout)1