如何故意从服务器获得一个409 HTTP冲突响应?

huangapple go评论100阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月14日 01:05:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63400000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定