/** * Test. * * @throws IOException e */ @Test public void testPeriodeNonTout() throws IOException { // counter avec période non TOUT et des requêtes collector.collectWithoutErrors(javaInformationsList); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1); sqlCounter.addRequest("sql1", 10, 10, false, -1); counter.addRequest(requestName, 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, false, 1000); counter.addRequest("test3", 10000, 500, true, 10000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.toHtml("message 6", null); assertNotEmptyAndClear(writer); // période personnalisée final HtmlReport htmlReportRange = new HtmlReport( collector, null, javaInformationsList, Range.createCustomRange(new Date(), new Date()), writer); htmlReportRange.toHtml("message 6", null); assertNotEmptyAndClear(writer); }
/** * 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"); }
/** * Test. * * @throws IOException e */ @Test public void testCounter() throws IOException { // counter avec 3 requêtes setProperty(Parameter.WARNING_THRESHOLD_MILLIS, "500"); setProperty(Parameter.SEVERE_THRESHOLD_MILLIS, "1500"); setProperty(Parameter.ANALYTICS_ID, "123456789"); counter.addRequest("test1", 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, false, 1000); counter.addRequest("test3", 100000, 50000, true, 10000); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5010; i++) { // HtmlCounterReport.MAX_REQUEST_LENGTH = 5000 sb.append(i % 10); } final String longRequestName = sb.toString(); counter.addRequest(longRequestName, 0, 0, false, 5000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml("message 2", null); assertNotEmptyAndClear(writer); setProperty(Parameter.NO_DATABASE, Boolean.TRUE.toString()); collector.collectWithoutErrors(javaInformationsList); htmlReport.toHtml("message 2", null); assertNotEmptyAndClear(writer); setProperty(Parameter.NO_DATABASE, Boolean.FALSE.toString()); setProperty(Parameter.WARNING_THRESHOLD_MILLIS, "-1"); try { htmlReport.toHtml("message 2", null); } catch (final IllegalStateException e) { assertNotNull("ok", e); } setProperty(Parameter.WARNING_THRESHOLD_MILLIS, null); // cas counterReportsByCounterName.size() == 1 collector = new Collector("test", Arrays.asList(counter)); final HtmlReport htmlReport2 = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport2.toHtml(null, null); }
/** * Test. * * @throws IOException e */ @Test public void testErrorCounter() throws IOException { // errorCounter errorCounter.addRequestForSystemError("error", -1, -1, null); errorCounter.addRequestForSystemError("error2", -1, -1, "ma stack-trace"); collector.collectWithoutErrors(javaInformationsList); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml("message 3", null); assertNotEmptyAndClear(writer); for (final CounterRequest request : errorCounter.getRequests()) { htmlReport.writeRequestAndGraphDetail(request.getId()); } htmlReport.writeRequestAndGraphDetail("n'importe quoi"); assertNotEmptyAndClear(writer); }