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));
}
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);
}
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();
}
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);
}
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));
}
Aggregations