Search in sources :

Example 91 with ResourceImpl

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

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)

Example 92 with ResourceImpl

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

the class OrganizationalAccountAvailableResourcesProviderTest method shouldCalculateUsedResourceBySuborganizations.

@Test
public void shouldCalculateUsedResourceBySuborganizations() throws Exception {
    // given
    doReturn(new Page<>(singletonList(suborganization), 0, 1, 2)).doReturn(new Page<>(singletonList(subsuborganization), 1, 1, 2)).when(organizationManager).getSuborganizations(anyString(), anyInt(), anyLong());
    ResourceImpl usedBySuborgResource = new ResourceImpl("test", 1500, "unit");
    doReturn(singletonList(usedBySuborgResource)).when(resourceManager).getUsedResources(SUBORG_ID);
    ResourceImpl usedBySubsuborgResource = new ResourceImpl("test", 2000, "unit");
    doReturn(singletonList(usedBySubsuborgResource)).when(resourceManager).getUsedResources(SUBSUBORG_ID);
    // when
    List<? extends Resource> usedResources = availableResourcesProvider.getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
    // then
    assertEquals(usedResources.size(), 2);
    assertTrue(usedResources.contains(usedBySuborgResource));
    assertTrue(usedResources.contains(usedBySubsuborgResource));
    verify(organizationManager, times(2)).getSuborganizations(eq(ROOT_ORG_NAME), anyInt(), anyLong());
    verify(resourceManager).getUsedResources(SUBORG_ID);
    verify(resourceManager).getUsedResources(SUBSUBORG_ID);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Page(org.eclipse.che.api.core.Page) Test(org.testng.annotations.Test)

Example 93 with ResourceImpl

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

the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnAvailableResourcesForSuborganization.

@Test
public void shouldReturnAvailableResourcesForSuborganization() throws Exception {
    // given
    ResourceImpl parentAvailableResource = new ResourceImpl("test", 3000, "unit");
    prepareAvailableResource(ROOT_ORG_ID, parentAvailableResource);
    ResourceImpl suborgAvailableResource = new ResourceImpl("test", 5000, "unit");
    prepareAvailableResource(SUBORG_ID, suborgAvailableResource);
    doReturn(asList(parentAvailableResource, suborgAvailableResource)).when(resourceAggregator).intersection(anyList(), anyList());
    doReturn(singletonList(parentAvailableResource)).when(resourceAggregator).min(anyList());
    // when
    List<? extends Resource> availableResources = availableResourcesProvider.getAvailableResources(SUBORG_ID);
    // then
    assertEquals(availableResources.size(), 1);
    assertEquals(availableResources.get(0), parentAvailableResource);
    verify(availableResourcesProvider).getAvailableOrganizationResources(rootOrganization);
    verify(availableResourcesProvider).getAvailableOrganizationResources(suborganization);
    verify(resourceAggregator).intersection(singletonList(parentAvailableResource), singletonList(suborgAvailableResource));
    verify(resourceAggregator).min(asList(parentAvailableResource, suborgAvailableResource));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Test(org.testng.annotations.Test)

Example 94 with ResourceImpl

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

the class OrganizationalAccountAvailableResourcesProviderTest method shouldReturnExcessiveResourcesWhenUsedResourceAreGreaterThanTotal.

@Test
public void shouldReturnExcessiveResourcesWhenUsedResourceAreGreaterThanTotal() throws Exception {
    // given
    ResourceImpl totalResource = new ResourceImpl("test", 9000, "unit");
    ResourceImpl excessiveTotalResource = new ResourceImpl("test1", 1000, "unit");
    doReturn(asList(totalResource, excessiveTotalResource)).when(resourceManager).getTotalResources(anyString());
    ResourceImpl usedResource = new ResourceImpl("test", 10000, "unit");
    doReturn(singletonList(usedResource)).when(resourceManager).getUsedResources(anyString());
    doReturn(emptyList()).when(availableResourcesProvider).getUsedResourcesBySuborganizations(anyString());
    doThrow(new NoEnoughResourcesException(emptyList(), emptyList(), emptyList())).when(resourceAggregator).deduct(anyList(), anyList());
    doReturn(singletonList(excessiveTotalResource)).when(resourceAggregator).excess(anyList(), anyList());
    // when
    List<? extends Resource> availableResources = availableResourcesProvider.getAvailableOrganizationResources(rootOrganization);
    // then
    assertEquals(availableResources.size(), 1);
    assertEquals(availableResources.get(0), excessiveTotalResource);
    verify(resourceManager).getTotalResources(ROOT_ORG_ID);
    verify(resourceManager).getUsedResources(ROOT_ORG_ID);
    verify(availableResourcesProvider).getUsedResourcesBySuborganizations(ROOT_ORG_NAME);
    verify(resourceAggregator).deduct(asList(totalResource, excessiveTotalResource), singletonList(usedResource));
    verify(resourceAggregator).excess(asList(totalResource, excessiveTotalResource), singletonList(usedResource));
}
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 95 with ResourceImpl

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

the class SuborganizationResourcesProviderTest method shouldProvideResourcesForSuborganizationalAccount.

@Test
public void shouldProvideResourcesForSuborganizationalAccount() throws Exception {
    // given
    when(account.getType()).thenReturn(OrganizationImpl.ORGANIZATIONAL_ACCOUNT);
    when(organization.getParent()).thenReturn("parentOrg");
    final ResourceImpl parentNotCapedResource = new ResourceImpl("test", 1234, "unit");
    final ResourceImpl parentCapedResource = new ResourceImpl("caped", 20, "unit");
    final ResourceImpl parentUnlimitedCapedResource = new ResourceImpl("unlimited", -1, "unit");
    doReturn(asList(parentNotCapedResource, parentCapedResource, parentUnlimitedCapedResource)).when(resourceManager).getTotalResources(anyString());
    final ResourceImpl capedResourceCap = new ResourceImpl("caped", 10, "unit");
    final ResourceImpl unlimitedCapedResourceCap = new ResourceImpl("unlimited", 40, "unit");
    doReturn(asList(capedResourceCap, unlimitedCapedResourceCap)).when(resourcesDistributor).getResourcesCaps(any());
    // when
    final List<ProvidedResources> providedResources = suborganizationResourcesProvider.getResources("organization123");
    // then
    assertEquals(providedResources.size(), 1);
    assertEquals(providedResources.get(0), new ProvidedResourcesImpl(SuborganizationResourcesProvider.PARENT_RESOURCES_PROVIDER, null, "organization123", -1L, -1L, asList(parentNotCapedResource, capedResourceCap, unlimitedCapedResourceCap)));
    verify(accountManager).getById("organization123");
    verify(organizationManager).getById("organization123");
    verify(resourcesDistributor).getResourcesCaps("organization123");
    verify(resourceManager).getTotalResources("parentOrg");
}
Also used : ProvidedResourcesImpl(org.eclipse.che.multiuser.resource.spi.impl.ProvidedResourcesImpl) ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) ProvidedResources(org.eclipse.che.multiuser.resource.model.ProvidedResources) 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