0

I am using Spring Feign clients. Is there a way to get the time it took for a response to be received after a request was sent? I have a lot of requests mapped and would like a clean way to assert in tests that a response was received within a certain time.

Thanks

Jusbat
  • 40
  • 5

2 Answers2

0

You can use System.nanoTime():

long startTime = System.nanoTime();

// make your request

long elapsedTime = System.nanoTime()-startTime;
spectrum
  • 379
  • 4
  • 11
0

You can do this with a generic method as well. Please find snippet below:

   myMethod() { 
    Date startDate = new Date();
.... body 
    return timedReturn(LOGGER, new Object() {}.getClass().getEnclosingMethod().getName(), startDate.getTime(), response);
    } 


public class MY_Utilities {
public static <T> T timedReturn(final Logger LOGGER, String method, long start, T object) {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(String.format("Execution of method %s took %05d ms", method, System.currentTimeMillis() - start));
    }

    return object;
}

}