Uploaded image for project: 'Thorntail'
  1. Thorntail
  2. THORN-1794

Microprofile Fault Tolerance Timeout not throwing TimeoutException until method finished

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 2017.12.1, 2018.1.0
    • Fix Version/s: 2018.3.3
    • Component/s: microprofile
    • Labels:
      None
    • Story Points:
      5
    • Steps to Reproduce:
      Hide

      Create a simple CDI-bean with the following method:

      SomeService.java
      @RequestScoped
      public class SomeService {
      
      	@Timeout
      	public String someSlowMethod(int timeToSleep) {
      		try {
      			Thread.sleep(timeToSleep);
      			throw new RuntimeException("Timeout did not interrupt");
      		} catch (InterruptedException e) {
      			// expected, but does not occur
      		}
      		return null;
      	}
      }
      

      and execute this test case:

      TimeoutTest.java
      @RunWith(Arquillian.class)
      @DefaultDeployment
      public class TimeoutTest {
      
        @Inject
        SomeService service;
      
        /**
         * A test to exercise the default timeout (1000 ms).
         * 
         */
        @Test
        public void testTimeout() {
          long now = System.currentTimeMillis();
          try {
            service.someSlowMethod(3000);
            Assert.fail("serviceA should throw a TimeoutException in testTimeout");
          } catch (TimeoutException ex) {
            // Expected
          } catch (RuntimeException ex) {
            // Not Expected
            Assert.fail("serviceA should throw a TimeoutException in testTimeout not a RuntimeException");
          }
          System.out.println("Total call should not exceed timeout (1000 ms). Took "
              + (System.currentTimeMillis() - now));
        }
      }
      

      The outcome is that the call takes ~3 seconds, not 1 s as expected. Also, when debugging, the InterruptException in SomeService#someSlowMethod(timeout) never occurs.

      Show
      Create a simple CDI-bean with the following method: SomeService.java @RequestScoped public class SomeService { @Timeout public String someSlowMethod( int timeToSleep) { try { Thread .sleep(timeToSleep); throw new RuntimeException( "Timeout did not interrupt" ); } catch (InterruptedException e) { // expected, but does not occur } return null ; } } and execute this test case: TimeoutTest.java @RunWith(Arquillian.class) @DefaultDeployment public class TimeoutTest { @Inject SomeService service; /** * A test to exercise the default timeout (1000 ms). * */ @Test public void testTimeout() { long now = System .currentTimeMillis(); try { service.someSlowMethod(3000); Assert.fail( "serviceA should throw a TimeoutException in testTimeout" ); } catch (TimeoutException ex) { // Expected } catch (RuntimeException ex) { // Not Expected Assert.fail( "serviceA should throw a TimeoutException in testTimeout not a RuntimeException" ); } System .out.println( "Total call should not exceed timeout (1000 ms). Took " + ( System .currentTimeMillis() - now)); } } The outcome is that the call takes ~3 seconds, not 1 s as expected. Also, when debugging, the InterruptException in SomeService#someSlowMethod(timeout) never occurs.

      Description

      A @Timeout annotation on a service method does not throw TimeoutException after specified timeout but rather when the method is done. The timeout should occur after the specified timeout and the execution thread should be interrupted. This has been tested on both wildflyswarm 2017.12.1 and 2018.1.0.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                mkouba Martin Kouba
                Reporter:
                enbohm Andreas Enbohm
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: