EventLog implements EventLogInterface { public void writeHtmlState(StringBuilder sb, Node node) { TimeZone tz = TimeZone.getTimeZone("UTC"); LinkedList<Event> events = new LinkedList<>(); long currentTime = timer.getCurrentTimeInMillis(); long recentNodeEvents = 0; if (node == null) { events = eventLog; sb.append("<h2 id=\"eventlog\">Event log</h2>\n") .append("<p>A total number of " + eventsSeen + " has been seen since ").append(RealTimer.printDate(startTime, tz)).append(".</p>\n"); } else { if (nodeLog.containsKey(node)) { events.addAll(nodeLog.get(node)); } recentNodeEvents = getNodeEventsSince(node, currentTime - recentTimePeriod); sb.append("<h2>Node event log for " + node + "</h2>\n") .append("<p>A total number of " + events.size() + " events has been seen since ") .append(RealTimer.printDate(startTime, tz)).append(".</p>\n") .append("<p>Recently, " + recentNodeEvents + " events has been seen since ") .append(RealTimer.printDate(currentTime - recentTimePeriod, tz)).append(".</p>\n"); } sb.append("<table border=\"1\" cellspacing=\"0\">\n") .append("<tr><td>Date (").append(tz.getDisplayName(false, TimeZone.SHORT)) .append(")</td><td>Type</td><td>Node</td><td>Bucket space</td><td>Event</td></tr>\n"); int nr = 0; Iterator<Event> eventIterator = (events == null ? null : events.descendingIterator()); if (eventIterator != null) while (eventIterator.hasNext()) { Event e = eventIterator.next(); String colStart = "<font color=\"" + (++nr > recentNodeEvents ? "grey" : "black") + "\">"; String colEnd = "</font>"; sb.append("<tr>\n"); addNobrTableCell(sb, colStart, colEnd, RealTimer.printDate(e.getTimeMs(), tz)); addNobrTableCell(sb, colStart, colEnd, e.getCategory()); if (e instanceof NodeEvent) { NodeEvent nodeEvent = (NodeEvent)e; addNobrTableCell(sb, colStart, colEnd, nodeEvent.getNode().toString()); addNobrTableCell(sb, colStart, colEnd, nodeEvent.getBucketSpace().orElse(" - ")); } else { addNobrTableCell(sb, colStart, colEnd, " - "); addNobrTableCell(sb, colStart, colEnd, " - "); } addTableCell(sb, colStart, colEnd, e.getDescription()); sb.append("</tr>\n"); } sb.append("</table>\n"); } EventLog(Timer timer, MetricUpdater metricUpdater); void setMaxSize(int size, int nodesize); long getRecentTimePeriod(); void add(Event e); void add(Event e, boolean logInfo); void addNodeOnlyEvent(NodeEvent e, java.util.logging.Level level); int getNodeEventsSince(Node n, long time); List<NodeEvent> getNodeEvents(Node n); void writeHtmlState(StringBuilder sb, Node node); static Logger log; }
@Test public void testNoEventsDoNotThrowException() { initialize(metricUpdater); StringBuilder builder = new StringBuilder(); Node nonExistantNode = new Node(NodeType.DISTRIBUTOR, 0); eventLog.writeHtmlState(builder, nonExistantNode); assertNotEquals("", builder.toString()); }