当前位置: 首页>>代码示例>>Java>>正文


Java Bucket类代码示例

本文整理汇总了Java中com.google.api.services.storage.model.Bucket的典型用法代码示例。如果您正苦于以下问题:Java Bucket类的具体用法?Java Bucket怎么用?Java Bucket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Bucket类属于com.google.api.services.storage.model包,在下文中一共展示了Bucket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateBucket

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testCreateBucket() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
         any(String.class), any(Bucket.class))).thenReturn(mockStorageInsert);
  when(mockStorageInsert.execute())
      .thenThrow(new SocketTimeoutException("SocketException"))
      .thenReturn(new Bucket());

  gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}
 
开发者ID:apache,项目名称:beam,代码行数:23,代码来源:GcsUtilTest.java

示例2: testCreateBucketAccessErrors

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testCreateBucketAccessErrors() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage.Buckets.Insert mockStorageInsert = Mockito.mock(Storage.Buckets.Insert.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(FluentBackoff.DEFAULT.backoff());
  GoogleJsonResponseException expectedException =
      googleJsonResponseException(HttpStatusCodes.STATUS_CODE_FORBIDDEN,
          "Waves hand mysteriously", "These aren't the buckets you're looking for");

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.insert(
         any(String.class), any(Bucket.class))).thenReturn(mockStorageInsert);
  when(mockStorageInsert.execute())
      .thenThrow(expectedException);

  thrown.expect(AccessDeniedException.class);

  gcsUtil.createBucket("a", new Bucket(), mockBackOff, new FastNanoClockAndSleeper());
}
 
开发者ID:apache,项目名称:beam,代码行数:27,代码来源:GcsUtilTest.java

示例3: testBucketAccessible

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testBucketAccessible() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage.Buckets.Get mockStorageGet = Mockito.mock(Storage.Buckets.Get.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(
      FluentBackoff.DEFAULT.backoff());

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet);
  when(mockStorageGet.execute())
      .thenThrow(new SocketTimeoutException("SocketException"))
      .thenReturn(new Bucket());

  assertTrue(gcsUtil.bucketAccessible(GcsPath.fromComponents("testbucket", "testobject"),
      mockBackOff, new FastNanoClockAndSleeper()));
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:GcsUtilTest.java

示例4: testGetBucket

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testGetBucket() throws IOException {
  GcsOptions pipelineOptions = gcsOptionsWithTestCredential();
  GcsUtil gcsUtil = pipelineOptions.getGcsUtil();

  Storage mockStorage = Mockito.mock(Storage.class);
  gcsUtil.setStorageClient(mockStorage);

  Storage.Buckets mockStorageObjects = Mockito.mock(Storage.Buckets.class);
  Storage.Buckets.Get mockStorageGet = Mockito.mock(Storage.Buckets.Get.class);

  BackOff mockBackOff = BackOffAdapter.toGcpBackOff(
      FluentBackoff.DEFAULT.backoff());

  when(mockStorage.buckets()).thenReturn(mockStorageObjects);
  when(mockStorageObjects.get("testbucket")).thenReturn(mockStorageGet);
  when(mockStorageGet.execute())
      .thenThrow(new SocketTimeoutException("SocketException"))
      .thenReturn(new Bucket());

  assertNotNull(gcsUtil.getBucket(GcsPath.fromComponents("testbucket", "testobject"),
      mockBackOff, new FastNanoClockAndSleeper()));
}
 
开发者ID:apache,项目名称:beam,代码行数:24,代码来源:GcsUtilTest.java

示例5: createBucket

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
private static Bucket createBucket(Storage storage, String projectId, String locationId, String bucketId) {
  try {
    Bucket bucket = new Bucket()
        .setLocation(locationId)
        .setName(bucketId)
        .setVersioning(new Bucket.Versioning().setEnabled(true));

    if (!StringUtils.isEmpty(locationId)) {
      bucket.setLocation(locationId);
    }

    return storage.buckets().insert(projectId, bucket).execute();
  } catch (IOException e) {
    throw new RuntimeException("Unable to create bucket", e);
  }
}
 
开发者ID:spinnaker,项目名称:halyard,代码行数:17,代码来源:GoogleStorage.java

示例6: initBuckets

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
/** Get all bucket names and create them. */
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
public static void initBuckets(final boolean create) {
    for (final String region : REGIONS) {
        final String bucketName = BUCKET_PREFIX + region.toLowerCase(Locale.ENGLISH);
        BUCKETS.put(region, bucketName);

        if (create) {
            try {
                LOGGER.debug("Creating bucket  '{}'", bucketName);
                client.buckets().insert(projectId,
                    new Bucket().setName(bucketName).setLocation(region)
                        .setStorageClass("DURABLE_REDUCED_AVAILABILITY")).execute();
            } catch (IOException e) {
                LOGGER.error("Create bucket exception", e);
            }
        }
    }
}
 
开发者ID:DevOps-TangoMe,项目名称:gcloud-storage-speedtest,代码行数:20,代码来源:StorageManager.java

示例7: testBadTTLWithUpdate

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testBadTTLWithUpdate() throws Exception {
  final Bucket bucket = new Bucket()
      .setName(BUCKET_NAME)
      .setLifecycle(
          new Bucket.Lifecycle().setRule(ImmutableList.of(new Rule()
                  .setCondition(new Rule.Condition().setAge(BAD_TTL))
                  .setAction(new Rule.Action().setType("Delete")))));

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkHasOneRuleLifecycle());

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:17,代码来源:ExpiringBucketLifecycleManagerTest.java

示例8: testReplaceComplexLifecycle

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testReplaceComplexLifecycle() throws Exception {
  final Rule expireGoodTTL = new Rule()
      .setCondition(new Rule.Condition().setAge(TTL))
      .setAction(new Rule.Action().setType("Delete"));
  final Bucket bucket = new Bucket()
      .setName(BUCKET_NAME)
      .setLifecycle(new Bucket.Lifecycle().setRule(
          // Create a list with two good rules, to validate that
          // multi-clause rules get thrown out.
          ImmutableList.of(expireGoodTTL, expireGoodTTL)));

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkHasOneRuleLifecycle());

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:20,代码来源:ExpiringBucketLifecycleManagerTest.java

示例9: testBadAction

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testBadAction() throws Exception {
  final Bucket bucket = new Bucket()
      .setName(BUCKET_NAME)
      .setLifecycle(
          new Bucket.Lifecycle().setRule(ImmutableList.of(new Rule()
                  .setCondition(new Rule.Condition().setAge(TTL))
                  .setAction(new Rule.Action().setType("Unknown")))));

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkHasOneRuleLifecycle());

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:17,代码来源:ExpiringBucketLifecycleManagerTest.java

示例10: testBadCondition

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testBadCondition() throws Exception {
  final Bucket bucket = new Bucket()
      .setName(BUCKET_NAME)
      .setLifecycle(
          new Bucket.Lifecycle().setRule(ImmutableList.of(new Rule()
                  .setCondition(new Rule.Condition().setNumNewerVersions(3))
                  .setAction(new Rule.Action().setType("Delete")))));

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkHasOneRuleLifecycle());

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:17,代码来源:ExpiringBucketLifecycleManagerTest.java

示例11: testBadComplexCondition

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testBadComplexCondition() throws Exception {
  final Bucket bucket = new Bucket()
      .setName(BUCKET_NAME)
      .setLifecycle(
          new Bucket.Lifecycle().setRule(ImmutableList.of(new Rule()
                  .setCondition(new Rule.Condition()
                      .setAge(TTL)
                      .setNumNewerVersions(3))
                  .setAction(new Rule.Action().setType("Delete")))));

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, bucket);
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkHasOneRuleLifecycle());

  underTest.perform(CREDENTIALS_ID, build, TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:19,代码来源:ExpiringBucketLifecycleManagerTest.java

示例12: testFailingBucketCheck

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testFailingBucketCheck() throws Exception {
  final Bucket bucket = new Bucket().setName(BUCKET_NAME);

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      bucket);

  // A get that returns a bucket should trigger a check/decorate/update
  executor.when(Storage.Buckets.Get.class, new Bucket());
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkSameBucket(bucket));

  underTest
      .perform(CREDENTIALS_ID, build, build.getWorkspace(),
          TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:19,代码来源:AbstractBucketLifecycleManagerTest.java

示例13: testPassingBucketCheck

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testPassingBucketCheck() throws Exception {
  final Bucket bucket = new Bucket().setName(BUCKET_NAME);

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      null /* pass the bucket check */);

  // A get that passes our check should incur no further RPC
  executor.when(Storage.Buckets.Get.class, bucket);

  underTest
      .perform(CREDENTIALS_ID, build, build.getWorkspace(),
          TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:17,代码来源:AbstractBucketLifecycleManagerTest.java

示例14: testPassingBucketCheckAfterNotFoundThenConflict

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
@Test
public void testPassingBucketCheckAfterNotFoundThenConflict()
    throws Exception {
  final Bucket bucket = new Bucket().setName(BUCKET_NAME);

  FakeUpload underTest = new FakeUpload(BUCKET_URI,
      new MockUploadModule(executor),
      FAKE_DETAILS,
      bucket);

  executor.throwWhen(Storage.Buckets.Get.class, notFoundException);
  executor.throwWhen(Storage.Buckets.Insert.class, conflictException);
  // Verify that our final "get" handles updating the bucket as well
  executor.when(Storage.Buckets.Get.class, new Bucket());
  executor.passThruWhen(Storage.Buckets.Update.class,
      checkSameBucket(bucket));

  underTest
      .perform(CREDENTIALS_ID, build, build.getWorkspace(),
          TaskListener.NULL);
}
 
开发者ID:jenkinsci,项目名称:google-storage-plugin,代码行数:22,代码来源:AbstractBucketLifecycleManagerTest.java

示例15: createItemInfoForBucket

import com.google.api.services.storage.model.Bucket; //导入依赖的package包/类
/**
 * Helper for converting a StorageResourceId + Bucket into a GoogleCloudStorageItemInfo.
 */
public static GoogleCloudStorageItemInfo createItemInfoForBucket(
    StorageResourceId resourceId, Bucket bucket) {
  Preconditions.checkArgument(resourceId != null, "resourceId must not be null");
  Preconditions.checkArgument(bucket != null, "bucket must not be null");
  Preconditions.checkArgument(
      resourceId.isBucket(), "resourceId must be a Bucket. resourceId: %s", resourceId);
  Preconditions.checkArgument(
      resourceId.getBucketName().equals(bucket.getName()),
      "resourceId.getBucketName() must equal bucket.getName(): '%s' vs '%s'",
      resourceId.getBucketName(), bucket.getName());

  // For buckets, size is 0.
  return new GoogleCloudStorageItemInfo(resourceId, bucket.getTimeCreated().getValue(),
      0, bucket.getLocation(), bucket.getStorageClass());
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:19,代码来源:GoogleCloudStorageImpl.java


注:本文中的com.google.api.services.storage.model.Bucket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。