Search in sources :

Example 1 with LibraryApi

use of org.apache.cxf.systest.jaxrs.resources.LibraryApi in project cxf by apache.

the class SpringJaxrsTest method testJaxrsProxyFailedMetric.

@Test
public void testJaxrsProxyFailedMetric() {
    final LibraryApi api = createApi(port);
    try (Response r = api.getBook("100")) {
        assertThat(r.getStatus()).isEqualTo(404);
    }
    await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
    RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
    Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(serverTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBook"), entry("uri", "/api/library/{id}"), entry("outcome", "CLIENT_ERROR"), entry("status", "404"));
    RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
    Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBook"), entry("uri", "http://localhost:" + port + "/api/library/100"), entry("outcome", "CLIENT_ERROR"), entry("status", "404"));
}
Also used : Response(javax.ws.rs.core.Response) LibraryApi(org.apache.cxf.systest.jaxrs.resources.LibraryApi) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with LibraryApi

use of org.apache.cxf.systest.jaxrs.resources.LibraryApi in project cxf by apache.

the class SpringJaxrsApplicationTest method testJaxrsProxySuccessMetric.

@Test
public void testJaxrsProxySuccessMetric() {
    final LibraryApi api = createApi(port);
    try (Response r = api.getBooks(1)) {
        assertThat(r.getStatus()).isEqualTo(200);
    }
    await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
    RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
    Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(serverTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBooks"), entry("uri", "/api/app/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
    RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
    Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBooks"), entry("uri", "http://localhost:" + port + "/api/app/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
}
Also used : Response(javax.ws.rs.core.Response) LibraryApi(org.apache.cxf.systest.jaxrs.resources.LibraryApi) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with LibraryApi

use of org.apache.cxf.systest.jaxrs.resources.LibraryApi in project cxf by apache.

the class SpringJaxrsApplicationTest method testJaxrsProxyExceptionMetric.

@Test
public void testJaxrsProxyExceptionMetric() {
    final LibraryApi api = createApi(port);
    assertThatThrownBy(() -> api.deleteBooks()).isInstanceOf(InternalServerErrorException.class).hasMessageContaining("Internal Server Error");
    await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
    RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
    Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(serverTags).containsOnly(entry("exception", "UnsupportedOperationException"), entry("method", "DELETE"), entry("operation", "deleteBooks"), entry("uri", "/api/app/library"), entry("outcome", "SERVER_ERROR"), entry("status", "500"));
    RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
    Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "DELETE"), entry("operation", "deleteBooks"), entry("uri", "http://localhost:" + port + "/api/app/library"), entry("outcome", "SERVER_ERROR"), entry("status", "500"));
}
Also used : LibraryApi(org.apache.cxf.systest.jaxrs.resources.LibraryApi) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with LibraryApi

use of org.apache.cxf.systest.jaxrs.resources.LibraryApi in project cxf by apache.

the class SpringJaxrsTest method testJaxrsProxySuccessMetric.

@Test
public void testJaxrsProxySuccessMetric() {
    final LibraryApi api = createApi(port);
    try (Response r = api.getBooks(1)) {
        assertThat(r.getStatus()).isEqualTo(200);
    }
    await().atMost(Duration.ofSeconds(1)).ignoreException(MeterNotFoundException.class).until(() -> registry.get("cxf.server.requests").timers(), not(empty()));
    RequiredSearch serverRequestMetrics = registry.get("cxf.server.requests");
    Map<Object, Object> serverTags = serverRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(serverTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBooks"), entry("uri", "/api/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
    RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
    Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "GET"), entry("operation", "getBooks"), entry("uri", "http://localhost:" + port + "/api/library"), entry("outcome", "SUCCESS"), entry("status", "200"));
}
Also used : Response(javax.ws.rs.core.Response) LibraryApi(org.apache.cxf.systest.jaxrs.resources.LibraryApi) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with LibraryApi

use of org.apache.cxf.systest.jaxrs.resources.LibraryApi in project cxf by apache.

the class SpringJaxrsTest method testJaxrsProxyClientExceptionMetric.

@Test
public void testJaxrsProxyClientExceptionMetric() {
    final int fakePort = SocketUtils.findAvailableTcpPort();
    final LibraryApi api = createApi(fakePort);
    assertThatThrownBy(() -> api.deleteBooks()).isInstanceOf(ProcessingException.class).hasMessageContaining("Connection refused");
    // no server meters
    assertThat(registry.getMeters()).noneMatch(m -> "cxf.server.requests".equals(m.getId().getName()));
    RequiredSearch clientRequestMetrics = registry.get("cxf.client.requests");
    Map<Object, Object> clientTags = clientRequestMetrics.timer().getId().getTags().stream().collect(toMap(Tag::getKey, Tag::getValue));
    assertThat(clientTags).containsOnly(entry("exception", "None"), entry("method", "DELETE"), entry("operation", "deleteBooks"), entry("uri", "http://localhost:" + fakePort + "/api/library"), entry("outcome", "UNKNOWN"), entry("status", "UNKNOWN"));
}
Also used : LibraryApi(org.apache.cxf.systest.jaxrs.resources.LibraryApi) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

RequiredSearch (io.micrometer.core.instrument.search.RequiredSearch)8 LibraryApi (org.apache.cxf.systest.jaxrs.resources.LibraryApi)8 Test (org.junit.jupiter.api.Test)8 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)8 MeterNotFoundException (io.micrometer.core.instrument.search.MeterNotFoundException)6 Response (javax.ws.rs.core.Response)4 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 ProcessingException (javax.ws.rs.ProcessingException)2