Search in sources :

Example 1 with Pool

use of bio.terra.buffer.common.Pool 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 Pool

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

the class BufferDaoTest method createPoolAndRetrievePools.

@Test
public void createPoolAndRetrievePools() {
    Pool pool1 = newPool(PoolId.create("pool1"));
    Pool pool2 = newPool(PoolId.create("pool2"));
    bufferDao.createPools(ImmutableList.of(pool1, pool2));
    List<Pool> pools = bufferDao.retrievePools();
    assertThat(pools, Matchers.containsInAnyOrder(pool1, pool2));
    assertEquals(pool1, bufferDao.retrievePool(pool1.id()).get());
    assertEquals(pool2, bufferDao.retrievePool(pool2.id()).get());
}
Also used : Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with Pool

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

the class BufferDaoTest method updatePoolSize.

@Test
public void updatePoolSize() {
    PoolId poolId = PoolId.create("poolId");
    Pool pool = newPool(poolId);
    bufferDao.createPools(ImmutableList.of(pool));
    Pool retrievedPool = bufferDao.retrievePools().get(0);
    Pool resizedPool = pool.toBuilder().size(retrievedPool.size() + 10).build();
    bufferDao.updatePoolsSizes(ImmutableMap.of(poolId, resizedPool.size()));
    assertThat(bufferDao.retrievePools(), Matchers.containsInAnyOrder(resizedPool));
}
Also used : PoolId(bio.terra.buffer.common.PoolId) Pool(bio.terra.buffer.common.Pool) BaseUnitTest(bio.terra.buffer.common.BaseUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with Pool

use of bio.terra.buffer.common.Pool 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 5 with Pool

use of bio.terra.buffer.common.Pool 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)

Aggregations

Pool (bio.terra.buffer.common.Pool)49 Test (org.junit.jupiter.api.Test)43 BaseUnitTest (bio.terra.buffer.common.BaseUnitTest)25 Resource (bio.terra.buffer.common.Resource)21 BaseIntegrationTest (bio.terra.buffer.common.BaseIntegrationTest)18 IntegrationUtils.preparePool (bio.terra.buffer.integration.IntegrationUtils.preparePool)18 FlightManager (bio.terra.buffer.service.resource.FlightManager)18 ResourceId (bio.terra.buffer.common.ResourceId)17 PoolId (bio.terra.buffer.common.PoolId)13 Project (com.google.api.services.cloudresourcemanager.v3.model.Project)13 PoolConfig (bio.terra.buffer.generated.model.PoolConfig)7 StubSubmissionFlightFactory (bio.terra.buffer.integration.IntegrationUtils.StubSubmissionFlightFactory)7 ResourceConfig (bio.terra.buffer.generated.model.ResourceConfig)4 PoolAndResourceStates (bio.terra.buffer.common.PoolAndResourceStates)3 RequestHandoutId (bio.terra.buffer.common.RequestHandoutId)3 ResourceState (bio.terra.buffer.common.ResourceState)3 ResourceType (bio.terra.buffer.common.ResourceType)3 bio.terra.buffer.generated.model (bio.terra.buffer.generated.model)3 CloudResourceUid (bio.terra.buffer.generated.model.CloudResourceUid)3 PrimaryConfiguration (bio.terra.buffer.app.configuration.PrimaryConfiguration)2