Search in sources :

Example 21 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.

the class SpringJaxwsTest method testJaxwsSuccessMetric.

@Test
public void testJaxwsSuccessMetric() throws MalformedURLException {
    // given in setUp
    // when
    String actual = sendSoapRequest(DUMMY_REQUEST_BODY, HELLO_SERVICE_NAME_V1);
    // then
    assertThat(actual).isEqualTo("<ns2:sayHelloResponse xmlns:ns2=\"http://service.ws.sample/\">" + "<return>Hello, Elan</return>" + "</ns2:sayHelloResponse>");
    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("faultCode", "None"), entry("method", "POST"), entry("operation", "sayHello"), entry("uri", "/Service/" + HELLO_SERVICE_NAME_V1), 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("faultCode", "None"), entry("method", "POST"), entry("operation", "Invoke"), entry("uri", "http://localhost:" + port + "/Service/" + HELLO_SERVICE_NAME_V1), entry("outcome", "SUCCESS"), entry("status", "200"));
}
Also used : 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 22 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.

the class SpringJaxrsApplicationTest 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/app/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)

Example 23 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.

the class SpringJaxrsApplicationTest method testJaxrsClientExceptionMetric.

@Test
public void testJaxrsClientExceptionMetric() {
    final int fakePort = SocketUtils.findAvailableTcpPort();
    final WebTarget target = ClientBuilder.newClient().register(new MetricsFeature(metricsProvider)).target("http://localhost:" + fakePort + "/api/library");
    assertThatThrownBy(() -> target.request().delete(String.class)).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", "UNKNOWN"), entry("uri", "http://localhost:" + fakePort + "/api/library"), entry("outcome", "UNKNOWN"), entry("status", "UNKNOWN"));
}
Also used : MetricsFeature(org.apache.cxf.metrics.MetricsFeature) WebTarget(javax.ws.rs.client.WebTarget) 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)

Example 24 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.

the class SpringJaxrsApplicationTest 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/app/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/app/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 25 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project cxf by apache.

the class SpringJaxrsApplicationTest method testJaxrsSubresourceSuccessMetric.

@Test
public void testJaxrsSubresourceSuccessMetric() {
    final WebTarget target = createWebTarget().path("catalog").path("cxf");
    try (Response r = target.request().get()) {
        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", "catalog"), entry("uri", "/api/app/library/catalog/{catalog}"), 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", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/app/library/catalog/cxf"), entry("outcome", "SUCCESS"), entry("status", "200"));
}
Also used : Response(javax.ws.rs.core.Response) MeterNotFoundException(io.micrometer.core.instrument.search.MeterNotFoundException) WebTarget(javax.ws.rs.client.WebTarget) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

RequiredSearch (io.micrometer.core.instrument.search.RequiredSearch)28 Test (org.junit.jupiter.api.Test)25 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)25 MeterNotFoundException (io.micrometer.core.instrument.search.MeterNotFoundException)18 WebTarget (javax.ws.rs.client.WebTarget)12 Response (javax.ws.rs.core.Response)9 LibraryApi (org.apache.cxf.systest.jaxrs.resources.LibraryApi)8 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)4 ProcessingException (javax.ws.rs.ProcessingException)4 Counter (io.micrometer.core.instrument.Counter)3 MetricsFeature (org.apache.cxf.metrics.MetricsFeature)3 HelloService (org.apache.cxf.systest.jaxws.resources.HelloService)3 NotFoundException (javax.ws.rs.NotFoundException)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 Builder (javax.ws.rs.client.Invocation.Builder)2 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)2 Book (org.apache.cxf.systest.jaxrs.resources.Book)2 Test (org.junit.Test)2 BadRequestException (javax.ws.rs.BadRequestException)1 Endpoint (javax.xml.ws.Endpoint)1