Search in sources :

Example 1 with PrimaryConfiguration

use of bio.terra.buffer.app.configuration.PrimaryConfiguration in project terra-resource-buffer by DataBiosphere.

the class FlightSchedulerTest method scheduleDeactivationFlights_enableDeletion.

@Test
public void scheduleDeactivationFlights_enableDeletion() throws Exception {
    newPoolWithResourceCount(1, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY));
    PrimaryConfiguration primaryConfiguration = newPrimaryConfiguration();
    primaryConfiguration.setDeleteExcessResources(true);
    initializeScheduler(primaryConfiguration);
    TimeUnit.SECONDS.sleep(4);
    verify(flightManager).submitDeletionFlight(any(Resource.class), eq(ResourceType.GOOGLE_PROJECT));
}
Also used : Resource(bio.terra.buffer.common.Resource) PrimaryConfiguration(bio.terra.buffer.app.configuration.PrimaryConfiguration) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with PrimaryConfiguration

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

Example 3 with PrimaryConfiguration

use of bio.terra.buffer.app.configuration.PrimaryConfiguration in project terra-resource-buffer by DataBiosphere.

the class FlightSchedulerTest method newPrimaryConfiguration.

private PrimaryConfiguration newPrimaryConfiguration() {
    PrimaryConfiguration primaryConfiguration = new PrimaryConfiguration();
    primaryConfiguration.setSchedulerEnabled(true);
    primaryConfiguration.setResourceCreationPerPoolLimit(10);
    primaryConfiguration.setResourceDeletionPerPoolLimit(10);
    primaryConfiguration.setDeleteExcessResources(false);
    // Sets submissionPeriod to a big number to make sure it is only runs once.
    primaryConfiguration.setFlightSubmissionPeriod(Duration.ofHours(2));
    return primaryConfiguration;
}
Also used : PrimaryConfiguration(bio.terra.buffer.app.configuration.PrimaryConfiguration)

Example 4 with PrimaryConfiguration

use of bio.terra.buffer.app.configuration.PrimaryConfiguration in project terra-resource-buffer by DataBiosphere.

the class FlightSchedulerTest method scheduleCreationFlights_smallerLimitPerExecute.

@Test
public void scheduleCreationFlights_smallerLimitPerExecute() throws Exception {
    // Pool size 10, need to create 7 more resources.
    // Expect number of resourceCreationPerPoolLimit(5) flights are submitted at most.
    Pool pool = newPoolWithResourceCount(10, ImmutableMultiset.of(ResourceState.READY, ResourceState.READY, ResourceState.CREATING));
    PrimaryConfiguration primaryConfiguration = newPrimaryConfiguration();
    primaryConfiguration.setResourceCreationPerPoolLimit(5);
    initializeScheduler(primaryConfiguration);
    TimeUnit.SECONDS.sleep(4);
    verify(flightManager, times(5)).submitCreationFlight(pool);
    verify(flightManager, never()).submitDeletionFlight(any(Resource.class), any(ResourceType.class));
}
Also used : Resource(bio.terra.buffer.common.Resource) PrimaryConfiguration(bio.terra.buffer.app.configuration.PrimaryConfiguration) Pool(bio.terra.buffer.common.Pool) ResourceType(bio.terra.buffer.common.ResourceType) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

PrimaryConfiguration (bio.terra.buffer.app.configuration.PrimaryConfiguration)4 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)3 Resource (bio.terra.buffer.common.Resource)3 Test (org.junit.jupiter.api.Test)3 Pool (bio.terra.buffer.common.Pool)2 ResourceType (bio.terra.buffer.common.ResourceType)1