use of bio.terra.service.resourcemanagement.exception.GoogleResourceNotFoundException in project jade-data-repo by DataBiosphere.
the class BucketResourceTest method bucketExistsBeforeMetadataTest.
@Test
public // bucket cloud resource exists, but the corresponding bucket_resource metadata row does not
void bucketExistsBeforeMetadataTest() throws Exception {
logger.info("app property allowReuseExistingBuckets = " + resourceService.getAllowReuseExistingBuckets());
String bucketName = "testbucket_bucketexistsbeforemetadatatest";
String flightIdA = "bucketExistsBeforeMetadataTestA";
bucketNames.add(bucketName);
// create the bucket and metadata
GoogleBucketRequest googleBucketRequest = buildBucketRequest(bucketName);
GoogleBucketResource bucketResource = resourceService.getOrCreateBucket(googleBucketRequest, flightIdA);
checkBucketExists(bucketResource.getResourceId());
// delete the metadata only
boolean rowDeleted = resourceDao.deleteBucketMetadata(bucketName, flightIdA);
assertTrue("metadata row deleted", rowDeleted);
// try to fetch the bucket again, check fails with not found exception
boolean caughtNotFoundException = false;
try {
resourceService.getBucketResourceById(bucketResource.getResourceId(), true);
} catch (GoogleResourceNotFoundException cmEx) {
caughtNotFoundException = true;
}
assertTrue("fetch failed when metadata does not exist", caughtNotFoundException);
// set application property allowReuseExistingBuckets=false
// try to create bucket again, check fails with corrupt metadata exception
resourceService.setAllowReuseExistingBuckets(false);
String flightIdB = "bucketExistsBeforeMetadataTestB";
boolean caughtCorruptMetadataException = false;
try {
resourceService.getOrCreateBucket(googleBucketRequest, flightIdB);
} catch (CorruptMetadataException cmEx) {
caughtCorruptMetadataException = true;
}
assertTrue("create failed when cloud resource already exists", caughtCorruptMetadataException);
// set application property allowReuseExistingBuckets=true
// try to create bucket again, check succeeds
resourceService.setAllowReuseExistingBuckets(true);
String flightIdC = "bucketExistsBeforeMetadataTestC";
bucketResource = resourceService.getOrCreateBucket(googleBucketRequest, flightIdC);
// check the bucket and metadata exist
checkBucketExists(bucketResource.getResourceId());
// delete the bucket and metadata
deleteBucket(bucketResource.getName());
checkBucketDeleted(bucketResource.getName(), bucketResource.getResourceId());
// restore original value of application property allowReuseExistingBuckets, which was saved in setup
// (this is also done in cleanup after all tests, in case this test errors out before reaching this line)
resourceService.setAllowReuseExistingBuckets(allowReuseExistingBuckets);
}
Aggregations