|
@@ -20,8 +20,10 @@ package org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.resourc
|
|
|
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
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.conf.YarnConfiguration;
|
|
|
+import org.apache.hadoop.yarn.security.ContainerTokenIdentifier;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container;
|
|
|
import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.privileged.PrivilegedOperation;
|
|
|
import org.junit.Before;
|
|
@@ -32,6 +34,9 @@ import java.util.List;
|
|
|
|
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
+/**
|
|
|
+ * Unit test for CGroupsMemoryResourceHandlerImpl.
|
|
|
+ */
|
|
|
public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
|
|
|
private CGroupsHandler mockCGroupsHandler;
|
|
@@ -60,8 +65,7 @@ public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
try {
|
|
|
cGroupsMemoryResourceHandler.bootstrap(conf);
|
|
|
Assert.fail("Pmem check should not be allowed to run with cgroups");
|
|
|
- }
|
|
|
- catch(ResourceHandlerException re) {
|
|
|
+ } catch(ResourceHandlerException re) {
|
|
|
// do nothing
|
|
|
}
|
|
|
conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false);
|
|
@@ -69,8 +73,7 @@ public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
try {
|
|
|
cGroupsMemoryResourceHandler.bootstrap(conf);
|
|
|
Assert.fail("Vmem check should not be allowed to run with cgroups");
|
|
|
- }
|
|
|
- catch(ResourceHandlerException re) {
|
|
|
+ } catch(ResourceHandlerException re) {
|
|
|
// do nothing
|
|
|
}
|
|
|
}
|
|
@@ -84,8 +87,7 @@ public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
try {
|
|
|
cGroupsMemoryResourceHandler.bootstrap(conf);
|
|
|
Assert.fail("Negative values for swappiness should not be allowed.");
|
|
|
- }
|
|
|
- catch (ResourceHandlerException re) {
|
|
|
+ } catch (ResourceHandlerException re) {
|
|
|
// do nothing
|
|
|
}
|
|
|
try {
|
|
@@ -93,8 +95,7 @@ public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
cGroupsMemoryResourceHandler.bootstrap(conf);
|
|
|
Assert.fail("Values greater than 100 for swappiness"
|
|
|
+ " should not be allowed.");
|
|
|
- }
|
|
|
- catch (ResourceHandlerException re) {
|
|
|
+ } catch (ResourceHandlerException re) {
|
|
|
// do nothing
|
|
|
}
|
|
|
conf.setInt(YarnConfiguration.NM_MEMORY_RESOURCE_CGROUPS_SWAPPINESS, 60);
|
|
@@ -169,4 +170,32 @@ public class TestCGroupsMemoryResourceHandlerImpl {
|
|
|
public void testTeardown() throws Exception {
|
|
|
Assert.assertNull(cGroupsMemoryResourceHandler.teardown());
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testOpportunistic() throws Exception {
|
|
|
+ Configuration conf = new YarnConfiguration();
|
|
|
+ conf.setBoolean(YarnConfiguration.NM_PMEM_CHECK_ENABLED, false);
|
|
|
+ conf.setBoolean(YarnConfiguration.NM_VMEM_CHECK_ENABLED, false);
|
|
|
+
|
|
|
+ cGroupsMemoryResourceHandler.bootstrap(conf);
|
|
|
+ ContainerTokenIdentifier tokenId = mock(ContainerTokenIdentifier.class);
|
|
|
+ when(tokenId.getExecutionType()).thenReturn(ExecutionType.OPPORTUNISTIC);
|
|
|
+ Container container = mock(Container.class);
|
|
|
+ String id = "container_01_01";
|
|
|
+ ContainerId mockContainerId = mock(ContainerId.class);
|
|
|
+ when(mockContainerId.toString()).thenReturn(id);
|
|
|
+ when(container.getContainerId()).thenReturn(mockContainerId);
|
|
|
+ when(container.getContainerTokenIdentifier()).thenReturn(tokenId);
|
|
|
+ when(container.getResource()).thenReturn(Resource.newInstance(1024, 2));
|
|
|
+ cGroupsMemoryResourceHandler.preStart(container);
|
|
|
+ verify(mockCGroupsHandler, times(1))
|
|
|
+ .updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id,
|
|
|
+ CGroupsHandler.CGROUP_PARAM_MEMORY_SOFT_LIMIT_BYTES, "0M");
|
|
|
+ verify(mockCGroupsHandler, times(1))
|
|
|
+ .updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id,
|
|
|
+ CGroupsHandler.CGROUP_PARAM_MEMORY_SWAPPINESS, "100");
|
|
|
+ verify(mockCGroupsHandler, times(1))
|
|
|
+ .updateCGroupParam(CGroupsHandler.CGroupController.MEMORY, id,
|
|
|
+ CGroupsHandler.CGROUP_PARAM_MEMORY_HARD_LIMIT_BYTES, "1024M");
|
|
|
+ }
|
|
|
}
|