Skip to content

Commit

Permalink
YARN-11534. Added unit tests
Browse files Browse the repository at this point in the history
Change-Id: I379f76d5c45f7371a81fb6a01bbb4f2807f27ef6
  • Loading branch information
p-szucs committed Jul 20, 2023
1 parent 5069cc1 commit ce2c183
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,7 @@ public boolean signalContainer(ContainerSignalContext ctx)
LOG.warn("Error in signalling container {} with {}; exit = {}",
pid, signal, retCode, e);
logOutput(e.getOutput());

// In ContainerExecutionException -1 is the default value for the exit code.
// If it remained unset, we can treat the signalling as interrupted.
if (retCode == -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.apache.hadoop.yarn.server.nodemanager.containermanager.linux.runtime.LinuxContainerRuntime;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerExecutionException;
import org.apache.hadoop.yarn.server.nodemanager.containermanager.runtime.ContainerRuntimeContext;
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerExecContext;
import org.apache.hadoop.yarn.server.nodemanager.executor.ContainerReapContext;
import org.slf4j.Logger;
Expand All @@ -41,6 +46,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.util.ArrayList;
Expand Down Expand Up @@ -725,6 +731,44 @@ public void testGetLocalResources() throws Exception {
verify(lce, times(1)).getLocalResources(container);
}

@Test
public void testSignalContainerFailureWhenExitCodeIsPresentInTheException()
throws ContainerExecutionException {
LinuxContainerRuntime containerRuntime = mock(LinuxContainerRuntime.class);
LinuxContainerExecutor containerExecutor = spy(new LinuxContainerExecutor(
containerRuntime));
ContainerSignalContext signalContext = new ContainerSignalContext.Builder().build();
ContainerExecutionException testException =
new ContainerExecutionException("exceptionWithExitCode", 123);

doNothing().when(containerExecutor).verifyUsernamePattern(any());
doThrow(testException)
.when(containerRuntime)
.signalContainer(any(ContainerRuntimeContext.class));

assertThrows(IOException.class,
() -> containerExecutor.signalContainer(signalContext));
}

@Test
public void testSignalContainerFailureWhenExitCodeIsNotPresentInTheException()
throws ContainerExecutionException {
LinuxContainerRuntime containerRuntime = mock(LinuxContainerRuntime.class);
LinuxContainerExecutor containerExecutor = spy(new LinuxContainerExecutor(
containerRuntime));
ContainerSignalContext signalContext = new ContainerSignalContext.Builder().build();
ContainerExecutionException testException =
new ContainerExecutionException("exceptionWithoutExitCode");

Check failure on line 762 in hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java

View check run for this annotation

ASF Cloudbees Jenkins ci-hadoop / Apache Yetus

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java#L762

blanks: end of line
doNothing().when(containerExecutor).verifyUsernamePattern(any());
doThrow(testException)
.when(containerRuntime)
.signalContainer(any(ContainerRuntimeContext.class));

Check failure on line 767 in hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java

View check run for this annotation

ASF Cloudbees Jenkins ci-hadoop / Apache Yetus

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestLinuxContainerExecutor.java#L767

blanks: end of line
assertThrows(InterruptedIOException.class,
() -> containerExecutor.signalContainer(signalContext));
}

@Deprecated
private static class TestResourceHandler implements LCEResourcesHandler {
static Set<ContainerId> postExecContainers = new HashSet<ContainerId>();
Expand Down

0 comments on commit ce2c183

Please sign in to comment.