Search in sources :

Example 26 with RequiredSearch

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

the class SpringJaxrsApplicationTest method testJaxrsSuccessMetric.

@Test
public void testJaxrsSuccessMetric() {
    final WebTarget target = createWebTarget();
    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", "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", "UNKNOWN"), entry("uri", "http://localhost:" + port + "/api/app/library"), 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)

Example 27 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project webpieces by deanhiller.

the class TestLesson1Json method validate.

private void validate(SearchResponse resp) {
    // next if you want, move assert logic into a validate method to re-use amongst tests
    Assert.assertEquals("match1", resp.getMatches().get(0));
    // check metrics are wired correctly here as well
    RequiredSearch result = metrics.get("testCounter");
    Counter counter = result.counter();
    Assert.assertEquals(2.0, counter.count(), 0.1);
    // check the mock system was called with 6
    List<SendDataRequest> params = mockRemoteService.getSendMethodParameters();
    Assert.assertEquals(2, params.size());
    Assert.assertEquals(6, params.get(0).getNum());
}
Also used : Counter(io.micrometer.core.instrument.Counter) SendDataRequest(webpiecesxxxxxpackage.service.SendDataRequest) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch)

Example 28 with RequiredSearch

use of io.micrometer.core.instrument.search.RequiredSearch in project webpieces by deanhiller.

the class TestSyncWebServer method testBasic.

@Test
public void testBasic() {
    HttpFullRequest req = Requests.createRequest(KnownHttpMethod.GET, "/myroute");
    XFuture<HttpFullResponse> respFuture = http11Socket.send(req);
    ResponseWrapper response = ResponseExtract.waitResponseAndWrap(respFuture);
    response.assertStatusCode(KnownStatusCode.HTTP_200_OK);
    response.assertContains("This is the first raw html page");
    response.assertContentType("text/html; charset=utf-8");
    List<Header> headers = response.getResponse().getHeaderLookupStruct().getHeaders(KnownHeaderName.CONTENT_TYPE);
    Assert.assertEquals(1, headers.size());
    // check metrics are wired correctly here as well
    RequiredSearch result = meterRegistry.get("basicCounter");
    Counter counter = result.counter();
    Assert.assertEquals(1.0, counter.count(), 0.1);
}
Also used : HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) HttpFullRequest(org.webpieces.httpclient11.api.HttpFullRequest) Counter(io.micrometer.core.instrument.Counter) Header(org.webpieces.httpparser.api.common.Header) ResponseWrapper(org.webpieces.webserver.test.ResponseWrapper) RequiredSearch(io.micrometer.core.instrument.search.RequiredSearch) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

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