Java 用于集成测试的 AWS S3 本地服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23991694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:36:13  来源:igfitidea点击:

AWS S3 local server for integration testing

javaamazon-web-servicesjenkinsamazon-s3

提问by oggmonster

I have some code that uploads and downloads files using AWS S3 (using the Java AWS SDK). I want to be able to write some tests for it, I was wondering if anyone has any good options. Ideally I would like a light-weight S3 server that runs locally that can be started fast and requires no system configuration (the tests need to be run by Jenkins).

我有一些使用 AWS S3(使用 Java AWS SDK)上传和下载文件的代码。我希望能够为它编写一些测试,我想知道是否有人有任何好的选择。理想情况下,我想要一个在本地运行的轻量级 S3 服务器,它可以快速启动并且不需要系统配置(测试需要由 Jenkins 运行)。

Some options I have looked at so far:

到目前为止我看过的一些选项:

  1. FakeS3- Almost exactly what I'm looking for, however, when using the Java AWS SDK, you must edit your /etc/hosts file and restart networking, not something I can do in Jenkins. Also when trying it out there seems to be a bug with the creation date field being formatted wrong which makes my client throw an exception, which doesn't inspire me with much confidence in the project.
  2. Ceph- Implements S3 API but takes several minutes to install
  1. FakeS3- 几乎正是我正在寻找的东西,但是,在使用 Java AWS SDK 时,您必须编辑 /etc/hosts 文件并重新启动网络,而我在 Jenkins 中无法做到这一点。此外,在尝试时,似乎存在创建日期字段格式错误的错误,这使我的客户抛出异常,这并没有激发我对项目的信心。
  2. Ceph- 实现 S3 API,但需要几分钟才能安装

回答by Anthony Hobbs

I created different buckets to use for the different use cases. For example: my-dev-bucket and my-prod-bucket. I don't know if this meets your use criteria but you might want to consider it. The side benefit is it makes your pre production and production code follow the exact same flows.

我创建了不同的存储桶以用于不同的用例。例如:my-dev-bucket 和 my-prod-bucket。我不知道这是否符合您的使用标准,但您可能需要考虑一下。附带的好处是它使您的预生产和生产代码遵循完全相同的流程。

回答by koolhead17

You can try installing minioserver on your laptop/system, its open source & single static binary. Server is S3 compatible. Then you can try minio-java client libraryfor all operations, following is basic operations example.

您可以尝试在您的笔记本电脑/系统上安装minio服务器,它的开源和单一静态二进制文件。服务器与 S3 兼容。然后您可以尝试使用minio-java 客户端库进行所有操作,以下是基本操作示例

Installing minio server [GNU/Linux]

安装 minio 服务器 [GNU/Linux]

$ wget https://dl.minio.io/server/minio/release/linux-amd64/minio
$ chmod 755 minio
$ ./minio --help  

Hope it helps Disclaimer: I work for Minio

希望对您有所帮助免责声明:我为Minio工作

回答by RalfU

I started a S3 Server API project for Ladon, it contains a simple File System Repository. Its a Java Project and contains a Spring Boot Starter for simple testing. Not all S3 API features are supported yet but I will add them on request. Its on Github: Ladon S3 Server

我为 Ladon 启动了一个 S3 服务器 API 项目,它包含一个简单的文件系统存储库。它是一个 Java 项目,包含一个用于简单测试的 Spring Boot Starter。并非所有 S3 API 功能都受支持,但我会根据要求添加它们。它在 Github 上:Ladon S3 服务器

回答by Ian Bytchek

Late answer, will be useful mostly for Docker users. There's a great S3 compatible storage software called Riak CSand there's docker-riak-csimage that allows to quickly launch the server.

迟到的答案,主要对 Docker 用户有用。有一个很棒的 S3 兼容存储软件叫做Riak CS,还有一个docker-riak-cs镜像可以快速启动服务器。

I've been using it for nearly 2 years for local development and integration testing with great success. It has some limitations, but nothing major that comes in the way, see api / compatibility documentation.

我已经使用它进行了近 2 年的本地开发和集成测试,并取得了巨大的成功。它有一些限制,但没有什么大碍,请参阅 api/兼容性文档

If you need Docker-less solution, you can set it up locally for each build, all setup and configuration scripts are available in docker-riak-csrepository.

如果您需要 Docker-less 解决方案,您可以为每个构建在本地设置它,所有设置和配置脚本都可以在docker-riak-cs存储库中找到。

回答by Artur Gajowy

findify/s3mock- an in-process, Java S3 server aimed at testing. Didn't test it - just stumbled upon it. Needs no docker, which might be an advantage. HTH! :)

findify/s3mock- 一个用于测试的进程内 Java S3 服务器。没有测试它 - 只是偶然发现它。不需要 docker,这可能是一个优势。哼!:)

回答by Flux

You can try localstack, which is an open source local AWS cloud stack made for testing. It provides implementations of several of AWS services, including S3.

您可以尝试localstack,这是一个用于测试的开源本地 AWS 云堆栈。它提供了多种 AWS 服务的实现,包括 S3。

It looks like a very popular open source project on GitHub.

它看起来像是 GitHub 上一个非常流行的开源项目。