英文:
How to purposely get a 409 HTTP Conflict response from a server?
问题
我们正在使用Spring Retry实现针对HTTP 409冲突响应的重试机制,有时我们在生产服务器上会收到这种响应。
但我们想知道如何有意地让服务器以409状态代码响应?在我们的情况下,错误似乎每当我们尝试并行加载大量数据时都会发生;由于发生的概率似乎相当随机,是否有一种方法可以在测试目的下获得一致的结果?
英文:
We are implementing a retry mechanism (using Spring Retry) for http 409 Conflict responses, which we sometimes get on the production server.
But we wonder how to purposely get a server to respond with a 409 status code? In our cases, the error seems to happen whenever we try to load a lot of data in parallel; since the probability of it happening seems quite random, is there a method to get it consistently for testing purposes?
答案1
得分: 3
这是要翻译的内容:
"好吧,可能有多种可能的方法来实现这个,您需要澄清您希望在哪里引发409错误,
我假设(这是Spring Boot应用程序)您的一个服务(A)调用另一个服务/API(B),您希望它引发409错误。
如果是这种情况,您可以编写**@RunWith(SpringRunner.class)/@SpringBootTest**测试,并模拟来自服务/API B的409响应,然后测试您的重试机制。"
英文:
Well, There might be multiple possible ways to do so, You need to clarify where exactly you need 409 to be thrown ,
I assume (Its spring boot app) from one of your service (A) calls to another service/API(B) and you expect it to throw 409.
If that's the case, you can write @RunWith(SpringRunner.class)/@SpringBootTest test and mock the response from service/API B with 409 and test your retry mechanism.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论