Search in sources :

Example 31 with ResourceImpl

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

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);
}
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 32 with ResourceImpl

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

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()));
}
Also used : FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 33 with ResourceImpl

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

the class OrganizationResourcesDistributorTest method shouldCapResources.

@Test
public void shouldCapResources() throws Exception {
    List<ResourceImpl> toCap = singletonList(createTestResource(1000));
    // when
    manager.capResources(ORG_ID, toCap);
    // then
    verify(manager).checkResourcesAvailability(ORG_ID, toCap);
    verify(distributedResourcesDao).store(new OrganizationDistributedResourcesImpl(ORG_ID, toCap));
    verify(resourcesLocks).lock(ORG_ID);
    verify(lock).close();
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) OrganizationDistributedResourcesImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl) Test(org.testng.annotations.Test)

Example 34 with ResourceImpl

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

the class OrganizationResourcesDistributorTest method shouldResourceAvailabilityCappingResourcesWhenResourceCapIsGreaterThanUsedOne.

@Test(expectedExceptions = ConflictException.class, expectedExceptionsMessageRegExp = "Resources are currently in use. Denied.")
public void shouldResourceAvailabilityCappingResourcesWhenResourceCapIsGreaterThanUsedOne() throws Exception {
    // given
    doCallRealMethod().when(manager).checkResourcesAvailability(anyString(), any());
    doReturn("Denied.").when(manager).getMessage(anyString());
    ResourceImpl used = createTestResource(1000);
    doReturn(singletonList(used)).when(resourceManager).getUsedResources(any());
    ResourceImpl toCap = createTestResource(700);
    doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), singletonList(toCap))).when(resourceAggregator).deduct((Resource) any(), any());
    // when
    manager.checkResourcesAvailability(ORG_ID, singletonList(toCap));
    // then
    verify(resourceManager).getUsedResources(ORG_ID);
    verify(resourceAggregator).deduct(toCap, used);
}
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 35 with ResourceImpl

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

the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnAvailableResourcesForRootOrganization.

@Test
public void shouldReturnAvailableResourcesForRootOrganization() throws Exception {
    // given
    ResourceImpl availableResource = new ResourceImpl("test", 5000, "unit");
    doReturn(singletonList(availableResource)).when(availableResourcesProvider).getAvailableOrganizationResources(any());
    // when
    List<? extends Resource> availableResources = availableResourcesProvider.getAvailableResources(ROOT_ORG_ID);
    // then
    assertEquals(availableResources.size(), 1);
    assertEquals(availableResources.get(0), availableResource);
    verify(availableResourcesProvider).getAvailableResources(ROOT_ORG_ID);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) 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