如何在单元测试中覆盖 Quarkus @Retry.delay?
How to override Quarkus @Retry.delay in a unit test?
我有一个方法:
@Retry(retryOn = SomeException.class, maxRetries = 5, delay = 180000, maxDuration = 360000)
public void checkIfSomethingIsReady() {
if (something != ready) {
throw new SomeException();
} else {
// do stuff
}
}
我正在尝试对这样的方法进行一些边界测试,而无需等待或重试。有没有办法仅为测试覆盖此配置?
是的,你可以,
MicroProfile Fault Tolerance also allows configuration using
MicroProfile Config. For example:
com.example.MyService/hello/Retry/delay=5
对于以下代码示例:
@Singleton
public class MyService {
@Retry(maxRetries = 10, delay = 180000, retryOn = IOException.class)
public String hello() {
...
}
}
因此会是 packagePath.ClassName/methodName/Retry/delay=yourNumber
对于测试,只需要一个具有不同值的不同属性文件即可。
https://smallrye.io/docs/smallrye-fault-tolerance/5.0.0/usage/basic.html#_configuration
我有一个方法:
@Retry(retryOn = SomeException.class, maxRetries = 5, delay = 180000, maxDuration = 360000)
public void checkIfSomethingIsReady() {
if (something != ready) {
throw new SomeException();
} else {
// do stuff
}
}
我正在尝试对这样的方法进行一些边界测试,而无需等待或重试。有没有办法仅为测试覆盖此配置?
是的,你可以,
MicroProfile Fault Tolerance also allows configuration using MicroProfile Config. For example:
com.example.MyService/hello/Retry/delay=5
对于以下代码示例:
@Singleton
public class MyService {
@Retry(maxRetries = 10, delay = 180000, retryOn = IOException.class)
public String hello() {
...
}
}
因此会是 packagePath.ClassName/methodName/Retry/delay=yourNumber
对于测试,只需要一个具有不同值的不同属性文件即可。
https://smallrye.io/docs/smallrye-fault-tolerance/5.0.0/usage/basic.html#_configuration