org.eclipse.microprofile.faulttolerance.Timeout Java Examples

The following examples show how to use org.eclipse.microprofile.faulttolerance.Timeout. 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: DisableAnnotationOnClassTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
   Asset config = new DisableConfigAsset()
           .disable(DisableAnnotationClient.class, Retry.class)
           .disable(DisableAnnotationClient.class, CircuitBreaker.class)
           .disable(DisableAnnotationClient.class, Timeout.class)
           .disable(DisableAnnotationClient.class, Asynchronous.class)
           .disable(DisableAnnotationClient.class, Fallback.class)
           .disable(DisableAnnotationClient.class, Bulkhead.class);
    
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableClass.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableClass.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #2
Source File: CoffeeResource.java    From quarkus-quickstarts with Apache License 2.0 6 votes vote down vote up
@GET
@Path("/{id}/recommendations")
@Timeout(250)
@Fallback(fallbackMethod = "fallbackRecommendations")
public List<Coffee> recommendations(@PathParam int id) {
    long started = System.currentTimeMillis();
    final long invocationNumber = counter.getAndIncrement();

    try {
        randomDelay();
        LOGGER.infof("CoffeeResource#recommendations() invocation #%d returning successfully", invocationNumber);
        return coffeeRepository.getRecommendations(id);
    } catch (InterruptedException e) {
        LOGGER.errorf("CoffeeResource#recommendations() invocation #%d timed out after %d ms",
                invocationNumber, System.currentTimeMillis() - started);
        return null;
    }
}
 
Example #3
Source File: CircuitBreakerClientWithRetry.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * Configured to always time out and Retry until CircuitBreaker is triggered on 4th call.
 */
@CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 4, failureRatio = 0.75, delay = 50000)
@Retry(retryOn = {RuntimeException.class, TimeoutException.class}, maxRetries = 7, maxDuration = 20000)
@Timeout(100) // Scaled via config
public Connection serviceC() {
    Connection conn = null;
    counterForInvokingServiceC++;

    try {
        Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(5000));
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return conn;
}
 
Example #4
Source File: RetryTimeoutTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {

    final ConfigAnnotationAsset config = new ConfigAnnotationAsset()
        .setValue(RetryTimeoutClient.class,"serviceA", Timeout.class,getConfig().getTimeoutInStr(500))
        .setValue(RetryTimeoutClient.class,"serviceWithoutRetryOn", Timeout.class,getConfig().getTimeoutInStr(500))
        .setValue(RetryTimeoutClient.class,"serviceWithAbortOn", Timeout.class,getConfig().getTimeoutInStr(500));

    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "ftRetryTimeout.jar")
            .addClasses(RetryTimeoutClient.class)
            .addAsManifestResource(config, "microprofile-config.properties")
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftRetryTimeout.war")
            .addAsLibrary(testJar);
    return war;
}
 
Example #5
Source File: FaultToleranceExtension.java    From smallrye-fault-tolerance with Apache License 2.0 6 votes vote down vote up
void registerInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    LOGGER.info("MicroProfile: Fault Tolerance activated");
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(CircuitBreaker.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Retry.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Timeout.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Asynchronous.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Fallback.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Bulkhead.class)));

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    bbd.addAnnotatedType(bm.createAnnotatedType(FaultToleranceInterceptor.class),
            FaultToleranceInterceptor.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFallbackHandlerProvider.class),
            DefaultFallbackHandlerProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(ExecutorProvider.class),
            ExecutorProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFaultToleranceOperationProvider.class),
            DefaultFaultToleranceOperationProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(MetricsCollectorFactory.class), MetricsCollectorFactory.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(StrategyCache.class), StrategyCache.class.getName());
}
 
Example #6
Source File: CircuitBreakerClientWithRetryAsync.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * Configured to always time out and Retry until CircuitBreaker is triggered on 4th call. Runs asynchronously.
 */
@CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 4, failureRatio = 0.75, delay = 50000)
@Retry(retryOn = {TestException.class, TimeoutException.class}, maxRetries = 7, maxDuration = 20000)
@Timeout(100) // Scaled via config
@Asynchronous
public Future<Connection> serviceC() {
    Connection conn = null;
    counterForInvokingServiceC++;

    try {
        Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(5000));
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return CompletableFuture.completedFuture(conn);
}
 
Example #7
Source File: TimeoutMetricTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
    final ConfigAnnotationAsset config = new ConfigAnnotationAsset()
        .setValue(TimeoutMetricBean.class,"counterTestWorkForMillis", Timeout.class,getConfig().getTimeoutInStr(500))
        .setValue(TimeoutMetricBean.class,"histogramTestWorkForMillis", Timeout.class,getConfig().getTimeoutInStr(2000));

    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ftMetricTimeout.jar")
        .addClasses(TimeoutMetricBean.class)
        .addPackage(Packages.UTILS)
        .addPackage(Packages.METRIC_UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    WebArchive war = ShrinkWrap.create(WebArchive.class, "ftMetricTimeout.war")
        .addAsLibrary(jar);
    return war;
}
 
Example #8
Source File: DisableFTEnableGloballyTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
   Asset config = new DisableConfigAsset()
           .enable(Retry.class)
           .enable(CircuitBreaker.class)
           .enable(Timeout.class)
           .enable(Asynchronous.class)
           .enable(Fallback.class)
           .enable(Bulkhead.class)
           .disableGlobally();

    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableGlobalEnableClass.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableGlobalEnableClass.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #9
Source File: DisableFTEnableOnMethodTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
   Asset config = new DisableConfigAsset()
           .enable(DisableAnnotationClient.class, "failAndRetryOnce", Retry.class)
           .enable(DisableAnnotationClient.class, "failWithCircuitBreaker", CircuitBreaker.class)
           .enable(DisableAnnotationClient.class, "failWithTimeout", Timeout.class)
           .enable(DisableAnnotationClient.class, "asyncWaitThenReturn", Asynchronous.class)
           .enable(DisableAnnotationClient.class, "failRetryOnceThenFallback", Fallback.class)
           .enable(DisableAnnotationClient.class, "waitWithBulkhead", Bulkhead.class)
           .disableGlobally();

    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableGloballyEnableMethod.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableGloballyEnableMethod.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #10
Source File: DisableFTEnableOnClassTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
   Asset config = new DisableConfigAsset()
           .enable(DisableAnnotationClient.class, Retry.class)
           .enable(DisableAnnotationClient.class, CircuitBreaker.class)
           .enable(DisableAnnotationClient.class, Timeout.class)
           .enable(DisableAnnotationClient.class, Asynchronous.class)
           .enable(DisableAnnotationClient.class, Fallback.class)
           .enable(DisableAnnotationClient.class, Bulkhead.class)
           .disableGlobally();

    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableGlobalEnableClass.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableGlobalEnableClass.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #11
Source File: DisableAnnotationGloballyTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
    
    Asset config = new DisableConfigAsset()
            .disable(Retry.class)
            .disable(CircuitBreaker.class)
            .disable(Timeout.class)
            .disable(Asynchronous.class)
            .disable(Fallback.class)
            .disable(Bulkhead.class);
    
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableGlobally.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableGlobally.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #12
Source File: AsyncTimeoutTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {

    final Asset config = new ConfigAnnotationAsset()
        .setValue(AsyncTimeoutClient.class, "serviceA", Timeout.class, String.valueOf(TEST_TIMEOUT_SERVICEA.toMillis()))
        .setValue(AsyncTimeoutClient.class, "serviceB", Timeout.class, String.valueOf(TEST_TIMEOUT_SERVICEB.toMillis()))
        .setValue(AsyncClassLevelTimeoutClient.class, null, Timeout.class, getConfig().getTimeoutInStr(2000));

    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftAsyncTimeout.jar")
        .addClasses(AsyncTimeoutClient.class, AsyncClassLevelTimeoutClient.class, Connection.class)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftAsyncTimeout.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #13
Source File: AsyncTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * serviceA is a slow running service that will take 5 seconds in normal operation. Here it is
 * configured to time out after 2 seconds.
 * @return the result as a Future
 * @throws InterruptedException the interrupted exception
 */
@Timeout(2000)
@Asynchronous
public Future<Connection> serviceA() throws InterruptedException {

    Connection conn = new Connection() {
        {
            Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(5000));
        }
        
        @Override
        public String getData() {
            return "serviceA DATA";
        }
    };

    return CompletableFuture.completedFuture(conn);
}
 
Example #14
Source File: AsyncTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
/**
 * serviceB is a fast running service that will take 0.5 seconds in normal operation. That is considerably quicker than
 * its configured time out of 2 seconds.
 * @return the result as a Future
 * @throws InterruptedException the interrupted exception
 */
@Timeout(2000)
@Asynchronous
public Future<Connection> serviceB() throws InterruptedException {

    Connection conn = new Connection() {
        {
            Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(500));
        }
        
        @Override
        public String getData() {
            return "serviceB DATA";
        }
    };

    return CompletableFuture.completedFuture(conn);
}
 
Example #15
Source File: TimeoutConfigTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive create() {
    ConfigAnnotationAsset config = new ConfigAnnotationAsset()
        .set(TimeoutConfigBean.class, "serviceValue", Timeout.class, "value",
            TCKConfig.getConfig().getTimeoutInStr(1000))
        // only changing value here to scale the original, not for the purpose of this test
        .set(TimeoutConfigBean.class, "serviceUnit", Timeout.class, "value",
            TCKConfig.getConfig().getTimeoutInStr(1000))
        .set(TimeoutConfigBean.class, "serviceUnit", Timeout.class, "unit", "MILLIS")
        .set(TimeoutConfigBean.class, "serviceBoth", Timeout.class, "value",
            TCKConfig.getConfig().getTimeoutInStr(1000))
        .set(TimeoutConfigBean.class, "serviceBoth", Timeout.class, "unit", "MILLIS");

    JavaArchive jar = ShrinkWrap.create(JavaArchive.class, "ftTimeoutConfig.jar")
        .addClasses(TimeoutConfigBean.class, CompletableFutureHelper.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap.create(WebArchive.class, "ftTimeoutConfig.war")
        .addAsLibrary(jar);
}
 
Example #16
Source File: DisableAnnotationOnMethodsTest.java    From microprofile-fault-tolerance with Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive deploy() {
    Asset config = new DisableConfigAsset()
            .disable(DisableAnnotationClient.class, "failAndRetryOnce", Retry.class)
            .disable(DisableAnnotationClient.class, "failRetryOnceThenFallback", Fallback.class)
            .disable(DisableAnnotationClient.class, "failWithCircuitBreaker", CircuitBreaker.class)
            .disable(DisableAnnotationClient.class, "failWithTimeout", Timeout.class)
            .disable(DisableAnnotationClient.class, "asyncWaitThenReturn", Asynchronous.class)
            .disable(DisableAnnotationClient.class, "waitWithBulkhead", Bulkhead.class);
    
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftDisableMethods.jar")
        .addClasses(DisableAnnotationClient.class)
        .addPackage(Packages.UTILS)
        .addAsManifestResource(config, "microprofile-config.properties")
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
        .create(WebArchive.class, "ftDisableMethods.war")
        .addAsLibrary(testJar);
    return war;
}
 
Example #17
Source File: ClashingNameBean.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Retry(maxRetries = 5)
@Bulkhead(3)
@Timeout(value = 1000, unit = ChronoUnit.MILLIS)
@CircuitBreaker(failureRatio = 1.0, requestVolumeThreshold = 20)
@Fallback(fallbackMethod = "doFallback")
@Asynchronous
public Future<Void> doWork() {
    return CompletableFuture.completedFuture(null);
}
 
Example #18
Source File: ResilienceController.java    From ci.maven with Apache License 2.0 5 votes vote down vote up
@Fallback(fallbackMethod = "fallback") // better use FallbackHandler
@Timeout(500)
@GET
public String checkTimeout() {
    try {
        Thread.sleep(700L);
    } catch (InterruptedException e) {
        //
    }
    return "Never from normal processing";
}
 
Example #19
Source File: RetryTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * Sleeps for 1000ms, times out after 500ms, retries once on anything but TimeoutException
 * 
 * @return {@code null}
 */
@Timeout(500)
@Retry(maxRetries = 1, abortOn = TimeoutException.class)
public String serviceWithAbortOn() {
    try {
        counterForInvokingServiceWithAbortOn++;
        Thread.sleep(config.getTimeoutInMillis(1000));
        fail("Timeout did not interrupt");
    }
    catch (InterruptedException e) {
        // expected
    }
    return null;
}
 
Example #20
Source File: TimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * serviceD specifies a Timeout longer than the default, at 2 
 * seconds.
 * 
 * @param timeToSleepInMillis  How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(value = 2, unit = ChronoUnit.SECONDS)
public Connection serviceD(long timeToSleepInMillis) {
    try {
        Thread.sleep(timeToSleepInMillis);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #21
Source File: DefaultTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * serviceB specifies a an overriding Timeout longer than the default, at 2 seconds
 * @param timeToSleep How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(2000)
public Connection serviceB(long timeToSleep) {
    try {
        Thread.sleep(timeToSleep);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #22
Source File: ShorterTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * serviceB specifies a an overriding Timeout longer than the default, at 2 seconds
 * @param timeToSleep How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(2000)
public Connection serviceB(long timeToSleep) {
    try {
        Thread.sleep(timeToSleep);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #23
Source File: UninterruptableTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * Waits for at least {@code waitms}, then returns
 * <p>
 * Times out in 500ms.
 * <p>
 * Does not respect thread interruption.
 * <p>
 * Uses a tight loop so the thread interrupted flag should be set when the method returns
 * 
 * @param waitMs the time to wait
 */
@Timeout(value = 500, unit = ChronoUnit.MILLIS)
public void serviceTimeout(long waitMs) {
    long waitNs = Duration.ofMillis(waitMs).toNanos();
    long startTime = System.nanoTime();
    
    while (true) {
        if (System.nanoTime() - startTime > waitNs) {
            return;
        }
    }
}
 
Example #24
Source File: FallbackClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Timeout(500)
@Retry(maxRetries = 1)
@Fallback(StringFallbackHandler.class)
public String serviceC(long timeToSleep) {
    try {
        counterForInvokingServiceC++;
        Thread.sleep(timeToSleep);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #25
Source File: CustomerRepository.java    From Hands-On-Cloud-Native-Applications-with-Java-and-Quarkus with MIT License 5 votes vote down vote up
@Timeout(250)
@Fallback(fallbackMethod = "findAllStatic")
@Retry(maxRetries = 3)
public List<Customer> findAll() {

    randomSleep();

    return entityManager.createNamedQuery("Customers.findAll", Customer.class)
            .getResultList();

}
 
Example #26
Source File: TimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * serviceC specifies a Timeout shorter than the default, at .5 seconds
 * @param timeToSleep How long should the execution take in millis
 * @return null or exception is raised
 */
@Timeout(500)
public Connection serviceC(long timeToSleep) {
    try {
        Thread.sleep(timeToSleep);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #27
Source File: RetryTimeoutClient.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * Times out after 500ms, retries once
 * 
 * @param timeToSleep time this method should sleep for in ms 
 * @return {@code null}
 */
@Timeout(500)
@Retry(maxRetries = 1)
public String serviceA(long timeToSleep) {
    try {
        counterForInvokingServiceA++;
        Thread.sleep(timeToSleep);
        throw new RuntimeException("Timeout did not interrupt");
    } 
    catch (InterruptedException e) {
        //expected
    }
    return null;
}
 
Example #28
Source File: CircuitBreakerClientWithTimeout.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
/**
 * Sleeps for 1000ms, times out after 500ms
 * <p>
 * CircuitBreaker opens after two failed requests
 * 
 * @return should always throw TimeoutException, unless CircuitBreaker prevents execution
 */
@CircuitBreaker(successThreshold = 2, requestVolumeThreshold = 2, failureRatio = 0.75, delay = 50000)
@Timeout(500) // Adjusted by config
public String serviceWithTimeout() {
    try {
        Thread.sleep(TCKConfig.getConfig().getTimeoutInMillis(1000));
        fail("Thread not interrupted by timeout");
    }
    catch (InterruptedException e) {
        // Expected
    }
    return "OK";
}
 
Example #29
Source File: AllMetricsBean.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Retry(maxRetries = 5)
@Bulkhead(3)
@Timeout(value = 1, unit = ChronoUnit.MINUTES)
@CircuitBreaker(failureRatio = 1.0, requestVolumeThreshold = 20)
@Fallback(fallbackMethod = "doFallback")
@Asynchronous
public Future<Void> doWork() {
    return CompletableFuture.completedFuture(null);
}
 
Example #30
Source File: ClashingNameBean.java    From microprofile-fault-tolerance with Apache License 2.0 5 votes vote down vote up
@Retry(maxRetries = 5)
@Bulkhead(3)
@Timeout(value = 1000, unit = ChronoUnit.MILLIS)
@CircuitBreaker(failureRatio = 1.0, requestVolumeThreshold = 20)
@Fallback(fallbackMethod = "doFallback")
@Asynchronous
public Future<Void> doWork(String dummy) {
    return CompletableFuture.completedFuture(null);
}