我试图使用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: 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)
有什么想法吗?我错过了什么?代码似乎很有效,因为它是为我的同事工作的(我亲眼看到的)。他不记得在设置方面做过任何与我不同的事情。
顺便说一句,我们都在使用python 2.7.10(如果有必要的话)。
尽量不要假设AWS服务在任何时候都是健康的。在AWS服务的后端,他们也有容器,在那里他们的容器可以被关闭、旋转、重新启动,他们所有的容器支持服务也可能被关闭、旋转或重新启动。在这种情况下,您将需要进行健康检查,以确保sqs已准备好被推送或收听。下面的线程可能会向您指出如何通过健康检查正确收听:
Spring Boot健康检查-SQS消费者
这很可能是因为您的容器在测试开始运行时还没有准备好。您可以等待确定的健康检查或一些超文本传输协议路径,大致如下:
@ClassRule
public static final LocalStackContainer localstack = new LocalStackContainer().withServices(SQS);
@Before
public void before(){
localstack.waitingFor(Wait.forHealthcheck()); //or Wait.forHttp("/")
}
我尝试用LocalStack运行lambda函数。我安装了awscli-local和localstack pip3安装awscli-local pip3安装--用户localstack--忽略-安装六个 然后我启动了localstack lamdba_executor=Docker本地堆栈启动--Docker 当我现在要创建lambda函数时 aws lambda create-function-
我正在尝试利用localstack来进行本地AWS模拟测试。具体地说,我希望使用Apache CamelS3路由从LocalStackS3桶下载一个文件。然而,我遇到了错误。以下是我采取的步骤... 然后,我上传了一个测试文件到这个桶里... 两个操作都成功完成。在我的Java代码中,我创建了一个CDI生成器来生成com.amazonaws.services.s3.amazons3客户端对象...
我们已经为spark编写了单元测试,在本地模式下有4个线程。 当一个接一个地启动时,例如通过intellij或sbt testOnly,每个测试都运行良好。 当用sbt测试启动时,它们会出现如下错误 我们使用的是一个带有多个子项目的sbt项目,其定义如下:
我正在尝试运行一个使用Mockito的JUnit cucumber测试。这是我遇到的问题。在我的cucumber赛跑课上,我有 在我的常规JUnit测试中 鉴于我一次只能有一个@RunWith,我如何将Mockito与cucumber结合使用呢?
我有一个文件夹结构如下 当我运行命令时。它只运行Java单元测试(位于*src\test\Java*目录下),而不调用Groovy测试用例。Groovy似乎再也找不到Groovy测试了。 请帮助我在Maven的帮助下启用groovy测试用例执行? 波姆。xml
就像 会编译代码并运行生成的二进制文件一样,cargo test 在测试模式下编译代码并运行生成的测试二进制文件。可以指定命令行参数来改变 cargo test 的默认行为。例如,cargo test 生成的二进制文件的默认行为是并行的运行所有测试,并捕获测试运行过程中产生的输出避免他们被显示出来,使得阅读测试结果相关的内容变得更容易。 这些选项的一部分可以传递给 cargo test,而另一些则