use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method newReadyPool.
/**
* Creates a pool with resources with given size.
*/
private void newReadyPool(PoolId poolId, int poolSize) {
Pool pool = Pool.builder().creation(Instant.now()).id(poolId).resourceType(ResourceType.GOOGLE_PROJECT).size(poolSize).resourceConfig(new ResourceConfig().configName("resourceName")).status(PoolStatus.ACTIVE).build();
bufferDao.createPools(ImmutableList.of(pool));
for (int i = 0; i < poolSize; i++) {
ResourceId id = ResourceId.create(UUID.randomUUID());
bufferDao.createResource(Resource.builder().id(id).poolId(poolId).creation(Instant.now()).state(ResourceState.CREATING).build());
bufferDao.updateResourceAsReady(id, newProjectUid());
}
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class FlightSchedulerTest method scheduleDeactivationFlights_poolDeactivated.
@Test
public void scheduleDeactivationFlights_poolDeactivated() throws Exception {
// pool is delete, should delete the 2 READY resources.
Pool pool = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
bufferDao.deactivatePools(ImmutableList.of(pool.id()));
List<Resource> resources = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 2);
initializeScheduler();
TimeUnit.SECONDS.sleep(4);
resources.forEach(resource -> verify(flightManager).submitDeletionFlight(resource, ResourceType.GOOGLE_PROJECT));
verify(flightManager, never()).submitCreationFlight(any(Pool.class));
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class FlightSchedulerTest method scheduleDeactivationFlights_smallerLimitPerExecute.
@Test
public void scheduleDeactivationFlights_smallerLimitPerExecute() throws Exception {
// Pool1 size 5, need to deactivate the 4 READY resources.
// Expect number of resourceDeactivationPerPoolLimit(3) flights are submitted at most.
Pool pool = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
bufferDao.deactivatePools(ImmutableList.of(pool.id()));
List<Resource> resources = bufferDao.retrieveResourcesRandomly(pool.id(), ResourceState.READY, 4);
PrimaryConfiguration primaryConfiguration = newPrimaryConfiguration();
primaryConfiguration.setResourceDeletionPerPoolLimit(3);
initializeScheduler(primaryConfiguration);
TimeUnit.SECONDS.sleep(4);
verify(flightManager, times(3)).submitDeletionFlight(resourceArgumentCaptor.capture(), eq(ResourceType.GOOGLE_PROJECT));
assertThat(resources, (Matcher) Matchers.hasItems(resourceArgumentCaptor.getAllValues().toArray()));
verify(flightManager, never()).submitCreationFlight(any(Pool.class));
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class FlightSchedulerTest method newPoolWithResourceCount.
/**
* Creates a pool with resources with given {@code resourceStates}.
*/
private Pool newPoolWithResourceCount(int poolSize, Multiset<ResourceState> resourceStates) {
PoolId poolId = PoolId.create(UUID.randomUUID().toString());
Pool pool = Pool.builder().creation(Instant.now()).id(poolId).resourceType(ResourceType.GOOGLE_PROJECT).size(poolSize).resourceConfig(new ResourceConfig().configName("resourceName")).status(PoolStatus.ACTIVE).build();
bufferDao.createPools(ImmutableList.of(pool));
for (ResourceState state : resourceStates) {
bufferDao.createResource(Resource.builder().id(ResourceId.create(UUID.randomUUID())).poolId(poolId).creation(Instant.now()).state(state).build());
}
return pool;
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class FlightSchedulerTest method scheduleCreationFlights.
@Test
public void scheduleCreationFlights() throws Exception {
// Pool1 size 5, should create 2 more resources.
Pool pool1 = newPoolWithResourceCount(5, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
// Pool2 size 3, nothing to create.
Pool pool2 = newPoolWithResourceCount(3, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
initializeScheduler();
TimeUnit.SECONDS.sleep(4);
verify(flightManager, times(2)).submitCreationFlight(pool1);
verify(flightManager, never()).submitCreationFlight(pool2);
verify(flightManager, never()).submitDeletionFlight(any(Resource.class), any(ResourceType.class));
}
Aggregations