简体   繁体   English

使用 localstack 运行 SQS 测试时出现 502

[英]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.

相关问题 Laravel 使用 localstack 清除所有 SQS 队列 - Laravel clear all SQS queues using localstack 用于 localstack 的 AWS CLI SQS - 无法设置队列属性 - AWS CLI SQS for localstack - cannot set queue attribute boto3 和 lambda:使用 DynamoDB 资源和 localstack 时参数 KeyConditionExpression 的类型无效 - boto3 and lambda: Invalid type for parameter KeyConditionExpression when using DynamoDB resource and localstack 针对 LocalStack 运行 CDK 引导程序失败并出现凭据错误 - Running CDK bootstrap against LocalStack fails with credentials error 创建消息时为消息设置 AWS SQS 可见性超时 - Set AWS SQS visibility timeout for a message when creating the message 触发IOT规则时如何传递SQS属性? - How to pass SQS attributes when IOT rule is triggered? Google Cloud Dataflow:ModuleNotFoundError:运行集成测试时没有名为“main”的模块 - Google Cloud Dataflow: ModuleNotFoundError: No module named 'main' when running integration test 无服务器图像处理程序请求大文件大小时出现 502 错误 - 502 error when Serverless image handler requests a large file size 来自守护进程的错误响应:没有这样的图像:localstack/localstack:0.14.0 - Error response from daemon: No such image: localstack/localstack:0.14.0 Kubernetes GKE 502 服务器错误在多次重新加载时无法选择后端 - Kubernetes GKE 502 server error failed to pick backend when reloaded multiple times
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM