use of com.artipie.http.rq.RequestLine in project artipie by artipie.
the class ResponseMetricsSliceTest method shouldForwardRequestUnmodified.
@Test
void shouldForwardRequestUnmodified() {
final Header header = new Header("header1", "value1");
final byte[] body = "some code".getBytes();
final RsStatus status = RsStatus.CREATED;
MatcherAssert.assertThat(new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(status, rsheaders, rsbody), this.metrics).response(new RequestLine(RqMethod.POST, "/some_upload.war").toString(), new Headers.From(header), Flowable.just(ByteBuffer.wrap(body))), new ResponseMatcher(status, body, header));
}
use of com.artipie.http.rq.RequestLine in project artipie by artipie.
the class AuthAndPermissionsTest method adminCanDeploy.
@Test
void adminCanDeploy() throws IOException {
final RsStatus status = RsStatus.ACCEPTED;
MatcherAssert.assertThat(new BasicAuthSlice(new SliceSimple(new RsWithStatus(status)), new AuthFromYaml(this.credentials()), new Permission.ByName("deploy", this.permissions())).response(new RequestLine("PUT", "/foo", "HTTP/1.2").toString(), new ListOf<Map.Entry<String, String>>(new Authorization(String.format("Basic %s", new Base64Encoded("admin:abc").asString()))), Flowable.empty()), new RsHasStatus(status));
}
use of com.artipie.http.rq.RequestLine in project artipie by artipie.
the class ResponseMetricsSliceTest method shouldForwardResponseUnmodified.
@Test
void shouldForwardResponseUnmodified() {
final Header rsheader = new Header("header2", "value2");
final byte[] body = "piece of code".getBytes();
final RsStatus rsstatus = RsStatus.CREATED;
final Response response = new ResponseMetricsSlice((rsline, rsheaders, rsbody) -> new RsFull(rsstatus, new Headers.From(rsheader), Flowable.just(ByteBuffer.wrap(body))), this.metrics).response(new RequestLine(RqMethod.PUT, "/").toString(), Headers.EMPTY, Flowable.empty());
MatcherAssert.assertThat(response, new ResponseMatcher(rsstatus, body, rsheader));
}
use of com.artipie.http.rq.RequestLine 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));
}
use of com.artipie.http.rq.RequestLine in project artipie by artipie.
the class PromuSliceTest method returnsMetricsThatMatchNames.
@Test
void returnsMetricsThatMatchNames() {
final Metrics metrics = new InMemoryMetrics();
metrics.counter("http.response.count").inc();
metrics.gauge("http.response.content").set(5000L);
metrics.gauge("app.workload").set(300L);
MatcherAssert.assertThat(new PromuSlice(metrics), new SliceHasResponse(new RsHasBody(new AnyOf<>(new IsEqual<>(String.join("\n", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "")), new IsEqual<>(String.join("\n", "# HELP app_workload App workload", "# TYPE app_workload gauge", "app_workload 300.0", "# HELP http_response_content Http response content", "# TYPE http_response_content gauge", "http_response_content 5000.0", ""))), StandardCharsets.UTF_8), new RequestLine(RqMethod.GET, "/prometheus/metrics?name=http_response_content&name=app_workload"), new Headers.From(new Header(Accept.NAME, PromuSliceTest.PLAIN_TEXT)), Content.EMPTY));
}
Aggregations