Search in sources :

Example 6 with FaultToleranceConfig

use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig in project Payara by payara.

the class ConfigScopeTest method isMetricsEnabledOnlyResolvedOnce.

@Test
public void isMetricsEnabledOnlyResolvedOnce() {
    FaultToleranceConfig config = new BindableFaultToleranceConfig(overrides, null);
    assertTrue("default should be true", config.isMetricsEnabled());
    overrides.override(BindableFaultToleranceConfig.METRICS_ENABLED_PROPERTY, false);
    assertTrue("should still be true since it has been resolved already", config.isMetricsEnabled());
    assertFalse("should be false since property was set before it was resolved", new BindableFaultToleranceConfig(overrides, null).isMetricsEnabled());
}
Also used : FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) Test(org.junit.Test)

Example 7 with FaultToleranceConfig

use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig 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)

Example 8 with FaultToleranceConfig

use of fish.payara.microprofile.faulttolerance.FaultToleranceConfig in project Payara by payara.

the class ConfigOverridePriorityTest method onlyMethodLevelAnnotationPresent.

@Test
public void onlyMethodLevelAnnotationPresent() {
    Method annotatedMethod = TestUtils.getAnnotatedMethod();
    FaultToleranceConfig config = configFactory.bindTo(new StaticAnalysisContext(getClass(), annotatedMethod));
    Timeout timeout = config.getAnnotation(Timeout.class);
    assertEquals(42L, config.value(timeout));
    overrides.override(Timeout.class, "value", 11L);
    assertEquals("should be: global override effective", 11L, config.value(timeout));
    overrides.override(getClass(), Timeout.class, "value", 22L);
    assertEquals("should be: class level override ineffective because no class level annotation present", 11L, config.value(timeout));
    // do method level override
    overrides.override(annotatedMethod, Timeout.class, "value", 33L);
    assertEquals("should be: method level override effective", 33L, config.value(timeout));
}
Also used : StaticAnalysisContext(fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext) Timeout(org.eclipse.microprofile.faulttolerance.Timeout) FaultToleranceConfig(fish.payara.microprofile.faulttolerance.FaultToleranceConfig) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

FaultToleranceConfig (fish.payara.microprofile.faulttolerance.FaultToleranceConfig)8 Test (org.junit.Test)6 StaticAnalysisContext (fish.payara.microprofile.faulttolerance.policy.StaticAnalysisContext)5 Method (java.lang.reflect.Method)5 Retry (org.eclipse.microprofile.faulttolerance.Retry)3 FaultTolerancePolicy (fish.payara.microprofile.faulttolerance.policy.FaultTolerancePolicy)1 TestUtils.getAnnotatedMethod (fish.payara.microprofile.faulttolerance.test.TestUtils.getAnnotatedMethod)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Asynchronous (org.eclipse.microprofile.faulttolerance.Asynchronous)1 Timeout (org.eclipse.microprofile.faulttolerance.Timeout)1 FaultToleranceDefinitionException (org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException)1