|
| 1 | +/* |
| 2 | + * Copyright 2024-2024 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.test.context.junit.jupiter.SpringJUnitConfig; |
| 23 | + |
| 24 | +import static org.assertj.core.api.Assertions.assertThat; |
| 25 | + |
| 26 | +/** |
| 27 | + * @author Artem Bilan |
| 28 | + * @since 2.0.9 |
| 29 | + */ |
| 30 | +@SpringJUnitConfig |
| 31 | +public class RetryableXmlConfigTests { |
| 32 | + |
| 33 | + @Autowired |
| 34 | + Service service; |
| 35 | + |
| 36 | + @Test |
| 37 | + void serviceCallIsRetied() { |
| 38 | + this.service.service(); |
| 39 | + assertThat(service.getCount()).isEqualTo(3); |
| 40 | + } |
| 41 | + |
| 42 | + public static class Service { |
| 43 | + |
| 44 | + private int count = 0; |
| 45 | + |
| 46 | + @Retryable |
| 47 | + public void service() { |
| 48 | + if (this.count++ < 2) { |
| 49 | + throw new RuntimeException("Planned"); |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + public int getCount() { |
| 54 | + return this.count; |
| 55 | + } |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | +} |
0 commit comments