GH-148: Test for @Retryable with an XML config
Fixes: #148 Issue link: https://github.com/spring-projects/spring-retry/issues/148
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2024-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.retry.annotation;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @since 2.0.9
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
public class RetryableXmlConfigTests {
|
||||
|
||||
@Autowired
|
||||
Service service;
|
||||
|
||||
@Test
|
||||
void serviceCallIsRetied() {
|
||||
this.service.service();
|
||||
assertThat(service.getCount()).isEqualTo(3);
|
||||
}
|
||||
|
||||
public static class Service {
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@Retryable
|
||||
public void service() {
|
||||
if (this.count++ < 2) {
|
||||
throw new RuntimeException("Planned");
|
||||
}
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:aop="http://www.springframework.org/schema/aop"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">
|
||||
|
||||
<aop:aspectj-autoproxy/>
|
||||
|
||||
<bean class="org.springframework.retry.annotation.RetryConfiguration"/>
|
||||
|
||||
<bean class="org.springframework.retry.annotation.RetryableXmlConfigTests.Service"/>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user