Search in sources :

Example 1 with ExecutionStatistics

use of org.glassfish.jersey.server.monitoring.ExecutionStatistics in project jersey by jersey.

the class MonitoringStatisticsTest method testUrisWithProgrammaticResourcesAndExecution.

@Test
public void testUrisWithProgrammaticResourcesAndExecution() {
    final MonitoringStatisticsImpl.Builder statBuilder = getProgStats();
    final Resource.Builder resourceBuilder = Resource.builder();
    resourceBuilder.addMethod("GET").handledBy(MyInflector.class);
    resourceBuilder.addMethod("POST").handledBy(MyInflector.class);
    final Resource res = resourceBuilder.build();
    ResourceMethod getMethod;
    ResourceMethod postMethod;
    if (res.getResourceMethods().get(0).getHttpMethod().equals("GET")) {
        getMethod = res.getResourceMethods().get(0);
        postMethod = res.getResourceMethods().get(1);
    } else {
        getMethod = res.getResourceMethods().get(1);
        postMethod = res.getResourceMethods().get(0);
    }
    statBuilder.addExecution("/new/elefant", getMethod, 10, 5, 8, 8);
    statBuilder.addExecution("/new/elefant", getMethod, 20, 12, 18, 10);
    statBuilder.addExecution("/new/elefant", postMethod, 30, 2, 28, 4);
    final MonitoringStatisticsImpl stat = statBuilder.build();
    final Iterator<Map.Entry<String, ResourceStatistics>> it = stat.getUriStatistics().entrySet().iterator();
    check(it, "/hello", 2);
    check(it, "/hello/world", 1);
    check(it, "/new/elefant", 2);
    check(it, "/prog", 1);
    check(it, "/test-resource", 1);
    check(it, "/test-resource/child", 3);
    check(it, "/test-resource/prog-child", 1);
    final Map<ResourceMethod, ResourceMethodStatistics> resourceMethodStatistics = stat.getUriStatistics().get("/new/elefant").getResourceMethodStatistics();
    for (ResourceMethodStatistics methodStatistics : resourceMethodStatistics.values()) {
        final ResourceMethod method = methodStatistics.getResourceMethod();
        final ExecutionStatistics st = methodStatistics.getMethodStatistics();
        if (method.getHttpMethod().equals("GET")) {
            Assert.assertEquals(20, st.getLastStartTime().getTime());
        } else if (method.getHttpMethod().equals("POST")) {
            Assert.assertEquals(30, st.getLastStartTime().getTime());
        } else {
            Assert.fail();
        }
    }
}
Also used : ExecutionStatistics(org.glassfish.jersey.server.monitoring.ExecutionStatistics) ResourceMethodStatistics(org.glassfish.jersey.server.monitoring.ResourceMethodStatistics) Resource(org.glassfish.jersey.server.model.Resource) ResourceMethod(org.glassfish.jersey.server.model.ResourceMethod) Test(org.junit.Test)

Aggregations

Resource (org.glassfish.jersey.server.model.Resource)1 ResourceMethod (org.glassfish.jersey.server.model.ResourceMethod)1 ExecutionStatistics (org.glassfish.jersey.server.monitoring.ExecutionStatistics)1 ResourceMethodStatistics (org.glassfish.jersey.server.monitoring.ResourceMethodStatistics)1 Test (org.junit.Test)1