// Let attempt3 also write some logs
writeRealChars(attempt1, attempt3, LogName.SYSLOG, 225, 'C');
// Finish the JVM.
JVMInfo jvmInfo = new JVMInfo(attemptDir,
Arrays.asList((new Task[] { task1, task2, task3 })));
logManager.addLogEvent(new JvmFinishedEvent(jvmInfo));
// The log-file should now be truncated.
assertTrue(attemptDir.exists());
File logFile = TaskLog.getTaskLogFile(attempt1, false, LogName.SYSLOG);
assertEquals(400 + (2 * truncatedMsgSize), logFile.length());
// The index files should also be proper.
assertEquals(150 + truncatedMsgSize, getAllLogsFileLengths(attempt1, false)
.get(LogName.SYSLOG).longValue());
assertEquals(100, getAllLogsFileLengths(attempt2, false)
.get(LogName.SYSLOG).longValue());
assertEquals(150 + truncatedMsgSize, getAllLogsFileLengths(attempt3, false)
.get(LogName.SYSLOG).longValue());
// assert data for attempt1
String syslog = TestMiniMRMapRedDebugScript.readTaskLog(LogName.SYSLOG,
attempt1, false);
assertTrue(syslog.startsWith(TaskLogsTruncater.TRUNCATED_MSG));
String truncatedLog = syslog.substring(truncatedMsgSize);
for (int i = 0 ; i < 150; i++) {
assertEquals("Truncation didn't happen properly. At "
+ (i + 1) + "th byte, expected 'A' but found "
+ truncatedLog.charAt(i), 'A', truncatedLog.charAt(i));
}
// assert data for attempt2
syslog = TestMiniMRMapRedDebugScript.readTaskLog(LogName.SYSLOG,
attempt2, false);
for (int i = 0 ; i < 100; i++) {
assertEquals("Truncation didn't happen properly. At "
+ (i + 1) + "th byte, expected 'B' but found "
+ truncatedLog.charAt(i), 'B', syslog.charAt(i));
}
// assert data for attempt3
syslog = TestMiniMRMapRedDebugScript.readTaskLog(LogName.SYSLOG,
attempt3, false);
assertTrue(syslog.startsWith(TaskLogsTruncater.TRUNCATED_MSG));
truncatedLog = syslog.substring(truncatedMsgSize);
for (int i = 0 ; i < 150; i++) {
assertEquals("Truncation didn't happen properly. At "
+ (i + 1) + "th byte, expected 'C' but found "
+ truncatedLog.charAt(i), 'C', truncatedLog.charAt(i));
}
logManager.addLogEvent(new JvmFinishedEvent(jvmInfo));
// First and third attempts' logs are only truncated, so include 2*length of
// TRUNCATED_MSG header
assertEquals(400 + 2 * truncatedMsgSize, logFile.length());
}