FlumeSpecException, InterruptedException {
File f = FileUtil.createTempFile("multitemp1", ".tmp");
f.deleteOnExit();
File f2 = FileUtil.createTempFile("multitemp2", ".tmp");
f2.deleteOnExit();
final MemorySinkSource snk = new MemorySinkSource();
final EventSource src = TailSource.multiTailBuilder().build(
LogicalNodeContext.testingContext(), f.getAbsolutePath(),
f2.getAbsolutePath());
final CountDownLatch done = new CountDownLatch(1);
final int count = 60;
Thread t = new Thread() {
@Override
public void run() {
try {
src.open();
snk.open();
EventUtil.dumpN(count, src, snk);
src.close();
snk.close();
done.countDown();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
t.start();
int log1 = 0, log2 = 0;
FileWriter fw = new FileWriter(f);
FileWriter fw2 = new FileWriter(f2);
for (int i = 0; i < count; i++) {
if (Math.random() > 0.5) {
fw.append("Line " + i + "\n");
fw.flush();
log1++;
} else {
fw2.append("Line " + i + "\n");
fw2.flush();
log2++;
}
}
fw.close();
fw2.close();
assertTrue(done.await(15, TimeUnit.SECONDS));
Event e = null;
while ((e = snk.next()) != null) {
byte[] fn = e.get(TailSource.A_TAILSRCFILE);
String sfn = new String(fn);
if (!sfn.equals(f.getName()) && !sfn.equals(f2.getName())) {
Assert.fail("didn't have tail src file metadata! " + sfn + " != "
+ f.getName() + " or " + f2.getName());