【问题标题】:S3Client Unable to load credentials in QuarkusTest, using QuarkusTestResourceLifecycleManager in quarkus 2+S3Client 无法在 QuarkusTest 中加载凭据,在 quarkus 2+ 中使用 QuarkusTestResourceLifecycleManager
【发布时间】:2021-12-02 03:02:40
【问题描述】:

当我将 quarkus 从 1.13.2 升级到 2.X.X 时,我的集成测试中出现“无法加载凭据”错误。

LambdaIntegTest.class :

@Testcontainers
@QuarkusTest
@QuarkusTestResource(ContainerRessource.class)
class LambdaIntegTest {

    @Test
    void test() throws Exception {
        String s3Event = oneS3event();

        String out = LambdaClient.invokeJson(String.class, s3Event);

        assertThat(out).isEqualTo("Success");
    }

ContainerRessource.class:

public class ContainerRessource implements QuarkusTestResourceLifecycleManager {
    private static final LocalStackContainer LOCAL_STACK_CONTAINER;

    static {
        DockerImageName localstackImage = DockerImageName.parse("localstack/localstack:0.11.3");
        LOCAL_STACK_CONTAINER = new LocalStackContainer(localstackImage)
            .withServices(S3);
    }

    @Override
    public Map<String, String> start() {
        LOCAL_STACK_CONTAINER.start();
        innitS3();
        return Map.ofEntries(
            entry("aws.region", LOCAL_STACK_CONTAINER.getRegion()),
            entry("s3.url.override", LOCAL_STACK_CONTAINER.getEndpointOverride(S3).toString()),
            entry("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey()),
            entry("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey()));
    }

    @Override
    public void stop() {
        LOCAL_STACK_CONTAINER.stop();
    }
}

我尝试将凭据放入 application.properties,但我遇到了同样的错误。 我在 Quarkus 1.13.2 上的测试工作

我还有一个原生测试:

@QuarkusIntegrationTest
public class LambdaNativeTest extends LambdaIntegTest {
}

它奏效了。

【问题讨论】:

    标签: java amazon-s3 quarkus testcontainers localstack


    【解决方案1】:

    我找到了一种解决方法,如果我们在系统属性中手动设置凭据,它就可以工作。 修改后的方法 start() :

     @Override
        public Map<String, String> start() {
            LOCAL_STACK_CONTAINER.start();
            innitS3();
            System.setProperty("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey());
            System.setProperty("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey());
            return Map.ofEntries(
                entry("aws.region", LOCAL_STACK_CONTAINER.getRegion()),
                entry("s3.url.override", LOCAL_STACK_CONTAINER.getEndpointOverride(S3).toString()),
                entry("aws.accessKeyId", LOCAL_STACK_CONTAINER.getAccessKey()),
                entry("aws.secretAccessKey", LOCAL_STACK_CONTAINER.getSecretKey()));
        }
    

    QuarkusTestResourceLifecycleManager.start() 的 Javadoc 说: '@return 应该为正在运行的测试设置的系统属性映射'

    这似乎不适用于@QuarkusTest

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多