@Test public void testPrintServiceStats () throws IOException { Collector c = new Collector (); c.readLogMessagesFromFile("TestLogFile.log"); String expectedOutput = String.format(Collector.SERVICE_DATA_FORMAT, "24/216.216.217.254/SNMP", "7.144s", 1, "7.144s", 100.0, "0s", 0.0, "0s", "7.144s", "0s", "0s" ); StringWriter out = new StringWriter(); c.printServiceStats("24/216.216.217.254/SNMP", new PrintWriter(out, true)); String actualOutput = out.toString(); assertEquals(expectedOutput,actualOutput); }
private void printServiceStats(ServiceCollector serviceCollector, PrintWriter out) { out.printf(SERVICE_DATA_FORMAT, serviceCollector.getServiceID(), Collector.formatDuration(serviceCollector.getAverageCollectionTime()), serviceCollector.getCollectionCount(), Collector.formatDuration(serviceCollector.getAverageSuccessfulCollectionTime()), serviceCollector.getSuccessPercentage(), Collector.formatDuration(serviceCollector.getAverageErrorCollectionTime()), serviceCollector.getErrorPercentage(), Collector.formatDuration(serviceCollector.getAverageTimeBetweenCollections()), Collector.formatDuration(serviceCollector.getTotalCollectionTime()), Collector.formatDuration(serviceCollector.getAveragePersistTime()), Collector.formatDuration(serviceCollector.getTotalPersistTime())); }
Collector { private void printServiceStats(ServiceCollector serviceCollector, PrintWriter out) { out.printf(SERVICE_DATA_FORMAT, serviceCollector.getServiceID(), Collector.formatDuration(serviceCollector.getAverageCollectionTime()), serviceCollector.getCollectionCount(), Collector.formatDuration(serviceCollector.getAverageSuccessfulCollectionTime()), serviceCollector.getSuccessPercentage(), Collector.formatDuration(serviceCollector.getAverageErrorCollectionTime()), serviceCollector.getErrorPercentage(), Collector.formatDuration(serviceCollector.getAverageTimeBetweenCollections()), Collector.formatDuration(serviceCollector.getTotalCollectionTime()), Collector.formatDuration(serviceCollector.getAveragePersistTime()), Collector.formatDuration(serviceCollector.getTotalPersistTime())); } }
Collector { private void printServiceStats(ServiceCollector serviceCollector, PrintWriter out) { out.printf(SERVICE_DATA_FORMAT, serviceCollector.getServiceID(), Collector.formatDuration(serviceCollector.getAverageCollectionTime()), serviceCollector.getCollectionCount(), Collector.formatDuration(serviceCollector.getAverageSuccessfulCollectionTime()), serviceCollector.getSuccessPercentage(), Collector.formatDuration(serviceCollector.getAverageErrorCollectionTime()), serviceCollector.getErrorPercentage(), Collector.formatDuration(serviceCollector.getAverageTimeBetweenCollections()), Collector.formatDuration(serviceCollector.getTotalCollectionTime()), Collector.formatDuration(serviceCollector.getAveragePersistTime()), Collector.formatDuration(serviceCollector.getTotalPersistTime())); }  }
Collector { private void printServiceStats(ServiceCollector serviceCollector, PrintWriter out) { out.printf(SERVICE_DATA_FORMAT, serviceCollector.getServiceID(), Collector.formatDuration(serviceCollector.getAverageCollectionTime()), serviceCollector.getCollectionCount(), Collector.formatDuration(serviceCollector.getAverageSuccessfulCollectionTime()), serviceCollector.getSuccessPercentage(), Collector.formatDuration(serviceCollector.getAverageErrorCollectionTime()), serviceCollector.getErrorPercentage(), Collector.formatDuration(serviceCollector.getAverageTimeBetweenCollections()), Collector.formatDuration(serviceCollector.getTotalCollectionTime()), Collector.formatDuration(serviceCollector.getAveragePersistTime()), Collector.formatDuration(serviceCollector.getTotalPersistTime())); }  void setSearchString(String searchString); void setSortColumn(SortColumn sortFlag); void setSortOrder(SortOrder sortOrder); Collector.SortColumn getSortColumn(); String getSearchString(); static void setDurationsMs(boolean durationsMs); static boolean getDurationsMs(); void addLog(String logMessage); Date getStartTime(); LogMessage getFirstValidLogMessage(); LogMessage getLastValidLogMessage(); Date getEndTime(); long getDuration(); String getFormattedDuration(); int getServiceCount(); Map<String, ServiceCollector> getm_ServiceCollectors(); int compareLongs(long l1, long l2); Set<String> getServices(); List<ServiceCollector> getServiceCollectors(); Comparator<ServiceCollector> getColumnComparator(); int getThreadCount(); int getCollectionsPerService(String serviceID); long getAverageCollectionTimePerService(String serviceID); long getTotalCollectionTimePerService(String serviceID); void readLogMessagesFromFile(String fileName); void printGlobalStats(PrintWriter out); static String formatDuration(long millis); void printServiceHeader(PrintWriter out); void printReport(PrintWriter out); void printServiceStats(String serviceID, PrintWriter out); }
Collector { private void printServiceStats(ServiceCollector serviceCollector, PrintWriter out) { out.printf(SERVICE_DATA_FORMAT, serviceCollector.getServiceID(), Collector.formatDuration(serviceCollector.getAverageCollectionTime()), serviceCollector.getCollectionCount(), Collector.formatDuration(serviceCollector.getAverageSuccessfulCollectionTime()), serviceCollector.getSuccessPercentage(), Collector.formatDuration(serviceCollector.getAverageErrorCollectionTime()), serviceCollector.getErrorPercentage(), Collector.formatDuration(serviceCollector.getAverageTimeBetweenCollections()), Collector.formatDuration(serviceCollector.getTotalCollectionTime()), Collector.formatDuration(serviceCollector.getAveragePersistTime()), Collector.formatDuration(serviceCollector.getTotalPersistTime())); }  void setSearchString(String searchString); void setSortColumn(SortColumn sortFlag); void setSortOrder(SortOrder sortOrder); Collector.SortColumn getSortColumn(); String getSearchString(); static void setDurationsMs(boolean durationsMs); static boolean getDurationsMs(); void addLog(String logMessage); Date getStartTime(); LogMessage getFirstValidLogMessage(); LogMessage getLastValidLogMessage(); Date getEndTime(); long getDuration(); String getFormattedDuration(); int getServiceCount(); Map<String, ServiceCollector> getm_ServiceCollectors(); int compareLongs(long l1, long l2); Set<String> getServices(); List<ServiceCollector> getServiceCollectors(); Comparator<ServiceCollector> getColumnComparator(); int getThreadCount(); int getCollectionsPerService(String serviceID); long getAverageCollectionTimePerService(String serviceID); long getTotalCollectionTimePerService(String serviceID); void readLogMessagesFromFile(String fileName); void printGlobalStats(PrintWriter out); static String formatDuration(long millis); void printServiceHeader(PrintWriter out); void printReport(PrintWriter out); void printServiceStats(String serviceID, PrintWriter out); static final String SERVICE_TITLE_FORMAT; static final String SERVICE_DATA_FORMAT; }