Skip to content

Commit

Permalink
Merge branch '1.3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
shakuzen committed Jan 5, 2020
2 parents 23f1364 + 6490227 commit e419e78
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
* @author Johnny Lim
*/
class TomcatMetricsTest {
private static final int PROCESSING_TIME_IN_MILLIS = 10;

private SimpleMeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock());

private int port;
Expand Down Expand Up @@ -122,6 +124,14 @@ public Context getContext() {
assertThat(registry.get("tomcat.sessions.alive.max").tags(tags).timeGauge().value()).isGreaterThan(1.0);
}

private void sleep() {
try {
Thread.sleep(PROCESSING_TIME_IN_MILLIS);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
}

@Test
void mbeansAvailableAfterBinder() throws Exception {
TomcatMetrics.monitor(registry, null);
Expand All @@ -136,7 +146,7 @@ void mbeansAvailableAfterBinder() throws Exception {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
IOUtils.toString(req.getInputStream());

sleep();
resp.getOutputStream().write("yes".getBytes());
}
};
Expand All @@ -162,20 +172,23 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
return null;
});
}

@Test
void mbeansAvailableBeforeBinder() throws Exception {
HttpServlet servlet = new HttpServlet() {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
IOUtils.toString(req.getInputStream());

sleep();
resp.getOutputStream().write("yes".getBytes());
}
};

runTomcat(servlet, () -> {
TomcatMetrics.monitor(registry, null);

checkMbeansInitialState();

try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost post = new HttpPost("http://localhost:" + this.port + "/");
post.setEntity(new StringEntity("you there?"));
Expand Down Expand Up @@ -236,8 +249,8 @@ private void checkMbeansAfterRequests(long expectedSentBytes) {
assertThat(registry.get("tomcat.global.received").functionCounter().count()).isEqualTo(10.0);
assertThat(registry.get("tomcat.global.error").functionCounter().count()).isEqualTo(1.0);
assertThat(registry.get("tomcat.global.request").functionTimer().count()).isEqualTo(2.0);
assertThat(registry.get("tomcat.global.request").functionTimer().totalTime(TimeUnit.MILLISECONDS)).isGreaterThan(0.0);
assertThat(registry.get("tomcat.global.request.max").timeGauge().value(TimeUnit.MILLISECONDS)).isGreaterThan(0.0);
assertThat(registry.get("tomcat.global.request").functionTimer().totalTime(TimeUnit.MILLISECONDS)).isGreaterThanOrEqualTo(PROCESSING_TIME_IN_MILLIS);
assertThat(registry.get("tomcat.global.request.max").timeGauge().value(TimeUnit.MILLISECONDS)).isGreaterThanOrEqualTo(PROCESSING_TIME_IN_MILLIS);
assertThat(registry.get("tomcat.threads.config.max").gauge().value()).isGreaterThan(0.0);
assertThat(registry.get("tomcat.threads.busy").gauge().value()).isGreaterThanOrEqualTo(0.0);
assertThat(registry.get("tomcat.threads.current").gauge().value()).isGreaterThan(0.0);
Expand Down

0 comments on commit e419e78

Please sign in to comment.