diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java index bda489f..a0882b8 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-client/src/test/java/org/apache/hadoop/yarn/client/cli/TestLogsCLI.java @@ -414,9 +414,9 @@ public ContainerReport getContainerReport(String containerIdStr) sysOutStream.reset(); String logMessage = "Hello container_0_0001_01_000003 in stdout!"; - int fileContentSize = logMessage.getBytes().length; - int tailContentSize = "\nEnd of LogType:syslog\n\n".getBytes().length; - + String logContentIdex = "Log Contents:\n"; + int contentOffset = + fullContext.indexOf(logContentIdex) + logContentIdex.length(); // specify how many bytes we should get from logs // specify a position number, it would get the first n bytes from // container log @@ -425,8 +425,7 @@ public ContainerReport getContainerReport(String containerIdStr) "-size", "5"}); assertTrue(exitCode == 0); Assert.assertEquals(new String(logMessage.getBytes(), 0, 5), - new String(sysOutStream.toByteArray(), - (fullContextSize - fileContentSize - tailContentSize), 5)); + new String(sysOutStream.toByteArray(), contentOffset, 5)); sysOutStream.reset(); // specify a negative number, it would get the last n bytes from @@ -437,8 +436,7 @@ public ContainerReport getContainerReport(String containerIdStr) assertTrue(exitCode == 0); Assert.assertEquals(new String(logMessage.getBytes(), logMessage.getBytes().length - 5, 5), - new String(sysOutStream.toByteArray(), - (fullContextSize - fileContentSize - tailContentSize), 5)); + new String(sysOutStream.toByteArray(), contentOffset, 5)); sysOutStream.reset(); long negative = (fullContextSize + 1000) * (-1);