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());
}
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));
}
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));
}
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);
}
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());
}
Aggregations