org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException Java Examples

The following examples show how to use org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RetryConfig.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Override
public void validate() {
    if (get(MAX_RETRIES, Integer.class) < -1) {
        throw new FaultToleranceDefinitionException(
                INVALID_RETRY_ON + getMethodInfo() + " : maxRetries shouldn't be lower than -1");
    }
    if (get(DELAY, Long.class) < 0) {
        throw new FaultToleranceDefinitionException(
                INVALID_RETRY_ON + getMethodInfo() + " : delay shouldn't be lower than 0");
    }
    if (get(MAX_DURATION, Long.class) < 0) {
        throw new FaultToleranceDefinitionException(
                INVALID_RETRY_ON + getMethodInfo() + " : maxDuration shouldn't be lower than 0");
    }
    if (Duration.of(get(MAX_DURATION, Long.class), get(DURATION_UNIT, ChronoUnit.class)).toMillis() <= Duration
            .of(get(DELAY, Long.class), get(DELAY_UNIT, ChronoUnit.class)).toMillis()) {
        throw new FaultToleranceDefinitionException(
                INVALID_RETRY_ON + getMethodInfo() + " : maxDuration should be greater than delay");
    }
    if (get(JITTER, Long.class) < 0) {
        throw new FaultToleranceDefinitionException(
                INVALID_RETRY_ON + getMethodInfo() + " : jitter shouldn't be lower than 0");
    }
}
 
Example #2
Source File: FaultToleranceOperation.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * Throws {@link FaultToleranceDefinitionException} if validation fails.
 */
public void validate() {
    if (async && !isAcceptableAsyncReturnType(method.getReturnType())) {
        throw new FaultToleranceDefinitionException("Invalid @Asynchronous on " + method
                + ": must return java.util.concurrent.Future or java.util.concurrent.CompletionStage");
    }
    if (bulkhead != null) {
        bulkhead.validate();
    }
    if (circuitBreaker != null) {
        circuitBreaker.validate();
    }
    if (fallback != null) {
        fallback.validate();
    }
    if (retry != null) {
        retry.validate();
    }
    if (timeout != null) {
        timeout.validate();
    }
}
 
Example #3
Source File: CircuitBreakerConfig.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Override
public void validate() {
    if (get(DELAY, Long.class) < 0) {
        throw new FaultToleranceDefinitionException(
                INVALID_CIRCUIT_BREAKER_ON + getMethodInfo() + " : delay shouldn't be lower than 0");
    }
    if (get(REQUEST_VOLUME_THRESHOLD, Integer.class) < 1) {
        throw new FaultToleranceDefinitionException(
                INVALID_CIRCUIT_BREAKER_ON + getMethodInfo() + " : requestVolumeThreshold shouldn't be lower than 1");
    }
    if (get(FAILURE_RATIO, Double.class) < 0 || get(FAILURE_RATIO, Double.class) > 1) {
        throw new FaultToleranceDefinitionException(
                INVALID_CIRCUIT_BREAKER_ON + getMethodInfo() + " : failureRation should be between 0 and 1");
    }
    int successThreshold = get(SUCCESS_THRESHOLD, Integer.class);
    if (successThreshold < 1) {
        throw new FaultToleranceDefinitionException(
                INVALID_CIRCUIT_BREAKER_ON + getMethodInfo() + " : successThreshold shouldn't be lower than 1");
    }
}
 
Example #4
Source File: InvalidTimeoutValueTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidTimeout.jar")
        .addClasses(TimeoutClientForValidation.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidTimeout.war")
        .addAsLibrary(testJar);
}
 
Example #5
Source File: FallbackMethodOutOfPackageTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftFallbackMethodOutOfPackage.jar")
            .addClasses(FallbackMethodOutOfPackageBeanA.class, FallbackMethodOutOfPackageBeanB.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    
    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftFallbackMethodOutOfPackage.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #6
Source File: InvalidCircuitBreakerFailureSuccessNegTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB7.jar")
        .addClasses(CircuitBreakerClientForValidationSuccessNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB7.war")
        .addAsLibrary(testJar);
}
 
Example #7
Source File: InvalidAsynchronousClassTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidAsnycClass.jar")
        .addClasses(AsynchronousClientForValidationClass.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidAsnycClass.war")
        .addAsLibrary(testJar);
}
 
Example #8
Source File: InvalidCircuitBreakerFailureSuccess0Test.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB6.jar")
        .addClasses(CircuitBreakerClientForValidationSuccess0.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB6.war")
        .addAsLibrary(testJar);
}
 
Example #9
Source File: InvalidCircuitBreakerDelayTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB1.jar")
        .addClasses(CircuitBreakerClientForValidationDelay.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB1.war")
        .addAsLibrary(testJar);
}
 
Example #10
Source File: InvalidRetryMaxRetriesTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry2.jar")
        .addClasses(RetryClientForValidationMaxRetries.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry2.war")
        .addAsLibrary(testJar);
}
 
Example #11
Source File: IncompatibleFallbackPolicies.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalid.jar")
        .addClasses(FallbackClientWithBothFallbacks.class, IncompatibleFallbackHandler.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidFallbackPolicy.war")
        .addAsLibrary(testJar);
}
 
Example #12
Source File: IncompatibleFallbackMethodWithArgsTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deployAnotherApp() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "ftInvalid.jar")
            .addClasses(FallbackMethodWithArgsClient.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftInvalidFallbackMethodWithArgs.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #13
Source File: IncompatibleFallbackTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalid.jar")
        .addClasses(FallbackClient.class, IncompatibleFallbackHandler.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidFallbackHandler.war")
        .addAsLibrary(testJar);
}
 
Example #14
Source File: IncompatibleFallbackMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deployAnotherApp() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "ftInvalid.jar")
            .addClasses(FallbackMethodClient.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftInvalidFallbackMethod.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #15
Source File: FallbackMethodWildcardNegativeTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftFallbackMethodSuperclassPrivate.jar")
            .addClass(FallbackMethodWildcardNegativeBean.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    
    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftFallbackMethodSuperclassPrivate.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #16
Source File: FallbackMethodSubclassTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftFallbackMethodSubclass.jar")
            .addClasses(FallbackMethodSubclassBeanA.class, FallbackMethodSubclassBeanB.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    
    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftFallbackMethodSubclass.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #17
Source File: FallbackMethodSuperclassPrivateTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, "ftFallbackMethodSuperclassPrivate.jar")
            .addClasses(FallbackMethodSuperclassPrivateBeanA.class, FallbackMethodSuperclassPrivateBeanB.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
    
    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftFallbackMethodSuperclassPrivate.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #18
Source File: InvalidCircuitBreakerFailureReqVol0Test.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB4.jar")
        .addClasses(CircuitBreakerClientForValidationReqVol0.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB4.war")
        .addAsLibrary(testJar);
}
 
Example #19
Source File: InvalidCircuitBreakerFailureRatioNegTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB3.jar")
        .addClasses(CircuitBreakerClientForValidationFailureRatioNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB3.war")
        .addAsLibrary(testJar);
}
 
Example #20
Source File: InvalidBulkheadValueTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidBulkhead1.jar")
        .addClasses(BulkheadClientForValidation.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidBulkhead1.war")
        .addAsLibrary(testJar);
}
 
Example #21
Source File: InvalidRetryDelayDurationTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy2() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry3.jar")
        .addClasses(RetryClientForValidationDelayDuration.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry3.war")
        .addAsLibrary(testJar);
}
 
Example #22
Source File: InvalidAsynchronousMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidAsnycMethod.jar")
        .addClasses(AsynchronousClientForValidationMethod.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidAsnycMethod.war")
        .addAsLibrary(testJar);
}
 
Example #23
Source File: InvalidRetryDelayTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry1.jar")
        .addClasses(RetryClientForValidationDelay.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry1.war")
        .addAsLibrary(testJar);
}
 
Example #24
Source File: InvalidBulkheadAsynchQueueTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidBulkhead3.jar")
        .addClasses(BulkheadClientForValidationAsynchQueue.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidBulkhead3.war")
        .addAsLibrary(testJar);
}
 
Example #25
Source File: InvalidRetryJitterTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry4.jar")
        .addClasses(RetryClientForValidationJitter.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry4.war")
        .addAsLibrary(testJar);
}
 
Example #26
Source File: InvalidCircuitBreakerFailureReqVolNegTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB5.jar")
        .addClasses(CircuitBreakerClientForValidationReqVolNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB5.war")
        .addAsLibrary(testJar);
}
 
Example #27
Source File: InvalidCircuitBreakerFailureRatioPosTest.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Deployment
@ShouldThrowException(value = FaultToleranceDefinitionException.class)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB2.jar")
        .addClasses(CircuitBreakerClientForValidationFailureRatioPos.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB2.war")
        .addAsLibrary(testJar);
}
 
Example #28
Source File: BulkheadConfig.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public void validate() {
    if (get(VALUE, Integer.class) < 0) {
        throw new FaultToleranceDefinitionException(
                "Invalid Bulkhead on " + getMethodInfo() + " : value shouldn't be lower than 0");
    }
    if (get(WAITING_TASK_QUEUE, Integer.class) < 1) {
        throw new FaultToleranceDefinitionException(
                "Invalid Bulkhead on " + getMethodInfo() + " : waitingTaskQueue shouldn't be lower than 1");
    }
}
 
Example #29
Source File: TimeoutConfig.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Override
public void validate() {
    if (get(VALUE, Long.class) < 0) {
        throw new FaultToleranceDefinitionException(
                "Invalid @Timeout on " + getMethodInfo() + " : value shouldn't be lower than 0");
    }
}
 
Example #30
Source File: GenericConfig.java    From smallrye-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <U> U getConfigFromAnnotation(String key) {
    try {
        return (U) SecurityActions.getAnnotationMethod(annotationType, key).invoke(annotation);
    } catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException | IllegalArgumentException
            | PrivilegedActionException e) {
        throw new FaultToleranceDefinitionException(
                "Member " + key + " on annotation " + annotation.getClass().toString()
                        + " doesn't exist or is not accessible");
    }
}