|
@@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
|
|
|
import java.io.StringWriter;
|
|
|
import java.io.Writer;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.concurrent.CountDownLatch;
|
|
|
|
|
|
import junit.framework.Assert;
|
|
|
|
|
@@ -73,6 +74,96 @@ public class TestAggregatedLogFormat {
|
|
|
fs.delete(workDirPath, true);
|
|
|
}
|
|
|
|
|
|
+ //Test for Corrupted AggregatedLogs. The Logs should not write more data
|
|
|
+ //if Logvalue.write() is called and the application is still
|
|
|
+ //appending to logs
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testForCorruptedAggregatedLogs() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ File workDir = new File(testWorkDir, "testReadAcontainerLogs1");
|
|
|
+ Path remoteAppLogFile =
|
|
|
+ new Path(workDir.getAbsolutePath(), "aggregatedLogFile");
|
|
|
+ Path srcFileRoot = new Path(workDir.getAbsolutePath(), "srcFiles");
|
|
|
+ ContainerId testContainerId = BuilderUtils.newContainerId(1, 1, 1, 1);
|
|
|
+ Path t =
|
|
|
+ new Path(srcFileRoot, testContainerId.getApplicationAttemptId()
|
|
|
+ .getApplicationId().toString());
|
|
|
+ Path srcFilePath = new Path(t, testContainerId.toString());
|
|
|
+
|
|
|
+ long numChars = 950000;
|
|
|
+
|
|
|
+ writeSrcFileAndALog(srcFilePath, "stdout", numChars, remoteAppLogFile,
|
|
|
+ srcFileRoot, testContainerId);
|
|
|
+
|
|
|
+ LogReader logReader = new LogReader(conf, remoteAppLogFile);
|
|
|
+ LogKey rLogKey = new LogKey();
|
|
|
+ DataInputStream dis = logReader.next(rLogKey);
|
|
|
+ Writer writer = new StringWriter();
|
|
|
+ try {
|
|
|
+ LogReader.readAcontainerLogs(dis, writer);
|
|
|
+ } catch (Exception e) {
|
|
|
+ if(e.toString().contains("NumberFormatException")) {
|
|
|
+ Assert.fail("Aggregated logs are corrupted.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void writeSrcFileAndALog(Path srcFilePath, String fileName, final long length,
|
|
|
+ Path remoteAppLogFile, Path srcFileRoot, ContainerId testContainerId)
|
|
|
+ throws Exception {
|
|
|
+ File dir = new File(srcFilePath.toString());
|
|
|
+ if (!dir.exists()) {
|
|
|
+ if (!dir.mkdirs()) {
|
|
|
+ throw new IOException("Unable to create directory : " + dir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ File outputFile = new File(new File(srcFilePath.toString()), fileName);
|
|
|
+ FileOutputStream os = new FileOutputStream(outputFile);
|
|
|
+ final OutputStreamWriter osw = new OutputStreamWriter(os, "UTF8");
|
|
|
+ final int ch = filler;
|
|
|
+
|
|
|
+ UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
|
+ LogWriter logWriter = new LogWriter(conf, remoteAppLogFile, ugi);
|
|
|
+
|
|
|
+ LogKey logKey = new LogKey(testContainerId);
|
|
|
+ LogValue logValue =
|
|
|
+ new LogValue(Collections.singletonList(srcFileRoot.toString()),
|
|
|
+ testContainerId);
|
|
|
+
|
|
|
+ final CountDownLatch latch = new CountDownLatch(1);
|
|
|
+
|
|
|
+ Thread t = new Thread() {
|
|
|
+ public void run() {
|
|
|
+ try {
|
|
|
+ for(int i=0; i < length/3; i++) {
|
|
|
+ osw.write(ch);
|
|
|
+ }
|
|
|
+
|
|
|
+ latch.countDown();
|
|
|
+
|
|
|
+ for(int i=0; i < (2*length)/3; i++) {
|
|
|
+ osw.write(ch);
|
|
|
+ }
|
|
|
+ osw.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ t.start();
|
|
|
+
|
|
|
+ //Wait till the osw is partially written
|
|
|
+ //aggregation starts once the ows has completed 1/3rd of its work
|
|
|
+ latch.await();
|
|
|
+
|
|
|
+ //Aggregate The Logs
|
|
|
+ logWriter.append(logKey, logValue);
|
|
|
+ logWriter.close();
|
|
|
+ }
|
|
|
+
|
|
|
//Verify the output generated by readAContainerLogs(DataInputStream, Writer)
|
|
|
@Test
|
|
|
public void testReadAcontainerLogs1() throws Exception {
|