【发布时间】:2016-09-29 06:41:51
【问题描述】:
出于测试目的,我想模拟 Cloud Storage,因为它会减慢测试速度。
有谷歌云存储模拟器吗?
【问题讨论】:
-
看到这个答案stackoverflow.com/a/56804018/209288他们现在可能正在开发一个。
标签: google-cloud-storage cloud-storage
出于测试目的,我想模拟 Cloud Storage,因为它会减慢测试速度。
有谷歌云存储模拟器吗?
【问题讨论】:
标签: google-cloud-storage cloud-storage
Google 有一个in-memory emulator 可以使用(实现了大部分核心功能)。
您的测试类路径中需要com.google.cloud:google-cloud-nio(当前为:0.25.0-alpha)。然后您可以使用/注入由内存中LocalStorageHelper test-helper 服务实现的Storage 接口。
示例用法:
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper;
@Test
public void exampleInMemoryGoogleStorageTest() {
Storage storage = LocalStorageHelper.getOptions().getService();
final String blobPath = "test/path/foo.txt";
final String testBucketName = "test-bucket";
BlobInfo blobInfo = BlobInfo.newBuilder(
BlobId.of(testBucketName, blobPath)
).build();
storage.create(blobInfo, "randomContent".getBytes(StandardCharsets.UTF_8));
Iterable<Blob> allBlobsIter = storage.list(testBucketName).getValues();
// expect to find the blob we saved when iterating over bucket blobs
assertTrue(
StreamSupport.stream(allBlobsIter.spliterator(), false)
.map(BlobInfo::getName)
.anyMatch(blobPath::equals)
);
}
【讨论】:
暂时没有谷歌官方提供的模拟器。
我目前正在使用 Minio (https://www.minio.io/) 项目来模拟 Google Storage 在开发中的行为(Minio 使用文件系统作为存储后端并提供与 S3 apiV2 的兼容性,后者与 Google Storage 兼容)。
【讨论】: