/** * Test. * * @throws IOException e */ @Test public void testRootContexts() throws IOException { HtmlReport htmlReport; // addRequest pour que CounterRequestContext.getCpuTime() soit appelée counter.addRequest("first request", 100, 100, false, 1000); TestCounter.bindRootContexts("first request", counter, 3); sqlCounter.bindContext("sql", "sql", null, -1); htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml("message a", null); assertNotEmptyAndClear(writer); final Counter myCounter = new Counter("http", null); final Collector collector2 = new Collector("test 2", Arrays.asList(myCounter)); myCounter.bindContext("my context", "my context", null, -1); htmlReport = new HtmlReport(collector2, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.toHtml("message b", null); assertNotEmptyAndClear(writer); final HtmlCounterRequestContextReport htmlCounterRequestContextReport = new HtmlCounterRequestContextReport( collector2.getRootCurrentContexts(collector2.getCounters()), null, new ArrayList<ThreadInformations>(), false, 500, writer); htmlCounterRequestContextReport.toHtml(); assertNotEmptyAndClear(writer); }
private String buildSummary() { final String tmp; if (range.getPeriod() == Period.TOUT) { final String startDate = I18N.createDateAndTimeFormat().format(collector.getCounters().get(0).getStartDate()); tmp = getFormattedString( "Statistiques", "JavaMelody", I18N.getCurrentDateAndTime(), startDate, collector.getApplication()); } else { tmp = getFormattedString( "Statistiques_sans_depuis", "JavaMelody", I18N.getCurrentDateAndTime(), collector.getApplication()); } if (javaInformationsList.get(0).getContextDisplayName() != null) { return tmp + " (" + javaInformationsList.get(0).getContextDisplayName() + ')'; } return tmp; }
/** * Test. * * @throws Exception e */ @Test public void testWriteRequests() throws Exception { // NOPMD final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.writeRequestAndGraphDetail("httpHitsRate"); assertNotEmptyAndClear(writer); // writeRequestAndGraphDetail avec drill-down collector.collectWithoutErrors(javaInformationsList); // si sqlCounter reste à displayed=false, // il ne sera pas utilisé dans writeRequestAndGraphDetail sqlCounter.setDisplayed(true); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1); servicesCounter.clear(); servicesCounter.bindContext("myservices.service1", "service1", null, -1); sqlCounter.bindContext("sql1", "complete sql1", null, -1); sqlCounter.addRequest("sql1", 5, -1, false, -1); servicesCounter.addRequest("myservices.service1", 10, 10, false, -1); servicesCounter.bindContext("myservices.service2", "service2", null, -1); servicesCounter.addRequest("myservices.service2", 10, 10, false, -1); servicesCounter.addRequest("otherservices.service3", 10, 10, false, -1); servicesCounter.addRequest("otherservices", 10, 10, false, -1); jspCounter.addRequest("jsp1", 10, 10, false, -1); counter.addRequest(requestName, 0, 0, false, 1000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport toutHtmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); for (final Counter collectorCounter : collector.getCounters()) { for (final CounterRequest request : collectorCounter.getRequests()) { toutHtmlReport.writeRequestAndGraphDetail(request.getId()); assertNotEmptyAndClear(writer); toutHtmlReport.writeRequestUsages(request.getId()); assertNotEmptyAndClear(writer); } } sqlCounter.setDisplayed(false); // writeCounterSummaryPerClass toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), null); String requestId = new CounterRequest("myservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); requestId = new CounterRequest("otherservices", servicesCounter.getName()).getId(); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), requestId); toutHtmlReport.writeCounterSummaryPerClass(servicesCounter.getName(), "unknown"); }