Search in sources :

Example 21 with Resource

use of org.eclipse.che.multiuser.resource.model.Resource in project devspaces-images by redhat-developer.

the class AbstractExhaustibleResourceTest method shouldFindSumResourcesAmountsOnResourcesAggregation.

@Test
public void shouldFindSumResourcesAmountsOnResourcesAggregation() throws Exception {
    final Resource aggregate = resourceType.aggregate(new ResourceImpl(TestResourceType.ID, 1000, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
    assertEquals(aggregate.getType(), TestResourceType.ID);
    assertEquals(aggregate.getAmount(), 1500);
    assertEquals(aggregate.getUnit(), TestResourceType.UNIT);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Example 22 with Resource

use of org.eclipse.che.multiuser.resource.model.Resource in project devspaces-images by redhat-developer.

the class AbstractExhaustibleResourceTest method shouldFindDifferenceResourcesAmountsOnResourcesDeduction.

@Test
public void shouldFindDifferenceResourcesAmountsOnResourcesDeduction() throws Exception {
    final Resource deducted = resourceType.deduct(new ResourceImpl(TestResourceType.ID, 1000, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, 500, TestResourceType.UNIT));
    assertEquals(deducted.getType(), TestResourceType.ID);
    assertEquals(deducted.getAmount(), 500);
    assertEquals(deducted.getUnit(), TestResourceType.UNIT);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Example 23 with Resource

use of org.eclipse.che.multiuser.resource.model.Resource in project devspaces-images by redhat-developer.

the class AbstractExhaustibleResourceTest method shouldReturnResourceWithMinusOneAmountWhenSecondResourceHasMinusOneAmountOnResourcesDeduction.

@Test
public void shouldReturnResourceWithMinusOneAmountWhenSecondResourceHasMinusOneAmountOnResourcesDeduction() throws Exception {
    final Resource aggregate = resourceType.aggregate(new ResourceImpl(TestResourceType.ID, 2000, TestResourceType.UNIT), new ResourceImpl(TestResourceType.ID, -1, TestResourceType.UNIT));
    assertEquals(aggregate.getType(), TestResourceType.ID);
    assertEquals(aggregate.getAmount(), -1);
    assertEquals(aggregate.getUnit(), TestResourceType.UNIT);
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Example 24 with Resource

use of org.eclipse.che.multiuser.resource.model.Resource in project devspaces-images by redhat-developer.

the class ResourceManagerTest method testGetsAccountTotalResources.

@Test
public void testGetsAccountTotalResources() throws Exception {
    final List<Resource> res = ImmutableList.of(new ResourceImpl("RAM", 2048, "mb"), new ResourceImpl("timeout", 15, "minutes"));
    doReturn(res).when(providedResources).getResources();
    List<? extends Resource> actual = resourceManager.getTotalResources(ACCOUNT_ID);
    assertEquals(actual.size(), res.size());
    assertTrue(actual.containsAll(res));
}
Also used : ResourceImpl(org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Example 25 with Resource

use of org.eclipse.che.multiuser.resource.model.Resource in project devspaces-images by redhat-developer.

the class RamResourceUsageTrackerTest method shouldReturnUsedRamOfRunningWorkspaceForGivenAccount.

@Test
public void shouldReturnUsedRamOfRunningWorkspaceForGivenAccount() throws Exception {
    mockWorkspaces(createWorkspace(WorkspaceStatus.RUNNING, 1000, 500, 500));
    when(envRamCalculator.calculate(any(Runtime.class))).thenReturn(2000L);
    final Optional<Resource> usedRamOpt = ramUsageTracker.getUsedResource(ACCOUNT_ID);
    assertTrue(usedRamOpt.isPresent());
    final Resource usedRam = usedRamOpt.get();
    assertEquals(usedRam.getType(), RamResourceType.ID);
    assertEquals(usedRam.getAmount(), 2000L);
    assertEquals(usedRam.getUnit(), RamResourceType.UNIT);
    verify(accountManager).getById(ACCOUNT_ID);
    verify(workspaceManager).getByNamespace(anyString(), anyBoolean(), anyInt(), anyLong());
}
Also used : Runtime(org.eclipse.che.api.core.model.workspace.Runtime) Resource(org.eclipse.che.multiuser.resource.model.Resource) Test(org.testng.annotations.Test)

Aggregations

Resource (org.eclipse.che.multiuser.resource.model.Resource)52 ResourceImpl (org.eclipse.che.multiuser.resource.spi.impl.ResourceImpl)24 Test (org.testng.annotations.Test)24 ArrayList (java.util.ArrayList)14 NotFoundException (org.eclipse.che.api.core.NotFoundException)12 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)12 Optional (java.util.Optional)10 Inject (javax.inject.Inject)10 Singleton (javax.inject.Singleton)10 AccountManager (org.eclipse.che.account.api.AccountManager)10 Account (org.eclipse.che.account.shared.model.Account)10 ServerException (org.eclipse.che.api.core.ServerException)10 ResourceUsageTracker (org.eclipse.che.multiuser.resource.api.ResourceUsageTracker)10 NoEnoughResourcesException (org.eclipse.che.multiuser.resource.api.exception.NoEnoughResourcesException)10 List (java.util.List)8 WorkspaceManager (org.eclipse.che.api.workspace.server.WorkspaceManager)8 VisibleForTesting (com.google.common.annotations.VisibleForTesting)6 HashMap (java.util.HashMap)6 Collectors (java.util.stream.Collectors)6 Provider (javax.inject.Provider)6