Search in sources :

Example 36 with ResourceImpl

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

the class OrganizationDistributedResourcesDaoTest method shouldUpdateDistributedResourcesWhenStoringExistentOne.

@Test
public void shouldUpdateDistributedResourcesWhenStoringExistentOne() throws Exception {
    // given
    OrganizationDistributedResourcesImpl toStore = new OrganizationDistributedResourcesImpl(distributedResources[0].getOrganizationId(), singletonList(new ResourceImpl(TEST_RESOURCE_TYPE, 1000, "unit")));
    // when
    distributedResourcesDao.store(toStore);
    // then
    assertEquals(distributedResourcesDao.get(toStore.getOrganizationId()), copy(toStore));
}
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 37 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class OrganizationResourcesDistributorTest method shouldResourceAvailabilityCappingResourcesWhenResourceCapIsLessThanUsedOne.

@Test
public void shouldResourceAvailabilityCappingResourcesWhenResourceCapIsLessThanUsedOne() throws Exception {
    // given
    doCallRealMethod().when(manager).checkResourcesAvailability(anyString(), any());
    ResourceImpl used = createTestResource(500);
    doReturn(singletonList(used)).when(resourceManager).getUsedResources(any());
    ResourceImpl toCap = createTestResource(700);
    doReturn(createTestResource(200)).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 : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 38 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class OrganizationResourcesDistributorTest method shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne.

@Test
public void shouldRemoveResourceFromListWhenItsAmountEqualsToMinusOne() throws Exception {
    ResourceImpl toCap = new ResourceImpl("test1", 1000, "init");
    ResourceImpl toReset = new ResourceImpl("test2", -1, "init");
    List<ResourceImpl> resourcesToCap = asList(toCap, toReset);
    // when
    manager.capResources(ORG_ID, resourcesToCap);
    // then
    verify(manager).checkResourcesAvailability(ORG_ID, singletonList(toCap));
    verify(distributedResourcesDao).store(new OrganizationDistributedResourcesImpl(ORG_ID, singletonList(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 39 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

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)

Example 40 with ResourceImpl

use of org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl in project devspaces-images by redhat-developer.

the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnAvailableResourcesAsTotalMinusUsedByItselfAndItsSuborganizations.

@Test
public void shouldReturnAvailableResourcesAsTotalMinusUsedByItselfAndItsSuborganizations() throws Exception {
    // given
    ResourceImpl totalResource = new ResourceImpl("test", 9000, "unit");
    doReturn(singletonList(totalResource)).when(resourceManager).getTotalResources(anyString());
    ResourceImpl usedResource = new ResourceImpl("test", 3000, "unit");
    doReturn(singletonList(usedResource)).when(resourceManager).getUsedResources(anyString());
    ResourceImpl usedBySuborgResource = new ResourceImpl("test", 1500, "unit");
    ResourceImpl usedBySubsuborgResource = new ResourceImpl("test", 2000, "unit");
    doReturn(asList(usedBySuborgResource, usedBySubsuborgResource)).when(availableResourcesProvider).getUsedResourcesBySuborganizations(anyString());
    ResourceImpl availableResource = new ResourceImpl("test", 2500, "unit");
    doReturn(singletonList(availableResource)).when(resourceAggregator).deduct(anyList(), anyList());
    // when
    List<? extends Resource> availableResources = availableResourcesProvider.getAvailableOrganizationResources(rootOrganization);
    // then
    assertEquals(availableResources.size(), 1);
    assertEquals(availableResources.get(0), availableResource);
    verify(resourceManager).getTotalResources(ROOT_ORG_ID);
    verify(resourceManager).getUsedResources(ROOT_ORG_ID);
    verify(availableResourcesProvider).getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
    verify(resourceAggregator).deduct(singletonList(totalResource), asList(usedResource, usedBySuborgResource, usedBySubsuborgResource));
}
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