Payara: [microprofile] @Timeout annotation cannot set the java.time.temporal.ChronoUnit via the configuration file.

Created on 8 Mar 2019  路  7Comments  路  Source: payara/Payara

# Description #

I've tried to set the fault tolerance annotation time unit via the META-INF/microprofile-config.properties, but have no luck to success with the following exception: -

java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.ChronoUnit
    at fish.payara.microprofile.faulttolerance.interceptors.TimeoutInterceptor.timeout(TimeoutInterceptor.java:199)
    at fish.payara.microprofile.faulttolerance.interceptors.TimeoutInterceptor.intercept(TimeoutInterceptor.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.weld.interceptor.reader.SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(SimpleInterceptorInvocation.java:73)
    at org.jboss.weld.interceptor.proxy.NonTerminalAroundInvokeInvocationContext.proceedInternal(NonTerminalAroundInvokeInvocationContext.java:66)
    at org.jboss.weld.interceptor.proxy.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:78)

It is related to #3763 , but this time is for @Timeout.

Expected Outcome

Able to configure the java.time.temporal.ChronoUnit via the META-INF/microprofile-config.properties.

Current Outcome

There is an exception as java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.ChronoUnit.

Steps to reproduce (Only for bug reports)

  1. Annotate the method with empty @Timeout
  2. Set the CircuitBreaker attribute via the META-INF/microprofile-config.properties as

    • /Timeout/unit=java.time.temporal.ChronoUnit.MILLIS or

    • /Timeout/unit=MILLIS

  3. Access the service via cURL, the exception shown at the log.

Samples

# META-INF/microprofile-config.properties
my.service.MyService/alwaysFail/Timeout/value=1000
my.service.MyService/alwaysFail/Timeout/unit=java.time.temporal.ChronoUnit.MILLIS

# or
# my.service.MyService/alwaysFail/Timeout/unit=MILLIS
# 

```java
package my.service;
@ApplicationPath("/myapi")
public class MyApplication extends Application {
}

```java
package my.service;
@Path("ft")
@ApplicationScoped
public class MyResource {
    @GET
    @Timeout
    public Response alwaysFail() {
        try {
            Thread.sleep(1500L);
        } catch (InterruptedException e) {
            //Handle exception
        }
    }
}
curl -v -X GET \
http://localhost:8080/myweb/myapi/ft

# The exception 
# java.lang.ClassCastException: java.lang.String cannot be cast to java.time.temporal.ChronoUnit 
# shown at the log.

Furthermore, I also have a chance to look at TimeoutInterceptor and found that it use String.class for looking up the value and then cast it to ChronoUnit as the following: -

        ChronoUnit unit = (ChronoUnit) FaultToleranceCdiUtils.getOverrideValue(
                config, Timeout.class, "unit", invocationContext, String.class)
                .orElse(timeout.unit());

This may be the root cause.

Context (Optional)

I've tried to learn the Microprofile: Fault Tolerance and tried to config them via the META-INF/microprofile-config.properties.

Environment

From Docker payara/micro:latest

  • Payara Version: Payara Micro 5.184 #badassmicrofish (build 89)
  • Edition: Micro
  • JDK Version:
openjdk version "1.8.0_181"
OpenJDK Runtime Environment (IcedTea 3.9.0) (Alpine 8.181.13-r0)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
  • Operating System:
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.8.1
PRETTY_NAME="Alpine Linux v3.8"
  • Database: N/A
Accepted Bug

All 7 comments

Fixed by #3765

@smillidge I apologize for disturbing you again.

Please correct me if I'm wrong. The #3765 fixed only for CircuitBreakerInterceptor.java, anyhow at this time is for TimeoutInterceptor.java.

The line number 197-199 of TimeoutInterceptor.java still be

ChronoUnit unit = (ChronoUnit) FaultToleranceCdiUtils.getOverrideValue(
                config, Timeout.class, "unit", invocationContext, String.class)
                .orElse(timeout.unit());

Could you please help to advise and consider?

Hi,

I've created the reproducible test case at

https://github.com/charleech/payara-evaluation/tree/master/payara-evaluation-fault-tolerance

I hope this may be useful.

Opened internal issue PAYARA-3753

Hi, working on update to MP FT 2.0 and will fix this in connection with the required changes.

Going to be fixed by #3911

Fixed by #3911

Was this page helpful?
0 / 5 - 0 ratings