use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.
the class LimitsCheckingWorkspaceManagerTest method shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableRamResource.
@Test(expectedExceptions = LimitExceededException.class, expectedExceptionsMessageRegExp = "Workspace namespace/workspace.. needs 3000MB to start\\. " + "Your account has 200MB available and 100MB in use\\. " + "The workspace can't be start. Stop other workspaces or grant more resources\\.")
public void shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableRamResource() throws Exception {
doThrow(new NoEnoughResourcesException(singletonList(new ResourceImpl(RamResourceType.ID, 200L, RamResourceType.UNIT)), singletonList(new ResourceImpl(RamResourceType.ID, 3000L, RamResourceType.UNIT)), emptyList())).when(resourceManager).checkResourcesAvailability(any(), any());
doReturn(singletonList(new ResourceImpl(RamResourceType.ID, 100L, RamResourceType.UNIT))).when(resourceManager).getUsedResources(any());
// given
LimitsCheckingWorkspaceManager manager = managerBuilder().setResourceManager(resourceManager).setEnvironmentRamCalculator(environmentRamCalculator).build();
when(environmentRamCalculator.calculate(any(Environment.class))).thenReturn(3000L);
WorkspaceConfig config = createConfig("3gb");
// when
manager.checkRamResourcesAvailability(ACCOUNT_ID, NAMESPACE, config, null);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.
the class LimitsCheckingWorkspaceManagerTest method shouldUseRamOfDefaultEnvironmentOnCheckingAvailabilityOfRamResourceWhen.
@Test
public void shouldUseRamOfDefaultEnvironmentOnCheckingAvailabilityOfRamResourceWhen() throws Exception {
// given
LimitsCheckingWorkspaceManager manager = managerBuilder().setResourceManager(resourceManager).setEnvironmentRamCalculator(environmentRamCalculator).build();
when(environmentRamCalculator.calculate(any(Environment.class))).thenReturn(3000L);
WorkspaceConfig config = createConfig("3gb");
// when
manager.checkRamResourcesAvailability(ACCOUNT_ID, NAMESPACE, config, null);
// then
verify(environmentRamCalculator).calculate(config.getEnvironments().get(config.getDefaultEnv()));
verify(resourceManager).checkResourcesAvailability(ACCOUNT_ID, singletonList(new ResourceImpl(RamResourceType.ID, 3000, RamResourceType.UNIT)));
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.
the class LimitsCheckingWorkspaceManagerTest method shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableRuntimeResource.
@Test(expectedExceptions = LimitExceededException.class, expectedExceptionsMessageRegExp = "You are not allowed to start more workspaces\\.")
public void shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableRuntimeResource() throws Exception {
// given
doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(resourceManager).checkResourcesAvailability(any(), any());
doReturn(singletonList(new ResourceImpl(RuntimeResourceType.ID, 5, RuntimeResourceType.UNIT))).when(resourceManager).getTotalResources(anyString());
LimitsCheckingWorkspaceManager manager = managerBuilder().setResourceManager(resourceManager).build();
// when
manager.checkRuntimeResourceAvailability(ACCOUNT_ID);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.
the class LimitsCheckingWorkspaceManagerTest method shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableWorkspaceResource.
@Test(expectedExceptions = LimitExceededException.class, expectedExceptionsMessageRegExp = "You are not allowed to create more workspaces\\.")
public void shouldThrowLimitExceedExceptionIfAccountDoesNotHaveEnoughAvailableWorkspaceResource() throws Exception {
// given
doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(resourceManager).checkResourcesAvailability(any(), any());
doReturn(singletonList(new ResourceImpl(WorkspaceResourceType.ID, 5, WorkspaceResourceType.UNIT))).when(resourceManager).getTotalResources(anyString());
LimitsCheckingWorkspaceManager manager = managerBuilder().setResourceManager(resourceManager).build();
// when
manager.checkWorkspaceResourceAvailability(ACCOUNT_ID);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.
the class FreeResourcesLimitDaoTest method setUp.
@BeforeMethod
private void setUp() throws Exception {
accounts = new AccountImpl[COUNTS_OF_LIMITS];
limits = new FreeResourcesLimitImpl[COUNTS_OF_LIMITS];
for (int i = 0; i < COUNTS_OF_LIMITS; i++) {
accounts[i] = new AccountImpl("accountId-" + i, "accountName" + i, "test");
limits[i] = new FreeResourcesLimitImpl(accounts[i].getId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, i, "test")));
}
accountRepository.createAll(Arrays.asList(accounts));
limitRepository.createAll(Stream.of(limits).map(FreeResourcesLimitImpl::new).collect(Collectors.toList()));
}
Aggregations