use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method updateReadyResourceAsDeleting_currentStateIsNotReady.
@Test
public void updateReadyResourceAsDeleting_currentStateIsNotReady() {
Pool pool = newPool(PoolId.create("poolId"));
Resource resource = newResource(pool.id(), ResourceState.HANDED_OUT);
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(resource);
assertFalse(bufferDao.updateReadyResourceToDeleting(resource.id()));
assertEquals(ResourceState.HANDED_OUT, bufferDao.retrieveResource(resource.id()).get().state());
}
use of bio.terra.buffer.common.Resource in project terra-resource-buffer by DataBiosphere.
the class BufferDaoTest method retrieveResourcesWithState.
@Test
public void retrieveResourcesWithState() {
Pool pool = newPool(PoolId.create("poolId1"));
// 1 CREATING, 3 READY resources; and ask for 2 READY resources.
Resource creating = newResource(pool.id(), ResourceState.CREATING);
Resource ready1 = newResource(pool.id(), ResourceState.READY);
Resource ready2 = newResource(pool.id(), ResourceState.READY);
Resource ready3 = newResource(pool.id(), ResourceState.READY);
bufferDao.createPools(ImmutableList.of(pool));
bufferDao.createResource(creating);
bufferDao.createResource(ready1);
bufferDao.createResource(ready2);
bufferDao.createResource(ready3);
List<Resource> resources = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 2);
assertEquals(2, resources.size());
assertThat(ImmutableList.of(ready1, ready2, ready3), Matchers.hasItems(resources.toArray()));
}
use of bio.terra.buffer.common.Resource 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.Resource 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.Resource 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