Thread.sleep(1000);
ChukwaConfiguration cc = new ChukwaConfiguration();
int portno = cc.getInt("chukwaAgent.control.port", 9093);
ChukwaAgentController cli = new ChukwaAgentController("localhost", portno);
File tmpOutput = new File("/tmp/chukwaTest");
FileOutputStream fos = new FileOutputStream(tmpOutput);
Random r = new Random();
boolean failed = false;
byte[] randomData = new byte[2000];
r.nextBytes(randomData);
randomData[1999] = '\n';//need data to end with \n since default tailer uses that
fos.write(randomData);
fos.flush();
fos.close();
cli.addFile("unknown", tmpOutput.getAbsolutePath());
assertEquals(1, agent.adaptorCount());
cli.removeFile("unknown", tmpOutput.getAbsolutePath());
assertEquals(0, agent.adaptorCount());
org.apache.hadoop.chukwa.Chunk readIn = readInData.readOutChunk(randomData.length, 5000);
byte[] readInBytes = readIn.getData();
if(readInBytes.length != randomData.length)
{
System.err.println("FAIL: input ended at " + readInBytes.length + " bytes");
failed = true;
} else {
for(int i = 0; i < randomData.length ; ++i) {
byte next = readInBytes[i];
if(next != randomData[i]) {
System.err.println("FAIL: saw byte " + next + " at position " + i +
", expected " + randomData[i]);
failed = true;
break;
}
}
}
cli.removeAll();
tmpOutput.delete();
assertFalse(failed);
System.out.println("done");
} catch(Exception e) {
e.printStackTrace();