@Test public void shouldIncrementAllByteCounters() { assertThat(Statistics.getBytesReceived(), is(equalTo(0l))); assertThat(Statistics.getBytesSent(), is(equalTo(0l))); Statistics.addBytesReceived(3); assertThat(Statistics.getBytesReceived(), is(equalTo(3l))); Statistics.addBytesReceived(5); assertThat(Statistics.getBytesReceived(), is(equalTo(8l))); Statistics.addBytesSent(2); assertThat(Statistics.getBytesSent(), is(equalTo(2l))); Statistics.addBytesSent(11); assertThat(Statistics.getBytesSent(), is(equalTo(13l))); Statistics.reset(); assertThat(Statistics.getBytesReceived(), is(equalTo(0l))); assertThat(Statistics.getBytesSent(), is(equalTo(0l))); }
private HTMLDocument renderDocument() { HTMLDocument doc = new HTMLDocument("Statistics"); doc.setOwnerClass(getClass().getSimpleName()); doc.writeln("<div class=\"page-header\"><h1>Server statistics</h1></div>"); doc.writeln("<p class=\"bg-info\">Please refresh the page to update the statistics."); doc.writeln("<table class=\"table\">"); doc.writeln("<tr>"); doc.writeln(" <td>Data received</td><td>" + FileUtilities.fileSizeUnits(ro.polak.http.Statistics.getBytesReceived()) + "</td>"); doc.writeln("</tr>"); doc.writeln("<tr>"); doc.writeln(" <td>Data sent</td><td>" + FileUtilities.fileSizeUnits(ro.polak.http.Statistics.getBytesSent()) + "</td>"); doc.writeln("</tr>"); doc.writeln("<tr>"); doc.writeln(" <td>Requests handled</td><td>" + ro.polak.http.Statistics.getRequestsHandled() + "</td>"); doc.writeln("</tr>"); doc.writeln("<tr>"); doc.writeln(" <td>404 errors</td><td>" + ro.polak.http.Statistics.getError404s() + "</td>"); doc.writeln("</tr>"); doc.writeln("<tr>"); doc.writeln(" <td>500 errors</td><td>" + ro.polak.http.Statistics.getError500s() + "</td>"); doc.writeln("</tr>"); doc.writeln("</table"); return doc; } }