Search in sources :

Example 1 with Resource

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());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with Resource

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()));
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with Resource

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());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with Resource

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()));
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with Resource

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());
}
Also used : Resource(bio.terra.buffer.common.Resource) Pool(bio.terra.buffer.common.Pool) IntegrationUtils.preparePool(bio.terra.buffer.integration.IntegrationUtils.preparePool) FlightManager(bio.terra.buffer.service.resource.FlightManager) StubSubmissionFlightFactory(bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(bio.terra.buffer.common.BaseIntegrationTest)

Aggregations

Resource (bio.terra.buffer.common.Resource)25 Pool (bio.terra.buffer.common.Pool)18 Test (org.junit.jupiter.api.Test)18 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)11 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)7 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)6 FlightManager (bio.terra.buffer.service.resource.FlightManager)6 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)5 PoolId (bio.terra.buffer.common.PoolId)3 ResourceId (bio.terra.buffer.common.ResourceId)3 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)3 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)2 GoogleProjectUid (bio.terra.buffer.generated.model.GoogleProjectUid)2 InternalServerErrorException (bio.terra.common.exception.InternalServerErrorException)2 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)2 Transactional (org.springframework.transaction.annotation.Transactional)2 PrimaryConfiguration (bio.terra.buffer.app.configuration.PrimaryConfiguration)1 RequestHandoutId (bio.terra.buffer.common.RequestHandoutId)1 NotFoundException (bio.terra.buffer.common.exception.NotFoundException)1 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)1