String outputDirectory = buildConf(conf);
ServletCollector collector = new ServletCollector(conf);
Server collectorServ = startCollectorOnPort(conf, PORTNO, collector);
Thread.sleep(1000);
ChukwaAgent agent = new ChukwaAgent(conf);
HttpConnector conn = new HttpConnector(agent, "http://localhost:"+PORTNO+"/");
conn.start();
String resp = agent.processAddCommand("add constSend = " + ConstRateAdaptor.class.getCanonicalName() +
" testData "+ SEND_RATE + " 0");
assertTrue("adaptor_constSend".equals(resp));
Thread.sleep(END2END_TEST_SECS * 1000);
//do the shutdown directly, here, so that acks are still processed.
assertNotNull(agent.getAdaptor("adaptor_constSend"));
long bytesOutput = agent.getAdaptor("adaptor_constSend").shutdown(AdaptorShutdownPolicy.GRACEFULLY);
Thread.sleep(CLIENT_SCANPERIOD + SERVER_SCANPERIOD + ROTATEPERIOD + 3000);
String[] stat = agent.getAdaptorList().get("adaptor_constSend").split(" ");
long bytesCommitted = Long.valueOf(stat[stat.length -1]);
long bytesPerSec = bytesOutput / (1000 * END2END_TEST_SECS);
System.out.println("data rate was " + bytesPerSec + " kb /second");
//all data should be committed
System.out.println(bytesCommitted + " bytes committed");
System.out.println(bytesOutput + " bytes output");
System.out.println("difference is " + (bytesOutput - bytesCommitted));
ChukwaWriter w = collector.getWriter();
long bytesWritten = ((SeqFileWriter)w).getBytesWritten();
System.out.println("collector wrote " + bytesWritten);
assertEquals(bytesCommitted, bytesOutput);
assertEquals(bytesWritten, bytesCommitted);
//We need a little imprecision here, since the send rate is a bit bursty,
//and since some acks got lost after the adaptor was stopped.
assertTrue(bytesPerSec > 9 * SEND_RATE/ 1000 / 10);
AsyncAckSender sender = (AsyncAckSender)conn.getSender();
assertEquals(0, sender.adaptorReset.getResetCount());
agent.shutdown();
collectorServ.stop();
conn.shutdown();
Thread.sleep(5000); //for collector to shut down
TestDirTailingAdaptor.nukeDirContents(new File(outputDirectory));