Search in sources :

Example 1 with RequestHandoutId

use of bio.terra.buffer.common.RequestHandoutId in project terra-resource-buffer by DataBiosphere.

the class BufferDaoTest method updateOneReadyResourceToHandedOut_noResourceAvailable.

@Test
public void updateOneReadyResourceToHandedOut_noResourceAvailable() {
    Pool pool = newPool(PoolId.create("poolId"));
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    bufferDao.createPools(ImmutableList.of(pool));
    assertFalse(bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).isPresent());
}
Also used : RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with RequestHandoutId

use of bio.terra.buffer.common.RequestHandoutId in project terra-resource-buffer by DataBiosphere.

the class PoolServiceTest method handoutResource_deactivatedPool.

@Test
public void handoutResource_deactivatedPool() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    newReadyPool(poolId, 1);
    bufferDao.deactivatePools(ImmutableList.of(poolId));
    assertThrows(BadRequestException.class, () -> poolService.handoutResource(poolId, requestHandoutId));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with RequestHandoutId

use of bio.terra.buffer.common.RequestHandoutId in project terra-resource-buffer by DataBiosphere.

the class PoolServiceTest method handoutResource_noReadyResource.

@Test
public void handoutResource_noReadyResource() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    newReadyPool(poolId, 0);
    assertThrows(NotFoundException.class, () -> poolService.handoutResource(poolId, requestHandoutId));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with RequestHandoutId

use of bio.terra.buffer.common.RequestHandoutId in project terra-resource-buffer by DataBiosphere.

the class PoolServiceTest method handoutResource_success.

@Test
public void handoutResource_success() throws Exception {
    PoolId poolId = PoolId.create("poolId");
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    newReadyPool(poolId, 2);
    List<CloudResourceUid> resourceUids = bufferDao.retrieveResourcesRandomly(poolId, ResourceState.READY, 2).stream().map(Resource::cloudResourceUid).collect(Collectors.toList());
    ResourceInfo resourceInfo = poolService.handoutResource(poolId, requestHandoutId);
    assertEquals(poolId.id(), resourceInfo.getPoolId());
    assertEquals(requestHandoutId.id(), resourceInfo.getRequestHandoutId());
    // CloudResource may be either of the two resources.
    assertTrue(resourceInfo.getCloudResourceUid().equals(resourceUids.get(0)) || resourceInfo.getCloudResourceUid().equals(resourceUids.get(1)));
    // Use the same requestHandoutId, expect to get the same resource back.
    ResourceInfo secondResourceInfo = poolService.handoutResource(poolId, requestHandoutId);
    assertEquals(resourceInfo, secondResourceInfo);
}
Also used : CloudResourceUid(bio.terra.buffer.generated.model.CloudResourceUid) ResourceInfo(bio.terra.buffer.generated.model.ResourceInfo) PoolId(bio.terra.buffer.common.PoolId) RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with RequestHandoutId

use of bio.terra.buffer.common.RequestHandoutId in project terra-resource-buffer by DataBiosphere.

the class BufferDaoTest method updateOneReadyResourceToHandedOut.

@Test
public void updateOneReadyResourceToHandedOut() {
    Pool pool = newPool(PoolId.create("poolId"));
    RequestHandoutId requestHandoutId = RequestHandoutId.create("handoutId");
    Resource ready = newResource(pool.id(), ResourceState.READY);
    bufferDao.createPools(ImmutableList.of(pool));
    bufferDao.createResource(ready);
    Resource resource = bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get();
    Resource handedOutResource = bufferDao.retrieveResource(resource.id()).get();
    assertEquals(requestHandoutId, handedOutResource.requestHandoutId());
    assertEquals(ResourceState.HANDED_OUT, handedOutResource.state());
    // Now use the same requestHandoutId again, expect getting the same resource back.
    assertEquals(handedOutResource, bufferDao.updateOneReadyResourceToHandedOut(pool.id(), requestHandoutId).get());
}
Also used : Resource(bio.terra.buffer.common.Resource) RequestHandoutId(bio.terra.buffer.common.RequestHandoutId) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)5 RequestHandoutId (bio.terra.buffer.common.RequestHandoutId)5 Test (org.junit.jupiter.api.Test)5 PoolId (bio.terra.buffer.common.PoolId)3 Pool (bio.terra.buffer.common.Pool)2 Resource (bio.terra.buffer.common.Resource)1 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)1 ResourceInfo (bio.terra.buffer.generated.model.ResourceInfo)1