Search in sources :

Example 81 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class ResourceAggregatorTest method shouldThrowIllegalArgumentExceptionWhenSecondListContainsResourceWithUnsupportedTypeOnIntersection.

@Test(expectedExceptions = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWhenSecondListContainsResourceWithUnsupportedTypeOnIntersection() throws Exception {
    final ResourceImpl dResource = mock(ResourceImpl.class);
    when(dResource.getType()).thenReturn("resourceD");
    // when
    resourceAggregator.intersection(emptyList(), singletonList(dResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 82 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class FreeResourceManagerTest method shouldReturnFreeResourcesLimits.

@Test
public void shouldReturnFreeResourcesLimits() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    when(freeResourcesLimitDao.getAll(anyInt(), anyInt())).thenReturn(new Page<>(singletonList(resourcesLimitImpl), 5, 1, 9));
    // when
    Page<? extends FreeResourcesLimit> fetchedLimits = manager.getAll(1, 5);
    // then
    assertEquals(fetchedLimits.getTotalItemsCount(), 9);
    assertEquals(fetchedLimits.getSize(), 1);
    assertEquals(fetchedLimits.getItems().get(0), resourcesLimitImpl);
    verify(freeResourcesLimitDao).getAll(1, 5);
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 83 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class FreeResourceManagerTest method shouldReturnFreeResourcesLimitForSpecifiedAccount.

@Test
public void shouldReturnFreeResourcesLimitForSpecifiedAccount() throws Exception {
    // given
    ResourceImpl resource = new ResourceImpl(TEST_RESOURCE_TYPE, 1, "unit");
    FreeResourcesLimitImpl resourcesLimitImpl = new FreeResourcesLimitImpl("account123", singletonList(resource));
    when(freeResourcesLimitDao.get(any())).thenReturn(resourcesLimitImpl);
    // when
    FreeResourcesLimit fetchedLimit = manager.get("account123");
    // then
    assertEquals(fetchedLimit, resourcesLimitImpl);
    verify(freeResourcesLimitDao).get("account123");
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) FreeResourcesLimit(org.eclipse.che.multiuser.resource.model.FreeResourcesLimit) Test(org.testng.annotations.Test)

Example 84 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

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);
}
Also used : NoEnoughResourcesException(org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 85 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project che-server by eclipse-che.

the class LimitsCheckingWorkspaceManagerTest method shouldUseRamOfSpecifiedEnvironmentOnCheckingAvailabilityOfRamResource.

@Test
public void shouldUseRamOfSpecifiedEnvironmentOnCheckingAvailabilityOfRamResource() throws Exception {
    // given
    LimitsCheckingWorkspaceManager manager = managerBuilder().setResourceManager(resourceManager).setEnvironmentRamCalculator(environmentRamCalculator).build();
    when(environmentRamCalculator.calculate(any(Environment.class))).thenReturn(3000L);
    WorkspaceConfig config = createConfig("3gb");
    String envToStart = config.getDefaultEnv();
    // when
    manager.checkRamResourcesAvailability(ACCOUNT_ID, NAMESPACE, config, envToStart);
    // then
    verify(environmentRamCalculator).calculate(config.getEnvironments().get(envToStart));
    verify(resourceManager).checkResourcesAvailability(ACCOUNT_ID, singletonList(new ResourceImpl(RamResourceType.ID, 3000, RamResourceType.UNIT)));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Environment(org.eclipse.che.api.core.model.workspace.config.Environment) WorkspaceConfig(org.eclipse.che.api.core.model.workspace.WorkspaceConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)138 Test (org.testng.annotations.Test)116 Resource (org.eclipse.che.multiuser.resource.model.Resource)24 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)20 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)20 ProvidedResourcesImpl (org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl)14 FreeResourcesLimit (org.eclipse.che.multiuser.resource.model.FreeResourcesLimit)12 NotFoundException (org.eclipse.che.api.core.NotFoundException)10 AccountManager (org.eclipse.che.account.api.AccountManager)8 Account (org.eclipse.che.account.shared.model.Account)8 Environment (org.eclipse.che.api.core.model.workspace.config.Environment)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)8 ProvidedResources (org.eclipse.che.multiuser.resource.model.ProvidedResources)8 FreeResourcesLimitDto (org.eclipse.che.multiuser.resource.shared.dto.FreeResourcesLimitDto)8 Response (io.restassured.response.Response)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Provider (javax.inject.Provider)6 Singleton (javax.inject.Singleton)6 Pages (org.eclipse.che.api.core.Pages)6