gpt4 book ai didi

java - 用于集成测试的 AWS S3 Java 嵌入式模拟

转载 作者:搜寻专家 更新时间:2023-11-01 03:18:31 27 4
gpt4 key购买 nike

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

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

Maven 依赖项

<dependency>
<groupId>org.gaul</groupId>
<artifactId>s3proxy</artifactId>
<version>${s3proxy.version}</version>
<scope>test</scope>
</dependency>

代码

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, new ClientConfiguration());
client.setEndpoint(endpoint);

// Should Throw AWS Client Exception as Bucket / Key does not exist!
GetObjectRequest objectRequest = new GetObjectRequest("bucket", "key");
S3Object object = client.getObject(objectRequest);

s3Proxy.stop();

异常

java.lang.NoSuchMethodError: com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.<init>(Lcom/google/gson/internal/ConstructorConstructor;Lcom/google/gson/FieldNamingStrategy;Lcom/google/gson/internal/Excluder;)V

at org.jclouds.json.internal.DeserializationConstructorAndReflectiveTypeAdapterFactory.<init>(DeserializationConstructorAndReflectiveTypeAdapterFactory.java:116)
at org.jclouds.json.config.GsonModule.provideGson(GsonModule.java:129)

...

at org.jclouds.providers.config.BindProviderMetadataContextAndCredentials.backend(BindProviderMetadataContextAndCredentials.java:84)

...

at org.jclouds.ContextBuilder.build(ContextBuilder.java:581)

非常感谢任何帮助。我确信这对于许多与 AWS S3 交互的 Java 集成测试来说是一个很大的要求。

最佳答案

只是评论原因是因为您的项目正在使用冲突版本的 gson。 S3Proxy 的 dep 需要 gson 2.5。

关于java - 用于集成测试的 AWS S3 Java 嵌入式模拟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39170115/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com