use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class AbstractExhaustibleResourceTest method shouldReturnResourceWithMinusOneAmountWhenTotalResourceHasMinusOneOnResourcesDeduction.
@Test
public void shouldReturnResourceWithMinusOneAmountWhenTotalResourceHasMinusOneOnResourcesDeduction() throws Exception {
final Resource deducted = resourceType.deduct(new ResourceImpl(TestResourceType.ID, -1, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
assertEquals(deducted.getType(), TestResourceType.ID);
assertEquals(deducted.getAmount(), -1);
assertEquals(deducted.getUnit(), TestResourceType.UNIT);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class AbstractExhaustibleResourceTest method shouldFindDifferenceResourcesAmountsOnResourcesDeduction.
@Test
public void shouldFindDifferenceResourcesAmountsOnResourcesDeduction() throws Exception {
final Resource deducted = resourceType.deduct(new ResourceImpl(TestResourceType.ID, 1000, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
assertEquals(deducted.getType(), TestResourceType.ID);
assertEquals(deducted.getAmount(), 500);
assertEquals(deducted.getUnit(), TestResourceType.UNIT);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
the class DefaultAvailableResourcesProviderTest method shouldReturnExcessiveResourcesWhenNotOneResourceIsUsedButNotPresentInTotal.
@Test
public void shouldReturnExcessiveResourcesWhenNotOneResourceIsUsedButNotPresentInTotal() throws Exception {
// given
List<ResourceImpl> totalResources = singletonList(new ResourceImpl("test", 5000, "unit"));
doReturn(totalResources).when(resourceManager).getTotalResources(anyString());
List<ResourceImpl> usedResources = Arrays.asList(new ResourceImpl("test", 2000, "unit"), new ResourceImpl("test2", 5, "unit"));
doReturn(usedResources).when(resourceManager).getUsedResources(anyString());
doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(resourceAggregator).deduct(anyList(), anyList());
ResourceImpl excessiveResource = new ResourceImpl("test", 3000, "unit");
doReturn(singletonList(excessiveResource)).when(resourceAggregator).excess(anyList(), anyList());
// when
List<? extends Resource> availableResources = defaultAvailableResourcesProvider.getAvailableResources("account123");
// then
assertEquals(availableResources.size(), 1);
assertEquals(availableResources.get(0), excessiveResource);
verify(resourceManager).getTotalResources("account123");
verify(resourceManager).getUsedResources("account123");
verify(resourceAggregator).deduct(totalResources, usedResources);
verify(resourceAggregator).excess(totalResources, usedResources);
}
use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.
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 che-server by eclipse-che.
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)));
}
Aggregations