//we delete the file and also change the data type each time through the loop
//to make sure we get the cached chunk.
public void resendAfterStop(String adaptor) throws IOException,
ChukwaAgent.AlreadyRunningException, InterruptedException {
ChukwaAgent agent = new ChukwaAgent(conf);
String ADAPTORID = "adaptor_test" + System.currentTimeMillis();
String STR = "test data";
int PORTNO = 9878;
DatagramSocket send = new DatagramSocket();
byte[] buf = STR.getBytes();
DatagramPacket p = new DatagramPacket(buf, buf.length);
p.setSocketAddress(new InetSocketAddress("127.0.0.1",PORTNO));
assertEquals(0, agent.adaptorCount());
String name =agent.processAddCommand("add "+ ADAPTORID + " = "+adaptor+" UDPAdaptor raw "+PORTNO+ " 0");
assertEquals(name, ADAPTORID);
Thread.sleep(500);
send.send(p);
for(int i=0; i< 5; ++i) {
Chunk c = chunks.waitForAChunk(5000);
System.out.println("received " + i);
assertNotNull(c);
String dat = new String(c.getData());
assertTrue(dat.equals(STR));
assertTrue(c.getDataType().equals("raw"));
assertEquals(c.getSeqID(), STR.length());
agent.stopAdaptor(name, AdaptorShutdownPolicy.RESTARTING);
Thread.sleep(500); //for socket to deregister
name =agent.processAddCommand("add "+ADAPTORID + " = "+adaptor+" UDPAdaptor raw "+PORTNO + " 0");
assertEquals(name, ADAPTORID);
}
Chunk c = chunks.waitForAChunk(5000);
Thread.sleep(500);
buf = "different data".getBytes();
p = new DatagramPacket(buf, buf.length);
p.setSocketAddress(new InetSocketAddress("127.0.0.1",PORTNO));
send.send(p);
c = chunks.waitForAChunk(5000);
assertNotNull(c);
assertEquals(buf.length + STR.length(), c.getSeqID());
agent.stopAdaptor(name, true);
assertEquals(0, agent.adaptorCount());
Thread.sleep(500);//before re-binding
agent.shutdown();
}