Java源码示例:org.eclipse.microprofile.faulttolerance.exceptions.FaultToleranceDefinitionException
示例1
@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");
}
}
示例2
/**
* 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();
}
}
示例3
@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");
}
}
示例4
public boolean isValid() {
try {
validate();
return true;
} catch (FaultToleranceDefinitionException e) {
return false;
}
}
示例5
@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");
}
}
示例6
@Override
public void validate() {
if (get(VALUE, Long.class) < 0) {
throw new FaultToleranceDefinitionException(
"Invalid @Timeout on " + getMethodInfo() + " : value shouldn't be lower than 0");
}
}
示例7
@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");
}
}
示例8
@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);
}
示例9
@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);
}
示例10
@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);
}
示例11
@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);
}
示例12
@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);
}
示例13
@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);
}
示例14
@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);
}
示例15
@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);
}
示例16
@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);
}
示例17
@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);
}
示例18
@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);
}
示例19
@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);
}
示例20
@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);
}
示例21
@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);
}
示例22
@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);
}
示例23
@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);
}
示例24
@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);
}
示例25
@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;
}
示例26
@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);
}
示例27
@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;
}
示例28
@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;
}
示例29
@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;
}
示例30
@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;
}