use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method updateFromConfig_createPool.
@Test
public void updateFromConfig_createPool() throws Exception {
PoolId poolId = PoolId.create("poolId");
PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
List<Pool> pools = bufferDao.retrievePools();
assertEquals(1, pools.size());
Pool createdPool = pools.get(0);
assertEquals(poolId, createdPool.id());
assertEquals(ResourceType.GOOGLE_PROJECT, createdPool.resourceType());
assertEquals(PoolStatus.ACTIVE, createdPool.status());
assertEquals(parsedPoolConfig.resourceConfig(), createdPool.resourceConfig());
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method updateFromConfig_alreadyExists.
@Test
public void updateFromConfig_alreadyExists() throws Exception {
PoolId poolId = PoolId.create("poolId");
PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
List<Pool> pools = bufferDao.retrievePools();
assertEquals(1, pools.size());
Pool createdPool = pools.get(0);
assertEquals(poolId, createdPool.id());
assertEquals(ResourceType.GOOGLE_PROJECT, createdPool.resourceType());
assertEquals(PoolStatus.ACTIVE, createdPool.status());
assertEquals(parsedPoolConfig.resourceConfig(), createdPool.resourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
assertThat(bufferDao.retrievePools(), Matchers.containsInAnyOrder(pools.toArray()));
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method updateFromConfig_updateResourceConfigOnExistingPool_throwsException.
@Test
public void updateFromConfig_updateResourceConfigOnExistingPool_throwsException() throws Exception {
PoolId poolId = PoolId.create("poolId");
PoolConfig poolConfig = new PoolConfig().poolId(poolId.toString()).size(1).resourceConfigName(RESOURCE_CONFIG_NAME);
PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
// Sets ResourceConfig's GCP project id prefix to newer value.
PoolWithResourceConfig updatedPoolConfig = PoolWithResourceConfig.create(poolConfig, newResourceConfig(new GcpProjectConfig().projectIdSchema(new ProjectIdSchema().prefix("aou-rw-test2").scheme(ProjectIdSchema.SchemeEnum.RANDOM_CHAR))));
assertThrows(RuntimeException.class, () -> poolService.updateFromConfig(ImmutableList.of(updatedPoolConfig)));
assertThat(bufferDao.retrievePools().stream().map(Pool::resourceConfig).collect(Collectors.toList()), Matchers.containsInAnyOrder(parsedPoolConfig.resourceConfig()));
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method updateFromConfig_deactivatePool_updatePoolStatusSuccess.
@Test
public void updateFromConfig_deactivatePool_updatePoolStatusSuccess() throws Exception {
PoolId poolId = PoolId.create("poolId");
PoolWithResourceConfig parsedPoolConfig = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig));
List<Pool> pools = bufferDao.retrievePools();
Pool createdPool = pools.get(0);
assertEquals(poolId, createdPool.id());
assertEquals(PoolStatus.ACTIVE, createdPool.status());
poolService.updateFromConfig(ImmutableList.of());
Pool resizedPool = bufferDao.retrievePools().get(0);
assertEquals(poolId, resizedPool.id());
assertEquals(PoolStatus.DEACTIVATED, resizedPool.status());
}
use of bio.terra.buffer.common.Pool in project terra-resource-buffer by DataBiosphere.
the class PoolServiceTest method updateFromConfig_createDeactivateReactivate_success.
@Test
public void updateFromConfig_createDeactivateReactivate_success() throws Exception {
// Create two pools so we fully exercise the batch methods in the DAO.
PoolId poolId1 = PoolId.create("poolId1");
PoolWithResourceConfig parsedPoolConfig1 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId1.toString()).size(10).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
PoolId poolId2 = PoolId.create("poolId2");
PoolWithResourceConfig parsedPoolConfig2 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId2.toString()).size(50).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig1, parsedPoolConfig2));
List<Pool> pools = bufferDao.retrievePools();
assertEquals(2, pools.size());
Pool createdPool1 = pools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
assertEquals(poolId1, createdPool1.id());
assertEquals(ResourceType.GOOGLE_PROJECT, createdPool1.resourceType());
assertEquals(PoolStatus.ACTIVE, createdPool1.status());
assertEquals(parsedPoolConfig1.resourceConfig(), createdPool1.resourceConfig());
Pool createdPool2 = pools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
;
assertEquals(poolId2, createdPool2.id());
assertEquals(ResourceType.GOOGLE_PROJECT, createdPool2.resourceType());
assertEquals(PoolStatus.ACTIVE, createdPool2.status());
assertEquals(parsedPoolConfig1.resourceConfig(), createdPool1.resourceConfig());
// Deactivate both pools
poolService.updateFromConfig(Collections.emptyList());
List<Pool> deactivatedPools = bufferDao.retrievePools();
assertEquals(2, deactivatedPools.size());
Pool deactivatedPool1 = deactivatedPools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
assertEquals(ResourceType.GOOGLE_PROJECT, deactivatedPool1.resourceType());
assertEquals(PoolStatus.DEACTIVATED, deactivatedPool1.status());
Pool deactivatedPool2 = deactivatedPools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
assertEquals(ResourceType.GOOGLE_PROJECT, deactivatedPool2.resourceType());
assertEquals(PoolStatus.DEACTIVATED, deactivatedPool2.status());
// Re-activate pools
// Resize pool 2
PoolWithResourceConfig resizedPoolConfig2 = PoolWithResourceConfig.create(new PoolConfig().poolId(poolId2.toString()).size(25).resourceConfigName(RESOURCE_CONFIG_NAME), newResourceConfig());
poolService.updateFromConfig(ImmutableList.of(parsedPoolConfig1, resizedPoolConfig2));
List<Pool> reactivatedPools = bufferDao.retrievePools();
Pool reactivatedPool1 = reactivatedPools.stream().filter(p -> p.id().equals(poolId1)).findFirst().orElseThrow();
assertEquals(ResourceType.GOOGLE_PROJECT, reactivatedPool1.resourceType());
assertEquals(PoolStatus.ACTIVE, reactivatedPool1.status());
assertEquals(10, reactivatedPool1.size());
Pool reactivatedPool2 = reactivatedPools.stream().filter(p -> p.id().equals(poolId2)).findFirst().orElseThrow();
assertEquals(ResourceType.GOOGLE_PROJECT, reactivatedPool2.resourceType());
assertEquals(PoolStatus.ACTIVE, reactivatedPool2.status());
assertEquals(25, reactivatedPool2.size());
}
Aggregations