|
| 1 | +/* |
| 2 | + * Copyright 2019 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.retry.annotation; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import org.springframework.beans.factory.annotation.Autowired; |
| 22 | +import org.springframework.context.annotation.Bean; |
| 23 | +import org.springframework.context.annotation.Configuration; |
| 24 | +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; |
| 25 | + |
| 26 | +import static org.assertj.core.api.Assertions.assertThat; |
| 27 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
| 28 | + |
| 29 | +/** |
| 30 | + * @author Gary Russell |
| 31 | + * @since 1.3.4 |
| 32 | + */ |
| 33 | +@SpringJUnitConfig |
| 34 | +public class DontRetryRecovererTests { |
| 35 | + |
| 36 | + @Test |
| 37 | + void dontRetry(@Autowired Service service) { |
| 38 | + assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> service.foo("x")).withMessage("test"); |
| 39 | + assertThat(service.getCallCount()).isEqualTo(3); |
| 40 | + assertThat(service.getRecoverCount()).isEqualTo(1); |
| 41 | + } |
| 42 | + |
| 43 | + @Configuration |
| 44 | + @EnableRetry |
| 45 | + public static class Config { |
| 46 | + |
| 47 | + @Bean |
| 48 | + Service service() { |
| 49 | + return new Service(); |
| 50 | + } |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + @Retryable |
| 55 | + public static class Service { |
| 56 | + |
| 57 | + int callCount; |
| 58 | + |
| 59 | + int recoverCount; |
| 60 | + |
| 61 | + public void foo(String in) { |
| 62 | + callCount++; |
| 63 | + throw new RuntimeException(); |
| 64 | + } |
| 65 | + |
| 66 | + @Recover |
| 67 | + public void recover(Exception ex, String in) { |
| 68 | + this.recoverCount++; |
| 69 | + throw new RuntimeException("test"); |
| 70 | + } |
| 71 | + |
| 72 | + public int getCallCount() { |
| 73 | + return callCount; |
| 74 | + } |
| 75 | + |
| 76 | + public int getRecoverCount() { |
| 77 | + return recoverCount; |
| 78 | + } |
| 79 | + |
| 80 | + } |
| 81 | + |
| 82 | +} |
0 commit comments