我正在尝试使用localstack对SQS运行一些测试。但是,我仍然收到502。这对同事有效,但是在我的本地计算机,管道或docker上不起作用。该错误在每个地方都是相同的,所以我要发送docker版本,因为它可能更容易显示已安装的内容。
基本上,我正在创建一个docker映像,该映像安装java,python,并从/ 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"]
我的测试代码如下:
@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;
}
(...)
}
它失败并显示:
com.amazonaws.services.sqs.model.AmazonSQSException:空(服务:AmazonSQS;状态代码:502;错误代码:502错误的网关;请求ID:空)
在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1660) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeOneRequest(AmazonHttpClient.java:1324) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeHelper(AmazonHttpClient.java:1074) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.doExecute(AmazonHttpClient.java:745) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.executeWithTimer(AmazonHttpClient.java:719) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.execute(AmazonHttpClient.java:701) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutor.access $ 500(AmazonHttpClient.java:669) 在com.amazonaws.http.AmazonHttpClient $ RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:651) 在com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:515) 在com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2147) 在com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2116) 在com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2105) 在com.amazonaws.services.sqs.AmazonSQSClient.executeCreateQueue(AmazonSQSClient.java:756) 在com.amazonaws.services.sqs.AmazonSQSClient.createQueue(AmazonSQSClient.java:728) 在uk.co.sainsburys.giftcardservice.TimeoutQueueTest.setup(TimeoutQueueTest.java:76) 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在java.base / jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在java.base / jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在java.base / java.lang.reflect.Method.invoke(Method.java:566) 在org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50) 在org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) 在org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) 在org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24) 在org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) 在org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) 在org.springframework.test.context.junit4.statements.RunPrepareTestInstanceCallbacks.evaluate(RunPrepareTestInstanceCallbacks.java:64) 在org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) 在org.springframework.test.context.junit4.statements.SpringFailOnTimeout.evaluate(SpringFailOnTimeout.java:87) 在org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103) 在com.github.tomakehurst.wiremock.junit.WireMockRule $ 1.evaluate(WireMockRule.java:73) 在org.junit.rules.RunRules.evaluate(RunRules.java:20) 在org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) 在org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) 在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290) 在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71) 在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:58) 在org.junit.runners.ParentRunner上$ 2.evaluate(ParentRunner.java:268) 在org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) 在org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) 在org.springframework.test.context.junit4.statements.ProfileValueChecker.evaluate(ProfileValueChecker.java:103) 在org.springframework.test.context.junit4.rules.SpringClassRule $ TestContextManagerCacheEvictor.evaluate(SpringClassRule.java:190) 在org.junit.rules.RunRules.evaluate(RunRules.java:20) 在org.junit.runners.ParentRunner.run(ParentRunner.java:363) 在cloud.localstack.LocalstackTestRunner.run(LocalstackTestRunner.java:25) 在org.junit.runner.JUnitCore.run(JUnitCore.java:137) 在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) 在com.intellij.rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) 在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) 在com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
有什么想法吗?我想念什么?该代码似乎有效,因为它对我的同事有效(我亲眼所见)。他不记得在设置方面做过与我不同的事情。
我们都使用python 2.7.10,btw(如果有关系的话)。
答案 0 :(得分:1)
这很可能是由于测试开始运行时您的容器尚未准备好而发生的。您可以等待正常的健康检查或某些http路径,类似于:
@ClassRule
public static final LocalStackContainer localstack = new LocalStackContainer().withServices(SQS);
@Before
public void before(){
localstack.waitingFor(Wait.forHealthcheck()); //or Wait.forHttp("/")
}
答案 1 :(得分:-1)
尽量不要假设AWS服务始终健康。在AWS服务的后端,它们还具有容器,可以在其中关闭,旋转,重新启动其容器,并且还可以关闭,旋转或重新启动其所有容器支持服务。在这种情况下,您将需要进行健康检查,以确保可以推送或收听sqs。下面的线程可能会指出如何正确进行健康检查: