Search in sources :

Example 1 with TestMetricsOutput

use of com.artipie.metrics.memory.TestMetricsOutput in project artipie by artipie.

the class TrafficMetricSliceTest method updatesMetrics.

@Test
void updatesMetrics() throws Exception {
    final Metrics metrics = new InMemoryMetrics();
    final int req = 100;
    final int res = 50;
    new TrafficMetricSlice((line, head, body) -> new RsWithBody(Flowable.fromPublisher(body).ignoreElements().andThen(Flowable.just(ByteBuffer.wrap(new byte[res])))), metrics).response(new RequestLine(RqMethod.GET, "/foo").toString(), Collections.emptyList(), Flowable.just(ByteBuffer.wrap(new byte[req]))).send((status, headers, body) -> Flowable.fromPublisher(body).ignoreElements().to(CompletableInterop.await())).toCompletableFuture().get();
    final TestMetricsOutput out = new TestMetricsOutput();
    metrics.publish(out);
    MatcherAssert.assertThat("request body size wasn't updated", out.counters().get("request.body.size"), Matchers.equalTo((long) req));
    MatcherAssert.assertThat("response body size wasn't updated", out.counters().get("response.body.size"), Matchers.equalTo((long) res));
}
Also used : RequestLine(com.artipie.http.rq.RequestLine) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) Metrics(com.artipie.metrics.Metrics) InMemoryMetrics(com.artipie.metrics.memory.InMemoryMetrics) TestMetricsOutput(com.artipie.metrics.memory.TestMetricsOutput) RsWithBody(com.artipie.http.rs.RsWithBody) Test(org.junit.jupiter.api.Test)

Aggregations

RequestLine (com.artipie.http.rq.RequestLine)1 RsWithBody (com.artipie.http.rs.RsWithBody)1 Metrics (com.artipie.metrics.Metrics)1 InMemoryMetrics (com.artipie.metrics.memory.InMemoryMetrics)1 TestMetricsOutput (com.artipie.metrics.memory.TestMetricsOutput)1 Test (org.junit.jupiter.api.Test)1