[英]502 when running SQS test using localstack
I'm trying to run some tests with SQS using localstack.我正在尝试使用 localstack 使用 SQS 运行一些测试。 However, I keep getting a 502. This works for a co-worker, but it doesn't work on my local machine, on our pipeline, or on docker.
但是,我一直收到 502。这适用于同事,但不适用于我的本地机器、我们的管道或 docker。 The error is the same everywhere, so I'm sending the docker version, since it's probably easier to show what's installed.
错误到处都是一样的,所以我发送了 docker 版本,因为它可能更容易显示已安装的内容。
Basically I'm creating a docker image that installs java, python, and executes the gradle build from the /repo folder, executing integration tests.基本上我正在创建一个安装 java、python 的 docker 镜像,并从 /repo 文件夹执行 gradle 构建,执行集成测试。
FROM openjdk:11.0.2-jdk-oraclelinux7
RUN ["yum", "install", "-y", "python", "python-pip"]
RUN ["pip", "install", "--upgrade", "pip"]
RUN ["pip", "install", "virtualenv"]
VOLUME ["/repo"]
ARG sourceDir
COPY ["${sourceDir}", "/repo"]
WORKDIR "/repo"
ENTRYPOINT ["/repo/gradlew", "clean", "integrationTest"]
My test code looks like this:我的测试代码如下所示:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@RunWith(LocalstackTestRunner.class)
public class TimeoutQueueTest {
private AmazonSQS client;
private static final String QUEUE_NAME = "my queue";
@LocalServerPort
private int port;
@ClassRule
public static final SpringClassRule springClassRule = new SpringClassRule();
@Rule
public final SpringMethodRule springMethodRule = new SpringMethodRule();
@Before
public void setup() {
Map<String, String> attributeMap = new HashMap<>();
attributeMap.put("DelaySeconds", "0");
attributeMap.put("MaximumMessageSize", "262144");
attributeMap.put("MessageRetentionPeriod", "1209600");
attributeMap.put("ReceiveMessageWaitTimeSeconds", "20");
attributeMap.put("VisibilityTimeout", "30");
client = TestUtils.getClientSQS();
CreateQueueRequest createQueueRequest = new CreateQueueRequest(QUEUE_NAME).withAttributes(attributeMap);
//FAILS IN THE LINE BELOW!!!!!!!!!!!!!!!!!!
String standardQueueUrl = client.createQueue(createQueueRequest).getQueueUrl();
RestAssured.port = port;
}
(...)
}
It fails with:它失败了:
com.amazonaws.services.sqs.model.AmazonSQSException: null (Service: AmazonSQS; Status Code: 502; Error Code: 502 Bad Gateway; Request ID: null)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1660)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1324)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1074)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:745)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:719)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:701)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:669)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:651)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:515)
at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2147)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2116)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2105)
at com.amazonaws.services.sqs.AmazonSQSClient.executeCreateQueue(AmazonSQSClient.java:756)
at com.amazonaws.services.sqs.AmazonSQSClient.createQueue(AmazonSQSClient.java:728)
at uk.co.sainsburys.giftcardservice.TimeoutQueueTest.setup(TimeoutQueueTest.java:76)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.RunPrepareTestInstanceCallbacks.evaluate(RunPrepareTestInstanceCallbacks.java:64)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.springframework.test.context.junit4.statements.SpringFailOnTimeout.evaluate(SpringFailOnTimeout.java:87)
at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103)
at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:73)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103)
at org.springframework.test.context.junit4.rules.SpringClassRule$TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:190)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cloud.localstack.LocalstackTestRunner.run(LocalstackTestRunner.java:25)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Any ideas?有任何想法吗? What am I missing?
我错过了什么? The code seems to work, since it's working for my co-worker (saw it with my own eyes).
该代码似乎有效,因为它正在为我的同事工作(亲眼所见)。 He doesn't remember having done anything different than me in terms of setup.
他不记得在设置方面做过与我不同的事情。
We're both using python 2.7.10, btw (if it matters).我们都在使用 python 2.7.10,顺便说一句(如果重要的话)。
Most likely this happens because your container is not ready yet by the time tests start running.发生这种情况很可能是因为在测试开始运行时您的容器尚未准备就绪。 You can wait for an ok healthcheck or some http path, something along the line of:
您可以等待 ok healthcheck 或一些 http 路径,如下所示:
@ClassRule
public static final LocalStackContainer localstack = new LocalStackContainer().withServices(SQS);
@Before
public void before(){
localstack.waitingFor(Wait.forHealthcheck()); //or Wait.forHttp("/")
}
Try not to make assumption that AWS services are healthy at all times.尽量不要假设 AWS 服务在任何时候都是健康的。 In the backend of AWS services, they also have containers, where their containers can be shut down, rotated, restarted, and all their container supporting services may also be shut down, rotated or restarted.
在AWS服务的后端,他们也有容器,他们的容器可以在这里关闭、轮转、重启,他们所有的容器支持服务也可以关闭、轮转或重启。 In this case, you will need a health check to ensure that sqs is ready to be pushed or listened to.
在这种情况下,您将需要进行健康检查以确保 sqs 已准备好被推送或收听。 The thread below may point you to how to properly listen with a health check:
下面的线程可能会告诉您如何通过健康检查正确收听:
Spring Boot Health Check - SQS Consumer Spring Boot 健康检查 - SQS 消费者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.