cescoffier commented on a change in pull request #3597: URL: https://github.com/apache/camel-quarkus/pull/3597#discussion_r821494630
########## File path: extensions-support/azure-core-http-client-vertx/runtime/src/main/java/org/apache/camel/quarkus/support/azure/core/http/vertx/BufferedVertxHttpResponse.java ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.ByteBuffer; + +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import io.vertx.core.buffer.Buffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public final class BufferedVertxHttpResponse extends VertxHttpAsyncResponse { + + private final Buffer body; + + BufferedVertxHttpResponse(HttpRequest request, io.vertx.ext.web.client.HttpResponse response, Buffer body) { + super(request, response); + this.body = body; + } + + @Override + public Flux<ByteBuffer> getBody() { Review comment: Does the usage of Mono and Flux come from the Azure SDK? ########## File path: extensions-support/azure-core-http-client-vertx/deployment/src/test/java/org/apache/camel/quarkus/support/azure/core/http/vertx/VertxHttpClientBuilderTests.java ########## @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.net.InetSocketAddress; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpMethod; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.ProxyOptions; +import com.azure.core.util.Configuration; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import io.vertx.core.Vertx; +import io.vertx.ext.web.client.WebClientOptions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import reactor.test.StepVerifier; + +import static org.apache.camel.quarkus.support.azure.core.http.vertx.VertxHttpClientTestResource.PROXY_PASSWORD; +import static org.apache.camel.quarkus.support.azure.core.http.vertx.VertxHttpClientTestResource.PROXY_USER; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests {@link VertxHttpClientBuilder}. + */ +public class VertxHttpClientBuilderTests { + private static final String COOKIE_VALIDATOR_PATH = "/cookieValidator"; + private static final String DEFAULT_PATH = "/default"; + private static final String DISPATCHER_PATH = "/dispatcher"; + + private static final WireMockServer server = new WireMockServer( + WireMockConfiguration.options().dynamicPort().disableRequestJournal()); + private static final Vertx vertx = Vertx.vertx(); + + private static String defaultUrl; + + @BeforeAll + public static void setupWireMock() { + // Mocked endpoint to test building a client with a prebuilt client. + server.stubFor(WireMock.get(COOKIE_VALIDATOR_PATH).withCookie("test", WireMock.matching("success")) + .willReturn(WireMock.aResponse().withStatus(200))); + + // Mocked endpoint to test building a client with a timeout. + server.stubFor(WireMock.get(DEFAULT_PATH).willReturn(WireMock.aResponse().withStatus(200))); + + // Mocked endpoint to test building a client with a dispatcher and uses a delayed response. + server.stubFor(WireMock.get(DISPATCHER_PATH).willReturn(WireMock.aResponse().withStatus(200) + .withFixedDelay(5000))); + + server.start(); + + defaultUrl = "http://localhost:" + server.port() + DEFAULT_PATH; + } + + @AfterAll + public static void shutdownWireMock() { + if (server.isRunning()) { + server.shutdown(); + } + vertx.close(); + } + + @Test + public void buildWithConfigurationNone() { + HttpClient client = new VertxHttpClientBuilder(vertx) Review comment: It might be beneficial to close the client. It will be closed automatically when vert.x is closed, but you only close vert.x after all the tests. ########## File path: extensions-support/azure-core-http-client-vertx/deployment/src/test/java/org/apache/camel/quarkus/support/azure/core/http/vertx/VertxHttpClientHttpClientTests.java ########## @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import com.azure.core.http.HttpClient; +import com.azure.core.test.HttpClientTestsWireMockServer; +import com.azure.core.test.http.HttpClientTests; +import com.github.tomakehurst.wiremock.WireMockServer; +import io.vertx.core.Vertx; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; + +public class VertxHttpClientHttpClientTests extends HttpClientTests { + private static final WireMockServer server = HttpClientTestsWireMockServer.getHttpClientTestsServer(); + private static final Vertx vertx = Vertx.vertx(); + + @BeforeAll + public static void getWireMockServer() { + server.start(); + } + + @AfterAll + public static void shutdownWireMockServer() { + server.shutdown(); + vertx.close(); Review comment: Same comment, it is generally better to wait for the termination. ########## File path: extensions-support/azure-core-http-client-vertx/runtime/src/main/java/org/apache/camel/quarkus/support/azure/core/http/vertx/BufferedVertxHttpResponse.java ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.ByteBuffer; + +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import io.vertx.core.buffer.Buffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public final class BufferedVertxHttpResponse extends VertxHttpAsyncResponse { + + private final Buffer body; + + BufferedVertxHttpResponse(HttpRequest request, io.vertx.ext.web.client.HttpResponse response, Buffer body) { + super(request, response); + this.body = body; Review comment: We can do something better here (not sure it's needed). We could just get the body handler or the read stream associated with it and returns truly async Mono and Flux. It would only be useful if: 1. the operation needs to be lazy 2. the body size is huge ########## File path: extensions-support/azure-core-http-client-vertx/deployment/src/test/java/org/apache/camel/quarkus/support/azure/core/http/vertx/VertxHttpClientBuilderTests.java ########## @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.net.InetSocketAddress; +import java.time.Duration; +import java.util.ArrayList; +import java.util.List; + +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpMethod; +import com.azure.core.http.HttpRequest; +import com.azure.core.http.ProxyOptions; +import com.azure.core.util.Configuration; +import com.github.tomakehurst.wiremock.WireMockServer; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.github.tomakehurst.wiremock.core.WireMockConfiguration; +import io.vertx.core.Vertx; +import io.vertx.ext.web.client.WebClientOptions; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import reactor.test.StepVerifier; + +import static org.apache.camel.quarkus.support.azure.core.http.vertx.VertxHttpClientTestResource.PROXY_PASSWORD; +import static org.apache.camel.quarkus.support.azure.core.http.vertx.VertxHttpClientTestResource.PROXY_USER; +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * Tests {@link VertxHttpClientBuilder}. + */ +public class VertxHttpClientBuilderTests { + private static final String COOKIE_VALIDATOR_PATH = "/cookieValidator"; + private static final String DEFAULT_PATH = "/default"; + private static final String DISPATCHER_PATH = "/dispatcher"; + + private static final WireMockServer server = new WireMockServer( + WireMockConfiguration.options().dynamicPort().disableRequestJournal()); + private static final Vertx vertx = Vertx.vertx(); + + private static String defaultUrl; + + @BeforeAll + public static void setupWireMock() { + // Mocked endpoint to test building a client with a prebuilt client. + server.stubFor(WireMock.get(COOKIE_VALIDATOR_PATH).withCookie("test", WireMock.matching("success")) + .willReturn(WireMock.aResponse().withStatus(200))); + + // Mocked endpoint to test building a client with a timeout. + server.stubFor(WireMock.get(DEFAULT_PATH).willReturn(WireMock.aResponse().withStatus(200))); + + // Mocked endpoint to test building a client with a dispatcher and uses a delayed response. + server.stubFor(WireMock.get(DISPATCHER_PATH).willReturn(WireMock.aResponse().withStatus(200) + .withFixedDelay(5000))); + + server.start(); + + defaultUrl = "http://localhost:" + server.port() + DEFAULT_PATH; + } + + @AfterAll + public static void shutdownWireMock() { + if (server.isRunning()) { + server.shutdown(); + } + vertx.close(); Review comment: This is async. In general, it's better to wait for the complete termination. ```java CoundDownLatch latch = new CoundDownLatch(1); vertx.close(x -> latch.countDown()); latch.await(); ``` ########## File path: extensions-support/azure-core-http-client-vertx/runtime/src/main/java/org/apache/camel/quarkus/support/azure/core/http/vertx/BufferedVertxHttpResponse.java ########## @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.nio.ByteBuffer; + +import com.azure.core.http.HttpRequest; +import com.azure.core.http.HttpResponse; +import io.vertx.core.buffer.Buffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public final class BufferedVertxHttpResponse extends VertxHttpAsyncResponse { + + private final Buffer body; + + BufferedVertxHttpResponse(HttpRequest request, io.vertx.ext.web.client.HttpResponse response, Buffer body) { + super(request, response); + this.body = body; + } + + @Override + public Flux<ByteBuffer> getBody() { + return Flux.defer(() -> { + if (this.body == null || this.body.length() == 0) { + return Flux.empty(); + } + return Flux.just(this.body.getByteBuf().nioBuffer()); + }); + } + + @Override + public Mono<byte[]> getBodyAsByteArray() { + return Mono.defer(() -> { + if (this.body == null || this.body.length() == 0) { + return Mono.empty(); + } + return Mono.just(this.body.getBytes()); + }); + } + + @Override + public Mono<InputStream> getBodyAsInputStream() { Review comment: That is funny... InputStream is blocking by nature, so returning a Mono of InputStream is rather odd, but possible for sure. ########## File path: extensions-support/azure-core-http-client-vertx/runtime/src/main/java/org/apache/camel/quarkus/support/azure/core/http/vertx/VertxHttpAsyncResponse.java ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.quarkus.support.azure.core.http.vertx; + +import java.nio.ByteBuffer; + +import com.azure.core.http.HttpRequest; +import io.vertx.core.buffer.Buffer; +import io.vertx.ext.web.client.HttpResponse; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public class VertxHttpAsyncResponse extends VertxHttpResponse { + + VertxHttpAsyncResponse(HttpRequest request, HttpResponse response) { + super(request, response); + } + + @Override + public Flux<ByteBuffer> getBody() { + Buffer responseBody = getVertxHttpResponse().bodyAsBuffer(); Review comment: It might be better to stream the body. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
