EventAnalyzer extends AbstractMessageAnalyzer<EventReport> implements LogEnabled { @Override public void process(MessageTree tree) { String domain = tree.getDomain(); String ip = tree.getIpAddress(); EventReport report = m_reportManager.getHourlyReport(getStartTime(), domain, true); List<Event> events = tree.findOrCreateEvents(); for (Event event : events) { String data = String.valueOf(event.getData()); int total = 1; int fail = 0; boolean batchData = data.length() > 0 && data.charAt(0) == CatConstants.BATCH_FLAG; if (batchData) { String[] tab = data.substring(1).split(CatConstants.SPLIT); total = Integer.parseInt(tab[0]); fail = Integer.parseInt(tab[1]); } else { if (!event.isSuccess()) { fail = 1; } } processEvent(report, tree, event, ip, total, fail, batchData); } if (System.currentTimeMillis() > m_nextClearTime) { m_nextClearTime = m_nextClearTime + TimeHelper.ONE_MINUTE; Threads.forGroup("cat").start(new Runnable() { @Override public void run() { cleanUpReports(); } }); } }  @Override synchronized void doCheckpoint(boolean atEnd); @Override EventReport getReport(String domain); @Override void enableLogging(Logger logger); @Override ReportManager<EventReport> getReportManager(); void setReportManager(ReportManager<EventReport> reportManager); @Override void initialize(long startTime, long duration, long extraTime); @Override boolean isEligable(MessageTree tree); @Override void process(MessageTree tree); static final String ID; }
@Test public void testProcess() throws Exception { for (int i = 1; i <= 1000; i++) { MessageTree tree = ((DefaultMessageTree) generateMessageTree(i)).copyForTest(); m_analyzer.process(tree); } EventReport report = m_analyzer.getReport(m_domain); String expected = Files.forIO().readFrom(getClass().getResourceAsStream("event_analyzer.xml"), "utf-8"); EventReport expected4report = com.dianping.cat.consumer.event.model.transform.DefaultSaxParser.parse(expected); Assert.assertTrue(TestHelper.isEquals(expected4report,report)); }