com.google.cloud.storage.testing.RemoteStorageHelper Java Examples

The following examples show how to use com.google.cloud.storage.testing.RemoteStorageHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractGCSIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    try {
        helper = RemoteStorageHelper.create();
        storage = helper.getOptions().getService();

        if (storage.get(BUCKET) != null) {
            // As the generateBucketName function uses a UUID, this should pretty much never happen
            fail("Bucket " + BUCKET + " exists. Please rerun the test to generate a new bucket name.");
        }

        // Create the bucket
        storage.create(BucketInfo.of(BUCKET));
    } catch (StorageException e) {
        fail("Can't create bucket " + BUCKET + ": " + e.getLocalizedMessage());
    }

    if (storage.get(BUCKET) == null) {
        fail("Setup incomplete, tests will fail");
    }
}
 
Example #2
Source File: ITBlobSnippets.java    From google-cloud-java with Apache License 2.0 6 votes vote down vote up
@Test
public void testMoveObject() {
  String blob = "movethisblob";
  storage.create(BlobInfo.newBuilder(BlobId.of(BUCKET, blob)).build());
  assertNotNull(storage.get(BUCKET, blob));
  String newBucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.newBuilder(newBucket).build());
  try {
    MoveObject.moveObject(PROJECT_ID, BUCKET, blob, newBucket);
    assertNotNull(storage.get(newBucket, blob));
    assertNull(storage.get(BUCKET, blob));
  } finally {
    storage.delete(newBucket, blob);
    storage.delete(newBucket);
  }
}
 
Example #3
Source File: AbstractGCSIT.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    try {
        helper = RemoteStorageHelper.create();
        storage = helper.getOptions().getService();

        if (storage.get(BUCKET) != null) {
            // As the generateBucketName function uses a UUID, this should pretty much never happen
            fail("Bucket " + BUCKET + " exists. Please rerun the test to generate a new bucket name.");
        }

        // Create the bucket
        storage.create(BucketInfo.of(BUCKET));
    } catch (StorageException e) {
        fail("Can't create bucket " + BUCKET + ": " + e.getLocalizedMessage());
    }

    if (storage.get(BUCKET) == null) {
        fail("Setup incomplete, tests will fail");
    }
}
 
Example #4
Source File: ITBucketSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateBucketWithStorageClassAndLocation() {
  String newBucket = RemoteStorageHelper.generateBucketName();
  CreateBucketWithStorageClassAndLocation.createBucketWithStorageClassAndLocation(
      PROJECT_ID, newBucket);
  try {
    Bucket remoteBucket = storage.get(newBucket);
    assertNotNull(remoteBucket);
    assertEquals("COLDLINE", remoteBucket.getStorageClass().name());
    assertEquals("ASIA", remoteBucket.getLocation());
  } finally {
    storage.delete(newBucket);
  }
}
 
Example #5
Source File: ITStorageSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testUniformBucketLevelAccess() {
  String tempBucket = RemoteStorageHelper.generateBucketName();
  Bucket bucket = storageSnippets.createBucket(tempBucket);
  assertNotNull(bucket);
  bucket = storageSnippets.enableUniformBucketLevelAccess(tempBucket);
  assertTrue(bucket.getIamConfiguration().isUniformBucketLevelAccessEnabled());
  assertNotNull(bucket.getIamConfiguration().getUniformBucketLevelAccessLockedTime());
  bucket = storageSnippets.getUniformBucketLevelAccess(tempBucket);
  assertTrue(bucket.getIamConfiguration().isUniformBucketLevelAccessEnabled());
  assertNotNull(bucket.getIamConfiguration().getUniformBucketLevelAccessLockedTime());
  bucket = storageSnippets.disableUniformBucketLevelAccess(tempBucket);
  assertFalse(bucket.getIamConfiguration().isUniformBucketLevelAccessEnabled());
}
 
Example #6
Source File: ITStorageSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testLockRetentionPolicy() {
  String tempBucket = RemoteStorageHelper.generateBucketName();
  Bucket bucket = storageSnippets.createBucket(tempBucket);
  assertNotNull(bucket);
  bucket = storageSnippets.setRetentionPolicy(tempBucket, RETENTION_PERIOD);
  assertEquals(bucket.getRetentionPeriod(), RETENTION_PERIOD);
  bucket = storageSnippets.lockRetentionPolicy(tempBucket);
  assertTrue(bucket.retentionPolicyIsLocked());
}
 
Example #7
Source File: ITStorageSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void afterClass() throws ExecutionException, InterruptedException {
  if (storage != null) {
    // In beforeClass, we make buckets auto-delete blobs older than a day old.
    // Here, delete all buckets older than 2 days. They should already be empty and easy.
    long cleanTime = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(2);
    long cleanTimeout = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(1);
    RemoteStorageHelper.cleanBuckets(storage, cleanTime, cleanTimeout);

    boolean wasDeleted = RemoteStorageHelper.forceDelete(storage, BUCKET, 1, TimeUnit.MINUTES);
    if (!wasDeleted && log.isLoggable(Level.WARNING)) {
      log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
    }
  }
}
 
Example #8
Source File: ITStorageSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  RemoteStorageHelper helper = RemoteStorageHelper.create();
  storage = helper.getOptions().getService();
  storageSnippets = new StorageSnippets(storage);
  storageSnippets.createBucket(BUCKET);
}
 
Example #9
Source File: ITBlobSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testCopyObject() {
  String newBucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.newBuilder(newBucket).build());
  try {
    CopyObject.copyObject(PROJECT_ID, BUCKET, BLOB, newBucket);
    assertNotNull(storage.get(newBucket, BLOB));
  } finally {
    storage.delete(newBucket, BLOB);
    storage.delete(newBucket);
  }
}
 
Example #10
Source File: ITBlobSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void afterClass() throws ExecutionException, InterruptedException {
  if (storage != null) {
    boolean wasDeleted = RemoteStorageHelper.forceDelete(storage, BUCKET, 5, TimeUnit.SECONDS);
    if (!wasDeleted && log.isLoggable(Level.WARNING)) {
      log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
    }
  }
}
 
Example #11
Source File: ITBucketSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteBucket() {
  String newBucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.newBuilder(newBucket).build());
  assertNotNull(storage.get(newBucket));
  try {
    DeleteBucket.deleteBucket(PROJECT_ID, newBucket);
    assertNull(storage.get(newBucket));
  } finally {
    storage.delete(newBucket);
  }
}
 
Example #12
Source File: ITBucketSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void afterClass() throws ExecutionException, InterruptedException {
  if (storage != null) {
    boolean wasDeleted = RemoteStorageHelper.forceDelete(storage, BUCKET, 5, TimeUnit.SECONDS);
    if (!wasDeleted && log.isLoggable(Level.WARNING)) {
      log.log(Level.WARNING, "Deletion of bucket {0} timed out, bucket is not empty", BUCKET);
    }
  }
}
 
Example #13
Source File: ITTableSnippets.java    From google-cloud-java with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  bigquery = RemoteBigQueryHelper.create().getOptions().getService();
  bigquery.create(DatasetInfo.newBuilder(DATASET_NAME).build());
  bigquery.create(DatasetInfo.newBuilder(COPY_DATASET_NAME).build());
  storage = RemoteStorageHelper.create().getOptions().getService();
  storage.create(BucketInfo.of(BUCKET_NAME));
}
 
Example #14
Source File: StorageIntegrationTest.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/** Find credentials in the environment and create a bucket in GCS. */
@Before
public void createBucket() {
  RemoteStorageHelper storageHelper = RemoteStorageHelper.create();
  storage = storageHelper.getOptions().getService();
  projectId = storageHelper.getOptions().getProjectId();
  bucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.of(bucket));
}
 
Example #15
Source File: KeyStoreIntegrationTest.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/** Create a storage bucket for metadata and keys. */
@Before
public void createBucket() {
  RemoteStorageHelper storageHelper = RemoteStorageHelper.create();
  storage = storageHelper.getOptions().getService();
  projectId = storageHelper.getOptions().getProjectId();
  bucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.of(bucket));
}
 
Example #16
Source File: GcsBucket.java    From gcp-ingestion with Mozilla Public License 2.0 5 votes vote down vote up
/** Find credentials in the environment and create a bucket in GCS. */
@Override
protected void starting(Description description) {
  RemoteStorageHelper storageHelper = RemoteStorageHelper.create();
  storage = storageHelper.getOptions().getService();
  bucket = RemoteStorageHelper.generateBucketName();
  storage.create(BucketInfo.newBuilder(bucket).build());
}
 
Example #17
Source File: ITBucketSnippets.java    From google-cloud-java with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  RemoteStorageHelper helper = RemoteStorageHelper.create();
  storage = helper.getOptions().getService();
  bucketSnippets = new BucketSnippets(storage.create(BucketInfo.of(BUCKET)));
}
 
Example #18
Source File: ITStorageHmacKeySnippets.java    From google-cloud-java with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  RemoteStorageHelper helper = RemoteStorageHelper.create();
  storage = helper.getOptions().getService();
  storageSnippets = new StorageSnippets(storage);
}
 
Example #19
Source File: ITBlobSnippets.java    From google-cloud-java with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  RemoteStorageHelper helper = RemoteStorageHelper.create();
  storage = helper.getOptions().getService();
  storage.create(BucketInfo.of(BUCKET));
}
 
Example #20
Source File: ITTableSnippets.java    From google-cloud-java with Apache License 2.0 4 votes vote down vote up
@AfterClass
public static void afterClass() {
  RemoteBigQueryHelper.forceDelete(bigquery, DATASET_NAME);
  RemoteBigQueryHelper.forceDelete(bigquery, COPY_DATASET_NAME);
  RemoteStorageHelper.forceDelete(storage, BUCKET_NAME);
}
 
Example #21
Source File: KeyStoreIntegrationTest.java    From gcp-ingestion with Mozilla Public License 2.0 4 votes vote down vote up
/** Clean up storage resources. */
@After
public void deleteBucket() throws Exception {
  RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
}
 
Example #22
Source File: GcsBucket.java    From gcp-ingestion with Mozilla Public License 2.0 4 votes vote down vote up
/** Remove all resources we created in GCS. */
@Override
protected void finished(Description description) {
  RemoteStorageHelper.forceDelete(storage, bucket);
}
 
Example #23
Source File: StorageIntegrationTest.java    From gcp-ingestion with Mozilla Public License 2.0 2 votes vote down vote up
/**
 * Clean up all GCS resources we created.
 *
 * @throws Exception if BigQuery is unavailable
 */
@After
public void deleteBucket() throws Exception {
  RemoteStorageHelper.forceDelete(storage, bucket, 5, TimeUnit.SECONDS);
}