YARN-186. Coverage fixing LinuxContainerExecutor (Aleksey Gorshkov via bobby)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1407171 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ee6eb8430
commit
8a1f333707
|
@ -169,6 +169,9 @@ Release 0.23.5 - UNRELEASED
|
|||
YARN-32. Fix TestApplicationTokens to not depend on test order and thus pass
|
||||
on JDK7. (vinodkv)
|
||||
|
||||
YARN-186. Coverage fixing LinuxContainerExecutor (Aleksey Gorshkov via
|
||||
bobby)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -26,11 +26,13 @@ import java.io.File;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.LineNumberReader;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
|
@ -46,7 +48,6 @@ import org.junit.Test;
|
|||
|
||||
public class TestLinuxContainerExecutorWithMocks {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final Log LOG = LogFactory
|
||||
.getLog(TestLinuxContainerExecutorWithMocks.class);
|
||||
|
||||
|
@ -54,6 +55,7 @@ public class TestLinuxContainerExecutorWithMocks {
|
|||
private final File mockParamFile = new File("./params.txt");
|
||||
private LocalDirsHandlerService dirsHandler;
|
||||
|
||||
|
||||
private void deleteMockParamFile() {
|
||||
if(mockParamFile.exists()) {
|
||||
mockParamFile.delete();
|
||||
|
@ -126,8 +128,102 @@ public class TestLinuxContainerExecutorWithMocks {
|
|||
StringUtils.join(",", dirsHandler.getLocalDirs()),
|
||||
StringUtils.join(",", dirsHandler.getLogDirs())),
|
||||
readMockParams());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStartLocalizer() throws IOException {
|
||||
|
||||
|
||||
InetSocketAddress address = InetSocketAddress.createUnresolved("localhost", 8040);
|
||||
Path nmPrivateCTokensPath= new Path("file:///bin/nmPrivateCTokensPath");
|
||||
|
||||
try {
|
||||
mockExec.startLocalizer(nmPrivateCTokensPath, address, "test", "application_0", "12345", dirsHandler.getLocalDirs(), dirsHandler.getLogDirs());
|
||||
List<String> result=readMockParams();
|
||||
Assert.assertEquals(result.size(), 16);
|
||||
Assert.assertEquals(result.get(0), "test");
|
||||
Assert.assertEquals(result.get(1), "0" );
|
||||
Assert.assertEquals(result.get(2),"application_0" );
|
||||
Assert.assertEquals(result.get(3), "/bin/nmPrivateCTokensPath");
|
||||
Assert.assertEquals(result.get(7), "-classpath" );
|
||||
Assert.assertEquals(result.get(10),"org.apache.hadoop.yarn.server.nodemanager.containermanager.localizer.ContainerLocalizer" );
|
||||
Assert.assertEquals(result.get(11), "test");
|
||||
Assert.assertEquals(result.get(12), "application_0");
|
||||
Assert.assertEquals(result.get(13),"12345" );
|
||||
Assert.assertEquals(result.get(14),"localhost" );
|
||||
Assert.assertEquals(result.get(15),"8040" );
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
LOG.error("Error:"+e.getMessage(),e);
|
||||
Assert.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContainerLaunchError() throws IOException {
|
||||
|
||||
// reinitialize executer
|
||||
File f = new File("./src/test/resources/mock-container-executer-with-error");
|
||||
if (!f.canExecute()) {
|
||||
f.setExecutable(true);
|
||||
}
|
||||
String executorPath = f.getAbsolutePath();
|
||||
Configuration conf = new Configuration();
|
||||
conf.set(YarnConfiguration.NM_LINUX_CONTAINER_EXECUTOR_PATH, executorPath);
|
||||
conf.set(YarnConfiguration.NM_LOCAL_DIRS, "file:///bin/echo");
|
||||
conf.set(YarnConfiguration.NM_LOG_DIRS, "file:///dev/null");
|
||||
|
||||
mockExec = new LinuxContainerExecutor();
|
||||
dirsHandler = new LocalDirsHandlerService();
|
||||
dirsHandler.init(conf);
|
||||
mockExec.setConf(conf);
|
||||
|
||||
String appSubmitter = "nobody";
|
||||
String cmd = String
|
||||
.valueOf(LinuxContainerExecutor.Commands.LAUNCH_CONTAINER.getValue());
|
||||
String appId = "APP_ID";
|
||||
String containerId = "CONTAINER_ID";
|
||||
Container container = mock(Container.class);
|
||||
ContainerId cId = mock(ContainerId.class);
|
||||
ContainerLaunchContext context = mock(ContainerLaunchContext.class);
|
||||
HashMap<String, String> env = new HashMap<String, String>();
|
||||
|
||||
when(container.getContainerID()).thenReturn(cId);
|
||||
when(container.getLaunchContext()).thenReturn(context);
|
||||
|
||||
when(cId.toString()).thenReturn(containerId);
|
||||
|
||||
when(context.getEnvironment()).thenReturn(env);
|
||||
|
||||
Path scriptPath = new Path("file:///bin/echo");
|
||||
Path tokensPath = new Path("file:///dev/null");
|
||||
Path workDir = new Path("/tmp");
|
||||
Path pidFile = new Path(workDir, "pid.txt");
|
||||
|
||||
mockExec.activateContainer(cId, pidFile);
|
||||
int ret = mockExec.launchContainer(container, scriptPath, tokensPath,
|
||||
appSubmitter, appId, workDir, dirsHandler.getLocalDirs(),
|
||||
dirsHandler.getLogDirs());
|
||||
Assert.assertNotSame(0, ret);
|
||||
assertEquals(Arrays.asList(appSubmitter, cmd, appId, containerId,
|
||||
workDir.toString(), "/bin/echo", "/dev/null", pidFile.toString(),
|
||||
StringUtils.join(",", dirsHandler.getLocalDirs()),
|
||||
StringUtils.join(",", dirsHandler.getLogDirs())), readMockParams());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInit() throws Exception {
|
||||
|
||||
mockExec.init();
|
||||
assertEquals(Arrays.asList("--checksetup"), readMockParams());
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testContainerKill() throws IOException {
|
||||
String appSubmitter = "nobody";
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
for PARAM in "$@"
|
||||
do
|
||||
echo $PARAM;
|
||||
done > params.txt
|
||||
|
||||
exec badcommand
|
Loading…
Reference in New Issue