标签: s3proxy

用于集成测试的 AWS S3 Java Embedded Mock

在互联网上搜索嵌入式 Java AWS S3 模拟的良好解决方案后,S3NinjaS3Proxy似乎是最受欢迎的解决方案。

但是,似乎没有一种简单的方法可以以编程方式启动它们。放弃 S3Ninja 后,我尝试使用 S3Proxy 来完成,但效果不佳。

Maven 依赖项

<dependency>
    <groupId>org.gaul</groupId>
    <artifactId>s3proxy</artifactId>
    <version>${s3proxy.version}</version>
    <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

代码

String endpoint = "http://127.0.0.1:8085";
URI uri = URI.create(endpoint);
Properties properties = new Properties();
properties.setProperty("s3proxy.authorization", "none");
properties.setProperty("s3proxy.endpoint", endpoint);
properties.setProperty("jclouds.provider", "filesystem");
properties.setProperty("jclouds.filesystem.basedir", "/tmp/s3proxy");

ContextBuilder builder = ContextBuilder
        .newBuilder("filesystem")
        .credentials("x", "x")
        .modules(ImmutableList.<Module>of(new SLF4JLoggingModule()))
        .overrides(properties);
BlobStoreContext context = builder.build(BlobStoreContext.class);
BlobStore blobStore = context.getBlobStore();

S3Proxy s3Proxy = S3Proxy.builder().awsAuthentication("x", "x").endpoint(uri).keyStore("", "").blobStore(blobStore).build();
s3Proxy.start();

BasicAWSCredentials awsCredentials = new BasicAWSCredentials("x", "x");

AmazonS3Client client = new AmazonS3Client(awsCredentials, …
Run Code Online (Sandbox Code Playgroud)

java integration-testing amazon-s3 amazon-web-services s3proxy

6
推荐指数
1
解决办法
2847
查看次数