Search in sources :

Example 1 with AggregatedHttpRequest

use of com.linecorp.armeria.common.AggregatedHttpRequest in project zipkin by openzipkin.

the class ElasticsearchSpanStoreTest method requestLimitedTo2DaysOfIndices_singleTypeIndex.

void requestLimitedTo2DaysOfIndices_singleTypeIndex() {
    long today = TestObjects.midnightUTC(System.currentTimeMillis());
    long yesterday = today - TimeUnit.DAYS.toMillis(1);
    // 24 hrs ago always will fall into 2 days (ex. if it is 4:00pm, 24hrs ago is a different day)
    String indexesToSearch = "" + storage.indexNameFormatter().formatTypeAndTimestamp(TYPE_SPAN, yesterday) + "," + storage.indexNameFormatter().formatTypeAndTimestamp(TYPE_SPAN, today);
    AggregatedHttpRequest request = server.takeRequest().request();
    assertThat(request.path()).startsWith("/" + indexesToSearch + "/_search");
}
Also used : AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest)

Example 2 with AggregatedHttpRequest

use of com.linecorp.armeria.common.AggregatedHttpRequest in project zipkin by openzipkin.

the class ElasticsearchSpanConsumerTest method addsPipelineId.

@Test
void addsPipelineId() throws Exception {
    storage.close();
    storage = ElasticsearchStorage.newBuilder(() -> WebClient.of(server.httpUri())).pipeline("zipkin").build();
    ensureIndexTemplate();
    server.enqueue(SUCCESS_RESPONSE);
    accept(Span.newBuilder().traceId("1").id("1").name("foo").build());
    AggregatedHttpRequest request = server.takeRequest().request();
    assertThat(request.path()).isEqualTo("/_bulk?pipeline=zipkin");
}
Also used : AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Test(org.junit.jupiter.api.Test)

Example 3 with AggregatedHttpRequest

use of com.linecorp.armeria.common.AggregatedHttpRequest in project zipkin by openzipkin.

the class HttpCallTest method streamingContent.

@Test
void streamingContent() throws Exception {
    server.enqueue(SUCCESS_RESPONSE);
    HttpCall.RequestSupplier supplier = new HttpCall.RequestSupplier() {

        @Override
        public RequestHeaders headers() {
            return RequestHeaders.of(HttpMethod.POST, "/");
        }

        @Override
        public void writeBody(HttpCall.RequestStream requestStream) {
            requestStream.tryWrite(HttpData.ofUtf8("hello"));
            requestStream.tryWrite(HttpData.ofUtf8(" world"));
        }
    };
    http.newCall(supplier, NULL, "test").execute();
    AggregatedHttpRequest request = server.takeRequest().request();
    assertThat(request.method()).isEqualTo(HttpMethod.POST);
    assertThat(request.path()).isEqualTo("/");
    assertThat(request.contentUtf8()).isEqualTo("hello world");
}
Also used : AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Test(org.junit.jupiter.api.Test)

Example 4 with AggregatedHttpRequest

use of com.linecorp.armeria.common.AggregatedHttpRequest in project curiostack by curioswitch.

the class ArmeriaSdkHttpClientIntegrationTest method normal.

@Test
void normal() {
    server.enqueue(HttpResponse.of(HttpStatus.OK));
    GetItemResponse response = dynamoDbAsync.getItem(GetItemRequest.builder().tableName("test").key(ImmutableMap.of()).build()).join();
    assertThat(response.sdkHttpResponse().isSuccessful()).isTrue();
    AggregatedHttpRequest request = server.takeRequest().request();
    assertThat(request.headers().get(HttpHeaderNames.USER_AGENT)).contains("http/ArmeriaAsync");
}
Also used : GetItemResponse(software.amazon.awssdk.services.dynamodb.model.GetItemResponse) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Test(org.junit.jupiter.api.Test)

Example 5 with AggregatedHttpRequest

use of com.linecorp.armeria.common.AggregatedHttpRequest in project curiostack by curioswitch.

the class ArmeriaSdkHttpClientTest method converts_success.

@Test
void converts_success() {
    StreamMessage<ByteBuffer> requestStream = StreamMessage.of(ByteBuffer.wrap("meow".getBytes(StandardCharsets.UTF_8)), ByteBuffer.wrap("woof".getBytes(StandardCharsets.UTF_8)));
    AtomicReference<SdkHttpResponse> responseHeaders = new AtomicReference<>();
    AtomicReference<Throwable> responseError = new AtomicReference<>();
    AtomicReference<Throwable> responseSubscriberError = new AtomicReference<>();
    AtomicBoolean responseComplete = new AtomicBoolean();
    List<ByteBuffer> responsePayloads = new ArrayList<>();
    AsyncExecuteRequest request = AsyncExecuteRequest.builder().request(SdkHttpRequest.builder().protocol("https").method(SdkHttpMethod.POST).host("github.com").appendHeader("X-Animals", "cat").appendHeader("X-Animals", "dog").appendHeader("Content-Type", "application/json").encodedPath("/foo").appendRawQueryParameter("bar", "baz").build()).responseHandler(new SdkAsyncHttpResponseHandler() {

        @Override
        public void onHeaders(SdkHttpResponse headers) {
            responseHeaders.set(headers);
        }

        @Override
        public void onStream(Publisher<ByteBuffer> stream) {
            stream.subscribe(new Subscriber<ByteBuffer>() {

                @Override
                public void onSubscribe(Subscription s) {
                    s.request(Long.MAX_VALUE);
                }

                @Override
                public void onNext(ByteBuffer byteBuffer) {
                    responsePayloads.add(byteBuffer);
                }

                @Override
                public void onError(Throwable t) {
                    responseSubscriberError.set(t);
                }

                @Override
                public void onComplete() {
                    responseComplete.set(true);
                }
            });
        }

        @Override
        public void onError(Throwable error) {
            responseError.set(error);
        }
    }).requestContentPublisher(new SdkHttpContentPublisher() {

        @Override
        public Optional<Long> contentLength() {
            return Optional.of((long) ("body1" + "body2").length());
        }

        @Override
        public void subscribe(Subscriber<? super ByteBuffer> s) {
            requestStream.subscribe(s);
        }
    }).fullDuplex(false).build();
    AtomicReference<AggregatedHttpRequest> aggregatedRequest = new AtomicReference<>();
    when(webClient.execute(any(HttpRequest.class))).thenAnswer((Answer<HttpResponse>) invocation -> {
        HttpRequest httpRequest = invocation.getArgument(0);
        aggregatedRequest.set(httpRequest.aggregate().join());
        return HttpResponse.of(ResponseHeaders.of(HttpStatus.OK, HttpHeaderNames.CONTENT_TYPE, "application/json", HttpHeaderNames.of("X-Countries"), "Japan", HttpHeaderNames.of("X-Countries"), "US"), HttpData.ofUtf8("purr"), HttpData.ofUtf8("growl"));
    });
    CompletableFuture<Void> responseFuture = client.execute(request);
    assertThat(responseFuture.join()).isNull();
    assertThat(responseHeaders.get()).satisfies(headers -> {
        assertThat(headers.statusCode()).isEqualTo(HttpStatus.OK.code());
        assertThat(headers.statusText()).hasValue(HttpStatus.OK.reasonPhrase());
        assertThat(headers.headers()).containsEntry("content-type", ImmutableList.of("application/json")).containsEntry("x-countries", ImmutableList.of("Japan", "US"));
    });
    assertThat(responsePayloads).extracting(buf -> Unpooled.wrappedBuffer(buf).toString(StandardCharsets.UTF_8)).containsExactly("purr", "growl");
    assertThat(responseError.get()).isNull();
    assertThat(responseSubscriberError.get()).isNull();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) HttpHeaderNames(com.linecorp.armeria.common.HttpHeaderNames) ByteBuffer(java.nio.ByteBuffer) Unpooled(io.netty.buffer.Unpooled) ArrayList(java.util.ArrayList) Answer(org.mockito.stubbing.Answer) ImmutableList(com.google.common.collect.ImmutableList) CurioAssertions.assertThat(org.curioswitch.common.testing.assertj.CurioAssertions.assertThat) HttpStatus(com.linecorp.armeria.common.HttpStatus) WebClient(com.linecorp.armeria.client.WebClient) SdkHttpMethod(software.amazon.awssdk.http.SdkHttpMethod) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Subscriber(org.reactivestreams.Subscriber) HttpData(com.linecorp.armeria.common.HttpData) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Publisher(org.reactivestreams.Publisher) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) Mockito.when(org.mockito.Mockito.when) StandardCharsets(java.nio.charset.StandardCharsets) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Test(org.junit.jupiter.api.Test) HttpRequest(com.linecorp.armeria.common.HttpRequest) List(java.util.List) StreamMessage(com.linecorp.armeria.common.stream.StreamMessage) ResponseHeaders(com.linecorp.armeria.common.ResponseHeaders) Subscription(org.reactivestreams.Subscription) Optional(java.util.Optional) ArrayList(java.util.ArrayList) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Subscription(org.reactivestreams.Subscription) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) AggregatedHttpRequest(com.linecorp.armeria.common.AggregatedHttpRequest) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) HttpRequest(com.linecorp.armeria.common.HttpRequest) Optional(java.util.Optional) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) HttpResponse(com.linecorp.armeria.common.HttpResponse) AtomicReference(java.util.concurrent.atomic.AtomicReference) Publisher(org.reactivestreams.Publisher) SdkHttpContentPublisher(software.amazon.awssdk.http.async.SdkHttpContentPublisher) ByteBuffer(java.nio.ByteBuffer) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Test(org.junit.jupiter.api.Test)

Aggregations

AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)11 Test (org.junit.jupiter.api.Test)8 HttpData (com.linecorp.armeria.common.HttpData)3 CONTENT_TYPE (com.linecorp.armeria.common.HttpHeaderNames.CONTENT_TYPE)2 HttpMethod (com.linecorp.armeria.common.HttpMethod)2 DELETE (com.linecorp.armeria.common.HttpMethod.DELETE)2 GET (com.linecorp.armeria.common.HttpMethod.GET)2 PUT (com.linecorp.armeria.common.HttpMethod.PUT)2 JSON_UTF_8 (com.linecorp.armeria.common.MediaType.JSON_UTF_8)2 RequestHeaders (com.linecorp.armeria.common.RequestHeaders)2 IOException (java.io.IOException)2 Arrays.asList (java.util.Arrays.asList)2 TestInfo (org.junit.jupiter.api.TestInfo)2 TestInstance (org.junit.jupiter.api.TestInstance)2 Span (zipkin2.Span)2 TestObjects.spanBuilder (zipkin2.TestObjects.spanBuilder)2 ElasticsearchStorage (zipkin2.elasticsearch.ElasticsearchStorage)2 Internal (zipkin2.elasticsearch.internal.Internal)2 ITStorage (zipkin2.storage.ITStorage)2 StorageComponent (zipkin2.storage.StorageComponent)2