|
@@ -20,17 +20,19 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.scheduler;
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
-import static org.mockito.Mockito.spy;
|
|
|
-import static org.mockito.Mockito.doNothing;
|
|
|
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationAttemptId;
|
|
|
import org.apache.hadoop.yarn.api.records.ApplicationId;
|
|
|
import org.apache.hadoop.yarn.api.records.ContainerId;
|
|
|
import org.apache.hadoop.yarn.api.records.ExecutionType;
|
|
|
+import org.apache.hadoop.yarn.api.records.Resource;
|
|
|
+import org.apache.hadoop.yarn.api.records.ResourceUtilization;
|
|
|
import org.apache.hadoop.yarn.event.AsyncDispatcher;
|
|
|
import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.NodeManager.NMContext;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.ContainerManager;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.ContainerImpl;
|
|
|
+import org.apache.hadoop.yarn.server.nodemanager.containermanager.monitor.ContainersMonitor;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.metrics.NodeManagerMetrics;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.recovery.NMStateStoreService
|
|
|
.RecoveredContainerState;
|
|
@@ -40,7 +42,6 @@ import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
|
import org.mockito.InjectMocks;
|
|
|
import org.mockito.Mock;
|
|
|
-import org.mockito.Mockito;
|
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
|
|
/**
|
|
@@ -49,6 +50,10 @@ import org.mockito.MockitoAnnotations;
|
|
|
* ExecutionType.
|
|
|
*/
|
|
|
public class TestContainerSchedulerRecovery {
|
|
|
+ private static final Resource CONTAINER_SIZE =
|
|
|
+ Resource.newInstance(1024, 4);
|
|
|
+ private static final ResourceUtilization ZERO =
|
|
|
+ ResourceUtilization.newInstance(0, 0, 0.0f);
|
|
|
|
|
|
@Mock private NMContext context;
|
|
|
|
|
@@ -66,13 +71,9 @@ public class TestContainerSchedulerRecovery {
|
|
|
|
|
|
@Mock private ContainerId containerId;
|
|
|
|
|
|
- @Mock private AllocationBasedResourceUtilizationTracker
|
|
|
- allocationBasedResourceUtilizationTracker;
|
|
|
-
|
|
|
- @InjectMocks private ContainerScheduler tempContainerScheduler =
|
|
|
+ @InjectMocks private ContainerScheduler spy =
|
|
|
new ContainerScheduler(context, dispatcher, metrics, 0);
|
|
|
|
|
|
- private ContainerScheduler spy;
|
|
|
|
|
|
private RecoveredContainerState createRecoveredContainerState(
|
|
|
RecoveredContainerStatus status) {
|
|
@@ -81,16 +82,32 @@ public class TestContainerSchedulerRecovery {
|
|
|
return mockState;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Set up the {@link ContainersMonitor} dependency of
|
|
|
+ * {@link ResourceUtilizationTracker} so that we can
|
|
|
+ * verify the resource utilization.
|
|
|
+ */
|
|
|
+ private void setupContainerMonitor() {
|
|
|
+ ContainersMonitor containersMonitor = mock(ContainersMonitor.class);
|
|
|
+ when(containersMonitor.getVCoresAllocatedForContainers()).thenReturn(10L);
|
|
|
+ when(containersMonitor.getPmemAllocatedForContainers()).thenReturn(10240L);
|
|
|
+ when(containersMonitor.getVmemRatio()).thenReturn(1.0f);
|
|
|
+ when(containersMonitor.getVmemAllocatedForContainers()).thenReturn(10240L);
|
|
|
+
|
|
|
+ ContainerManager cm = mock(ContainerManager.class);
|
|
|
+ when(cm.getContainersMonitor()).thenReturn(containersMonitor);
|
|
|
+ when(context.getContainerManager()).thenReturn(cm);
|
|
|
+ }
|
|
|
+
|
|
|
@Before public void setUp() throws Exception {
|
|
|
MockitoAnnotations.initMocks(this);
|
|
|
- spy = spy(tempContainerScheduler);
|
|
|
+ setupContainerMonitor();
|
|
|
when(container.getContainerId()).thenReturn(containerId);
|
|
|
+ when(container.getResource()).thenReturn(CONTAINER_SIZE);
|
|
|
when(containerId.getApplicationAttemptId()).thenReturn(appAttemptId);
|
|
|
when(containerId.getApplicationAttemptId().getApplicationId())
|
|
|
.thenReturn(appId);
|
|
|
when(containerId.getContainerId()).thenReturn(123L);
|
|
|
- doNothing().when(allocationBasedResourceUtilizationTracker)
|
|
|
- .addContainerResources(container);
|
|
|
}
|
|
|
|
|
|
@After public void tearDown() {
|
|
@@ -112,8 +129,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(1, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as QUEUED, OPPORTUNISTIC,
|
|
@@ -132,8 +148,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(1, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as PAUSED, GUARANTEED,
|
|
@@ -152,8 +167,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(1, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as PAUSED, OPPORTUNISTIC,
|
|
@@ -172,8 +186,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(1, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as LAUNCHED, GUARANTEED,
|
|
@@ -192,8 +205,9 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(1, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(1))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(
|
|
|
+ ResourceUtilization.newInstance(1024, 1024, 4.0f),
|
|
|
+ spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as LAUNCHED, OPPORTUNISTIC,
|
|
@@ -212,8 +226,9 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(1, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(1))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(
|
|
|
+ ResourceUtilization.newInstance(1024, 1024, 4.0f),
|
|
|
+ spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as REQUESTED, GUARANTEED,
|
|
@@ -232,8 +247,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as REQUESTED, OPPORTUNISTIC,
|
|
@@ -252,8 +266,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as COMPLETED, GUARANTEED,
|
|
@@ -272,8 +285,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as COMPLETED, OPPORTUNISTIC,
|
|
@@ -292,8 +304,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as GUARANTEED but no executionType set,
|
|
@@ -311,8 +322,7 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
|
|
|
/*Test if a container is recovered as PAUSED but no executionType set,
|
|
@@ -330,7 +340,6 @@ public class TestContainerSchedulerRecovery {
|
|
|
assertEquals(0, spy.getNumQueuedGuaranteedContainers());
|
|
|
assertEquals(0, spy.getNumQueuedOpportunisticContainers());
|
|
|
assertEquals(0, spy.getNumRunningContainers());
|
|
|
- Mockito.verify(allocationBasedResourceUtilizationTracker, Mockito.times(0))
|
|
|
- .addContainerResources(container);
|
|
|
+ assertEquals(ZERO, spy.getCurrentUtilization());
|
|
|
}
|
|
|
}
|