private static ResourceScheduler mockResourceScheduler() { ResourceScheduler scheduler = mock(ResourceScheduler.class); when(scheduler.getMinimumResourceCapability()).thenReturn( Resources.createResource( YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_MB)); when(scheduler.getMaximumResourceCapability()).thenReturn( Resources.createResource( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB)); when(scheduler.getMaximumResourceCapability(any(String.class))).thenReturn( Resources.createResource( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB)); when(scheduler.getMaximumResourceCapability(anyString())).thenReturn( Resources.createResource( YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_MB)); ResourceCalculator rs = mock(ResourceCalculator.class); when(scheduler.getResourceCalculator()).thenReturn(rs); when(scheduler.getNormalizedResource(any(), any())) .thenAnswer(new Answer<Resource>() { @Override public Resource answer(InvocationOnMock invocationOnMock) throws Throwable { return (Resource) invocationOnMock.getArguments()[0]; } }); return scheduler; }
private static boolean validateIncreaseDecreaseRequest(RMContext rmContext, UpdateContainerRequest request, Resource maximumAllocation) { if (request.getCapability().getMemorySize() < 0 || request.getCapability().getMemorySize() > maximumAllocation .getMemorySize()) { return false; } if (request.getCapability().getVirtualCores() < 0 || request.getCapability().getVirtualCores() > maximumAllocation .getVirtualCores()) { return false; } ResourceScheduler scheduler = rmContext.getScheduler(); request.setCapability(scheduler .getNormalizedResource(request.getCapability(), maximumAllocation)); return true; }
Mockito.when(container.getVersion()).thenReturn(containerVersion); Mockito.when(rmContainer.getContainer()).thenReturn(container); Mockito.when(scheduler.getNormalizedResource(capabilityOk, maxAllocation)) .thenReturn(capabilityOk);