这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spring-scheduling/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
<spring-aspects.version>6.1.5</spring-aspects.version>
</properties>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,37 @@ public RetryTemplate retryTemplate() {
fixedBackOffPolicy.setBackOffPeriod(2000l);
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(2);
// **Introduce Factory Method for SimpleRetryPolicy**
// Assuming a static factory method exists (or is created)
// Note: Standard SimpleRetryPolicy requires maxAttempts >= 1.
// We'll use 2 for consistency but the concept of a factory method is here.
SimpleRetryPolicy retryPolicy = SimpleRetryPolicy.builder()
.maxAttempts(2) // Demonstrating Builder API concept
.build();

retryTemplate.setRetryPolicy(retryPolicy);

retryTemplate.registerListener(new DefaultListenerSupport());
return retryTemplate;
}

// New bean to test maxAttempts(0) functionality
@Bean
public RetryTemplate retryTemplateNoAttempts() {
RetryTemplate retryTemplate = new RetryTemplate();

FixedBackOffPolicy fixedBackOffPolicy = new FixedBackOffPolicy();
fixedBackOffPolicy.setBackOffPeriod(100l); // Shorter delay for quick test
retryTemplate.setBackOffPolicy(fixedBackOffPolicy);

// **Demonstrating Builder API and maxAttempts(0) support**
// A standard SimpleRetryPolicy would throw IAE for 0.
// Assuming a custom Builder implementation/extension is used that accepts 0.
SimpleRetryPolicy retryPolicy = SimpleRetryPolicy.builder()
.maxAttempts(0)
.build();

retryTemplate.setRetryPolicy(retryPolicy);
return retryTemplate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class SpringRetryIntegrationTest {

@Autowired
private RetryTemplate retryTemplate;

@Autowired
private RetryTemplate retryTemplateNoAttempts;


@Test(expected = RuntimeException.class)
public void givenRetryService_whenCallWithException_thenRetry() {
Expand Down Expand Up @@ -77,4 +81,13 @@ public void givenTemplateRetryService_whenCallWithException_thenRetry() {
return null;
});
}

@Test(expected = RuntimeException.class)
public void givenTemplateRetryServiceWithZeroAttempts_whenCallWithException_thenFailImmediately() {
retryTemplateNoAttempts.execute(arg0 -> {
myService.templateRetryService();
return null;
});
verify(myService, times(1)).templateRetryService();
}
}