【问题标题】:Is there Google Cloud Storage emulator? [closed]有谷歌云存储模拟器吗? [关闭]
【发布时间】:2016-09-29 06:41:51
【问题描述】:

出于测试目的,我想模拟 Cloud Storage,因为它会减慢测试速度。

有谷歌云存储模拟器吗?

【问题讨论】:

标签: google-cloud-storage cloud-storage


【解决方案1】:

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)
    );
  }

【讨论】:

【解决方案2】:

暂时没有谷歌官方提供的模拟器。

我目前正在使用 Minio (https://www.minio.io/) 项目来模拟 Google Storage 在开发中的行为(Minio 使用文件系统作为存储后端并提供与 S3 apiV2 的兼容性,后者与 Google Storage 兼容)。

【讨论】:

  • 您能否提供一些有关设置的详细信息?
  • 如果您能提供一些细节,我也很高兴。您是否能够创建指向本地 MinIO 实例的存储/存储桶引用?或者您只是模拟调用 Cloud Storage API 的服务并通过模拟服务存储文件?
  • 我无法再访问项目设置,但自从我回答了这个问题后,Google 开发了一个存储模拟器:github.com/googleapis/google-cloud-java/blob/master/…
  • 那个模拟器好像只是一个java类,实现了java客户端的云存储接口,所以真的是专供java开发者使用的
猜你喜欢
  • 2021-07-07
  • 1970-01-01
  • 2018-08-13
  • 1970-01-01
  • 2020-09-10
  • 2017-10-18
  • 2012-07-26
  • 2019-11-08
  • 2016-10-12
相关资源
最近更新 更多