Evg*_*nko 12 cloud-storage google-cloud-storage
出于测试目的,我想模拟云存储,因为它会减慢测试速度.
是否有Google云端存储模拟器?
Tho*_*sMH 13
谷歌有一个你可以使用的内存模拟器(大部分核心功能都已实现).
您需要com.google.cloud:google-cloud-nio
在测试类路径(:0.25.0-alpha
当前)上.然后你可以使用Storage
内存LocalStorageHelper
测试助手服务实现的/ inject 接口.
用法示例:
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)
);
}
Run Code Online (Sandbox Code Playgroud)
小智 6
目前还没有Google提供的官方模拟器.
我目前正在使用项目Minio(https://www.minio.io/)来模拟Google Storage在开发中的行为(Minio使用文件系统作为存储后端,并提供与S3 apiV2的兼容性,后者与Google存储兼容).
归档时间: |
|
查看次数: |
6074 次 |
最近记录: |