/** * Get the {@code timeout} configured via the {@link Timed @Timed} * annotation on the supplied {@code method}. * <p>Negative configured values will be converted to {@code 0}. * @return the configured timeout, or {@code 0} if the method is not * annotated with {@code @Timed} */ public static long getTimeout(Method method) { Timed timed = AnnotatedElementUtils.findMergedAnnotation(method, Timed.class); if (timed == null) { return 0; } return Math.max(0, timed.millis()); }
@Test @Timed(millis = 100) public void springTimeoutWithSleep() throws Exception { Thread.sleep(200); }
@Test @Timed(millis = 2000) public void springTimeoutWithNoOp() { /* no-op */ }
/** * Get the {@code timeout} configured via the {@link Timed @Timed} * annotation on the supplied {@code method}. * <p>Negative configured values will be converted to {@code 0}. * @return the configured timeout, or {@code 0} if the method is not * annotated with {@code @Timed} */ public static long getTimeout(Method method) { Timed timed = AnnotatedElementUtils.findMergedAnnotation(method, Timed.class); if (timed == null) { return 0; } return Math.max(0, timed.millis()); }
@Test(timeout = 200) @Timed(millis = 200) public void springAndJUnitTimeouts() { /* no-op */ } }
/** * Get the {@code timeout} configured via the {@link Timed @Timed} * annotation on the supplied {@code method}. * <p>Negative configured values will be converted to {@code 0}. * @return the configured timeout, or {@code 0} if the method is not * annotated with {@code @Timed} */ public static long getTimeout(Method method) { Timed timed = AnnotatedElementUtils.findMergedAnnotation(method, Timed.class); if (timed == null) { return 0; } return Math.max(0, timed.millis()); }
@Test @Timed(millis = 10000) public void nonAnnotated() throws Exception { incrementInvocationCount(); } }
@Test @Timed(millis = 10000) public void nonAnnotated() throws Exception { incrementInvocationCount(); } }
@Test @Timed(millis = 100) @Repeat(10) public void collectiveRepetitionsExceedTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(11); } }
@Test @Timed(millis = 20) @Repeat(4) public void firstRepetitionOfManyExceedsTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(25); }
@Test @Transactional(propagation = Propagation.NOT_SUPPORTED) @Timed(millis = 10000) @Repeat(5) public void notTransactionalWithSpringTimeout() { assertInTransaction(false); }
@Test @Timed(millis = 10) @Repeat(1) public void singleRepetitionExceedsTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(15); }
@Test @Timed(millis = 20) @Repeat(4) public void firstRepetitionOfManyExceedsTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(25); }
@Test @Timed(millis = 10) @Repeat(1) public void singleRepetitionExceedsTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(15); }
@Test @Timed(millis = 100) @Repeat(10) public void collectiveRepetitionsExceedTimeout() throws Exception { incrementInvocationCount(); Thread.sleep(11); } }
@Test @Repeat @Timed(millis = 10000) public void defaultRepeatValue() throws Exception { incrementInvocationCount(); } }
@Test @Repeat(-5) @Timed(millis = 10000) public void negativeRepeatValue() throws Exception { incrementInvocationCount(); } }
@Test @Timed(millis = 1000) @Repeat(5) public void repeatedFiveTimesButDoesNotExceedTimeout() throws Exception { incrementInvocationCount(); }