Skip to content

Commit

Permalink
GH-148: Test for @Retryable with an XML config
Browse files Browse the repository at this point in the history
Fixes: #148
Issue link: #148
  • Loading branch information
artembilan committed Sep 12, 2024
1 parent 74b7ae2 commit 5493ab7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}

}

}
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit 5493ab7

Please sign in to comment.