HtmlReport extends HtmlAbstractReport { @Override void toHtml() throws IOException { writeHtmlHeader(); htmlCoreReport.toHtml(); writeHtmlFooter(); } HtmlReport(Collector collector, CollectorServer collectorServer,
			List<JavaInformations> javaInformationsList, Range range, Writer writer);  HtmlReport(Collector collector, CollectorServer collectorServer,
			List<JavaInformations> javaInformationsList, Period period, Writer writer); void toHtml(String message, String anchorNameForRedirect); void writeLastShutdown(); static void writeAddAndRemoveApplicationLinks(String currentApplication,
			Collection<String> applications, Writer writer); void writeAllCurrentRequestsAsPart(); void writeAllThreadsAsPart(); void writeThreadsDump(); void writeCounterSummaryPerClass(String counterName, String requestId); void writeSource(String className); void writeDependencies(); void writeSpringContext(); void writeHtmlHeader(); void writeHtmlFooter(); void writeMessageIfNotNull(String message, String partToRedirectTo); void writeRequestAndGraphDetail(String graphName); void writeRequestUsages(String graphName); void writeSessions(List<SessionInformations> sessionsInformations, String message,
			String sessionsPart); void writeSessionDetail(String sessionId, SessionInformations sessionInformations); void writeHotspots(List<SampledMethod> hotspots); void writeHeapHistogram(HeapHistogram heapHistogram, String message,
			String heapHistoPart); void writeProcesses(List<ProcessInformations> processInformationsList); void writeProcesses(Map<String, List<ProcessInformations>> processesByTitle); void writeDatabase(DatabaseInformations databaseInformations); void writeConnections(List<ConnectionInformations> connectionInformationsList,
			boolean withoutHeaders); void writeJndi(List<JndiBinding> jndiBindings, String path); void writeMBeans(List<MBeanNode> mbeans); void writeMBeans(Map<String, List<MBeanNode>> mbeansByTitle); void writeCacheWithKeys(String cacheId, CacheInformations cacheInformations,
			String message, String cacheKeyPart, boolean withoutHeaders); void writeJCacheWithKeys(String cacheId, JCacheInformations jcacheInformations,
			String message, String cacheKeyPart, boolean withoutHeaders); void writeCrashes(); void writeHashPassword(String algorithm, String password);  }
@Test public void testSimpleToHtml() throws IOException { final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml(); assertNotEmptyAndClear(writer); }
@Test public void testToHtmlWithSession() throws IOException { final HttpSession session = createNiceMock(HttpSession.class); replay(session); try { SessionListener.bindSession(session); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml(); assertNotEmptyAndClear(writer); } finally { SessionListener.unbindSession(); } verify(session); }
@Test public void testToHtmlWithHsErrPid() throws IOException { final File hsErrPidFile = new File("./hs_err_pid12345.log"); try { hsErrPidFile.createNewFile(); setUp(); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml(); assertNotEmptyAndClear(writer); } finally { hsErrPidFile.delete(); } }
@Test public void testEmptyCounter() throws IOException { final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); counter.clear(); errorCounter.clear(); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); }
@Test public void testDoubleJavaInformations() throws IOException { final List<JavaInformations> myJavaInformationsList = Arrays .asList(new JavaInformations(null, true), new JavaInformations(null, true)); final HtmlReport htmlReport = new HtmlReport(collector, null, myJavaInformationsList, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); }
@Test public void testCounter() throws IOException { setProperty(Parameter.WARNING_THRESHOLD_MILLIS, "500"); setProperty(Parameter.SEVERE_THRESHOLD_MILLIS, "1500"); setProperty(Parameter.ANALYTICS_ID, "123456789"); counter.addRequest("test1", 0, 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, 500, false, 1000); counter.addRequest("test3", 100000, 50000, 50000, true, 10000); servicesCounter.addRequest("testServices", 100, 50, 50, false, -1); final StringBuilder sb = new StringBuilder(); for (int i = 0; i < 5010; i++) { sb.append(i % 10); } final String longRequestName = sb.toString(); counter.addRequest(longRequestName, 0, 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); collector = new Collector("test", Arrays.asList(counter)); final HtmlReport htmlReport2 = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport2.toHtml(null, null); }
@Test public void testPeriodeNonTout() throws IOException { collector.collectWithoutErrors(javaInformationsList); final String requestName = "test 1"; counter.bindContext(requestName, "complete test 1", null, -1, -1); sqlCounter.addRequest("sql1", 10, 10, 10, false, -1); counter.addRequest(requestName, 0, 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, 500, false, 1000); counter.addRequest("test3", 10000, 500, 500, true, 10000); collector.collectWithoutErrors(javaInformationsList); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.SEMAINE, writer); htmlReport.toHtml("message 6", null); assertNotEmptyAndClear(writer); final HtmlReport htmlReportRange = new HtmlReport(collector, null, javaInformationsList, Range.createCustomRange(new Date(), new Date()), writer); htmlReportRange.toHtml("message 6", null); assertNotEmptyAndClear(writer); }
@Test public void testRootContexts() throws IOException { HtmlReport htmlReport; counter.addRequest("first request", 100, 100, 100, false, 1000); TestCounter.bindRootContexts("first request", counter, 3); sqlCounter.bindContext("sql", "sql", null, -1, -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, -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); }
@Test public void testCache() throws IOException { final String cacheName = "test 1"; final CacheManager cacheManager = CacheManager.getInstance(); cacheManager.addCache(cacheName); cacheManager.addCache(new Cache("", 1000, true, false, 10000, 10000, false, 10000)); final String cacheName2 = "test 2"; try { final Cache cache = cacheManager.getCache(cacheName); cache.put(new Element(1, Math.random())); cache.get(1); cache.get(0); cacheManager.addCache(cacheName2); final Cache cache2 = cacheManager.getCache(cacheName2); cache2.getCacheConfiguration().setOverflowToDisk(false); cache2.getCacheConfiguration().setEternal(true); cache2.getCacheConfiguration().setMaxElementsInMemory(0); final List<JavaInformations> javaInformationsList2 = Collections .singletonList(new JavaInformations(null, true)); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList2, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, "false"); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); } finally { setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, null); cacheManager.removeCache(cacheName); cacheManager.removeCache(cacheName2); } }
@Test public void testJCache() throws IOException { final String cacheName = "test 1"; final javax.cache.CacheManager jcacheManager = Caching.getCachingProvider() .getCacheManager(); final MutableConfiguration<Object, Object> conf = new MutableConfiguration<Object, Object>(); conf.setManagementEnabled(true); conf.setStatisticsEnabled(true); jcacheManager.createCache(cacheName, conf); jcacheManager.createCache("", conf); final String cacheName2 = "test 2"; try { final javax.cache.Cache<Object, Object> cache = jcacheManager.getCache(cacheName); cache.put(1, Math.random()); cache.get(1); cache.get(0); final MutableConfiguration<Object, Object> conf2 = new MutableConfiguration<Object, Object>(); conf2.setManagementEnabled(false); conf2.setStatisticsEnabled(false); jcacheManager.createCache(cacheName2, conf2); final List<JavaInformations> javaInformationsList2 = Collections .singletonList(new JavaInformations(null, true)); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList2, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, "false"); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); } finally { setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, null); jcacheManager.destroyCache(cacheName); jcacheManager.destroyCache(cacheName2); } }
@Test public void testJob() throws IOException, SchedulerException { initJobGlobalListener(); getJobCounter().clear(); final Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler(); try { scheduler.start(); final Random random = new Random(); final JobDetail job2 = new JobDetail("job" + random.nextInt(), null, JobTestImpl.class); final SimpleTrigger trigger2 = new SimpleTrigger("trigger" + random.nextInt(), null, new Date(System.currentTimeMillis() + 60000)); trigger2.setRepeatInterval(2 * 24L * 60 * 60 * 1000); scheduler.scheduleJob(job2, trigger2); scheduler.pauseJob(job2.getName(), job2.getGroup()); try { final JobDetail job3 = new JobDetail("job" + random.nextInt(), null, JobTestImpl.class); final Trigger trigger3 = new CronTrigger("crontrigger" + random.nextInt(), null, "0 0 0 * * ? 2030"); scheduler.scheduleJob(job3, trigger3); final NthIncludedDayTrigger trigger4 = new NthIncludedDayTrigger( "nth trigger" + random.nextInt(), null); trigger4.setN(1); trigger4.setIntervalType(NthIncludedDayTrigger.INTERVAL_TYPE_YEARLY); trigger4.setJobName(job3.getName()); scheduler.scheduleJob(trigger4); } catch (final ParseException e) { throw new IllegalStateException(e); } final List<JavaInformations> javaInformationsList2 = Collections .singletonList(new JavaInformations(null, true)); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList2, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); final Map<JobDetail, SimpleTrigger> triggersByJob = new LinkedHashMap<JobDetail, SimpleTrigger>(); for (int i = 0; i < 10; i++) { final JobDetail job = new JobDetail("job" + random.nextInt(), null, JobTestImpl.class); job.setDescription("description"); final SimpleTrigger trigger = new SimpleTrigger("trigger" + random.nextInt(), null, new Date()); scheduler.scheduleJob(job, trigger); triggersByJob.put(job, trigger); } try { Thread.sleep(3000); } catch (final InterruptedException e) { throw new IllegalStateException(e); } for (final Map.Entry<JobDetail, SimpleTrigger> entry : triggersByJob.entrySet()) { entry.getValue().setRepeatInterval(60000); scheduler.scheduleJob(entry.getKey(), entry.getValue()); } setProperty(Parameter.SYSTEM_ACTIONS_ENABLED, Boolean.FALSE.toString()); final List<JavaInformations> javaInformationsList3 = Collections .singletonList(new JavaInformations(null, true)); final HtmlReport htmlReport3 = new HtmlReport(collector, null, javaInformationsList3, Period.TOUT, writer); htmlReport3.toHtml(null, null); assertNotEmptyAndClear(writer); } finally { scheduler.shutdown(); getJobCounter().clear(); destroyJobGlobalListener(); } }
@Test public void testWithCollectorServer() throws IOException { final CollectorServer collectorServer = new CollectorServer(); try { final HtmlReport htmlReport = new HtmlReport(collector, collectorServer, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); Utils.setProperty(Parameters.PARAMETER_SYSTEM_PREFIX + "mockLabradorRetriever", "true"); collectorServer.collectWithoutErrors(); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); } finally { collectorServer.stop(); } }
@Test public void testWithNoDatabase() throws IOException { final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml(null, null); assertNotEmptyAndClear(writer); }
@Test public void testHtmlCounterRequestContext() throws IOException { assertNotNull("HtmlCounterRequestContextReport", new HtmlCounterRequestContextReport(Collections.<CounterRequestContext> emptyList(), null, Collections.<ThreadInformations> emptyList(), true, 500, writer)); final HtmlCounterRequestContextReport report = new HtmlCounterRequestContextReport( Collections.<CounterRequestContext> emptyList(), Collections.<String, HtmlCounterReport> emptyMap(), Collections.<ThreadInformations> emptyList(), true, 500, writer); report.toHtml(); assertNotEmptyAndClear(writer); final List<CounterRequestContext> counterRequestContexts = Collections .singletonList(new CounterRequestContext(sqlCounter, null, "Test", "Test", null, null, -1, -1, "sessionId")); final HtmlCounterRequestContextReport report2 = new HtmlCounterRequestContextReport( counterRequestContexts, null, Collections.<ThreadInformations> emptyList(), true, 0, writer); report2.toHtml(); assertNotEmptyAndClear(writer); report2.writeTitleAndDetails(); }
@Test public void testToHtmlEn() throws IOException { I18N.bindLocale(Locale.US); Locale.setDefault(Locale.US); try { assertEquals("locale en", Locale.US, I18N.getCurrentLocale()); counter.addRequest("test1", 0, 0, 0, false, 1000); counter.addRequest("test2", 1000, 500, 500, false, 1000); counter.addRequest("test3", 10000, 5000, 5000, true, 10000); final HtmlReport htmlReport = new HtmlReport(collector, null, javaInformationsList, Period.TOUT, writer); htmlReport.toHtml("message", null); assertNotEmptyAndClear(writer); } finally { I18N.unbindLocale(); Locale.setDefault(Locale.FRENCH); } }