File f = File.createTempFile("truncate", ".bar");
f.deleteOnExit();
FileWriter fw = new FileWriter(f);
ExecNioSource.Builder builder = new ExecNioSource.Builder();
EventSource source = builder.build("tail -F " + f.getAbsolutePath());
source.open();
fw.write("foo\n");
fw.flush();
Event e = source.next();
assertTrue(Arrays.equals("foo".getBytes(), e.getBody()));
// this case inserts an extremely long line.
int max = (int) FlumeConfiguration.get().getEventMaxSizeBytes();
int tooBig = max * 10;
byte[] data = new byte[tooBig];
for (int i = 0; i < data.length; i++) {
data[i] = 'a';
}
fw.write(new String(data) + "\n");
fw.flush();
e = source.next();
assertEquals(max, e.getBody().length);
// back to previous test
fw.write("baz\n");
fw.flush();
e = source.next();
assertTrue(Arrays.equals("baz".getBytes(), e.getBody()));
source.close();
}