use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method retrievePoolWithResourceState.
@Test
public void retrievePoolWithResourceState() {
Pool pool1 = newPool(PoolId.create("poolId1"));
Pool pool2 = newPool(PoolId.create("poolId2"));
Pool pool3 = newPool(PoolId.create("poolId3"));
// Pool1 has 1 CREATING, 2 READY, Pool2 has 1 READY, 1 HANDED_OUT, Pool3 is empty
bufferDao.createPools(ImmutableList.of(pool1, pool2, pool3));
bufferDao.createResource(newResource(pool1.id(), ResourceState.CREATING));
bufferDao.createResource(newResource(pool1.id(), ResourceState.READY));
bufferDao.createResource(newResource(pool1.id(), ResourceState.READY));
bufferDao.createResource(newResource(pool2.id(), ResourceState.READY));
bufferDao.createResource(newResource(pool2.id(), ResourceState.HANDED_OUT));
PoolAndResourceStates pool1State = PoolAndResourceStates.builder().setPool(pool1).setResourceStateCount(ResourceState.CREATING, 1).setResourceStateCount(ResourceState.READY, 2).build();
assertThat(bufferDao.retrievePoolAndResourceStates(), Matchers.containsInAnyOrder(pool1State, PoolAndResourceStates.builder().setPool(pool2).setResourceStateCount(ResourceState.READY, 1).setResourceStateCount(ResourceState.HANDED_OUT, 1).build(), PoolAndResourceStates.builder().setPool(pool3).build()));
assertEquals(pool1State, bufferDao.retrievePoolAndResourceStatesById(pool1.id()).get());
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method updateReadyResourceAsDeleting_success.
@Test
public void updateReadyResourceAsDeleting_success() {
Pool pool = newPool(PoolId.create("poolId"));
Resource resource = newResource(pool.id(), ResourceState.READY);
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(resource);
assertTrue(bufferDao.updateReadyResourceToDeleting(resource.id()));
assertEquals(ResourceState.DELETING, bufferDao.retrieveResource(resource.id()).get().state());
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method insertAndRetrieveCleanupRecord.
@Test
public void insertAndRetrieveCleanupRecord() {
// Prepare 2 HANDED_OUT and 1 READY resources.
Pool pool = newPool(PoolId.create("poolId"));
Resource resource1 = newResource(pool.id(), ResourceState.READY);
Resource resource2 = newResource(pool.id(), ResourceState.READY);
Resource resource3 = newResource(pool.id(), ResourceState.READY);
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(resource1);
bufferDao.createResource(resource2);
bufferDao.createResource(resource3);
Resource handedOutR1 = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("1111")).get();
Resource handedOutR2 = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), RequestHandoutId.create("2222")).get();
// handedOutR1 is already in cleanup_record table, expect only handedOutR2 is returned.
bufferDao.insertCleanupRecord(handedOutR1.id());
assertThat(bufferDao.retrieveResourceToCleanup(1), Matchers.contains(bufferDao.retrieveResource(handedOutR2.id()).get()));
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_createsConsumerOverride.
@Test
public void testCreateGoogleProject_createsConsumerOverride() throws Exception {
FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
GcpProjectConfig gcpProjectConfig = newBasicGcpConfig().serviceUsage(new ServiceUsage().bigQuery(new BigQueryQuotas().overrideBigQueryDailyUsageQuota(true).bigQueryDailyUsageQuotaOverrideValueMebibytes(new BigDecimal(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES))));
Pool pool = preparePool(bufferDao, gcpProjectConfig);
String flightId = manager.submitCreationFlight(pool).orElseThrow();
ResourceId resourceId = extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
Project project = assertProjectExists(resourceId);
String projectNumber = getProjectNumberFromName(project.getName());
String parent = String.format("projects/%s/services/bigquery.googleapis.com/consumerQuotaMetrics/" + "bigquery.googleapis.com%%2Fquota%%2Fquery%%2Fusage/limits/%%2Fd%%2Fproject", projectNumber);
ServiceUsageCow.Services.ConsumerQuotaMetrics.Limits.ConsumerOverrides.List list = serviceUsageCow.services().consumerQuotaMetrics().limits().consumerOverrides().list(parent);
ListConsumerOverridesResponse response = list.execute();
assertEquals(1, response.getOverrides().size(), "single override expected");
QuotaOverride quotaOverride = response.getOverrides().get(0);
assertEquals(CONSUMER_QUOTA_OVERRIDE_VALUE_MEBIBYTES, quotaOverride.getOverrideValue());
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class CreateProjectFlightIntegrationTest method testCreateGoogleProject_errorWhenResourceStateChange.
@Test
public void testCreateGoogleProject_errorWhenResourceStateChange() throws Exception {
LatchStep.startNewLatch();
FlightManager manager = new FlightManager(bufferDao, new StubSubmissionFlightFactory(LatchBeforeAssertResourceStep.class), stairwayComponent, transactionTemplate);
Pool pool = preparePool(bufferDao, newBasicGcpConfig());
String flightId = manager.submitCreationFlight(pool).get();
// Resource is created in db
Resource resource = pollUntilResourcesMatch(bufferDao, pool.id(), ResourceState.CREATING, 1).get(0);
// Delete the resource from DB.
assertTrue(bufferDao.deleteResource(resource.id()));
// Release the latch, and resume the flight, assert flight failed.
LatchStep.releaseLatch();
extractResourceIdFromFlightState(blockUntilFlightComplete(stairwayComponent, flightId));
// Resource is deleted.
assertFalse(bufferDao.retrieveResource(resource.id()).isPresent());
assertEquals(FlightStatus.ERROR, stairwayComponent.get().getFlightState(flightId).getFlightStatus());
}
Aggregations