From bc93cde17ef1366d587dbb59011592943b68b281 Mon Sep 17 00:00:00 2001 From: Ashi Bhardwaj Date: Thu, 2 Jan 2025 20:36:06 +0530 Subject: [PATCH] [Backport] Upgrade async-http-client (#17558) --- licenses.yaml | 2 +- pom.xml | 3 +-- .../apache/druid/java/util/emitter/core/HttpPostEmitter.java | 4 ++-- .../apache/druid/java/util/emitter/core/HttpEmitterTest.java | 5 +++-- .../druid/java/util/http/client/AsyncHttpClientTest.java | 5 +++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/licenses.yaml b/licenses.yaml index 10b17a55ab28..19ddb90dcdfa 100644 --- a/licenses.yaml +++ b/licenses.yaml @@ -1924,7 +1924,7 @@ name: AsyncHttpClient asynchttpclient license_category: binary module: java-core license_name: Apache License version 2.0 -version: 2.5.3 +version: 3.0.1 libraries: - org.asynchttpclient: async-http-client - org.asynchttpclient: async-http-client-netty-utils diff --git a/pom.xml b/pom.xml index 19e22a72076c..36f888f6201f 100644 --- a/pom.xml +++ b/pom.xml @@ -980,8 +980,7 @@ org.asynchttpclient async-http-client - - 2.5.3 + 3.0.1 net.java.dev.jna diff --git a/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java b/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java index f70b7e7d3fd8..5bce984f9b6d 100644 --- a/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java +++ b/processing/src/main/java/org/apache/druid/java/util/emitter/core/HttpPostEmitter.java @@ -23,7 +23,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.base.Predicate; -import com.google.common.primitives.Ints; import io.netty.handler.codec.http.HttpHeaders; import org.apache.druid.concurrent.ConcurrentAwaitableCounter; import org.apache.druid.java.util.common.ISE; @@ -45,6 +44,7 @@ import java.net.URL; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.ArrayDeque; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.ConcurrentLinkedQueue; @@ -773,7 +773,7 @@ private void send(byte[] buffer, int length) throws Exception request.setHeader(HttpHeaders.Names.AUTHORIZATION, "Basic " + encoded); } - request.setRequestTimeout(Ints.saturatedCast(timeoutMillis)); + request.setRequestTimeout(Duration.ofMillis(timeoutMillis)); ListenableFuture future = client.executeRequest(request); Response response; diff --git a/processing/src/test/java/org/apache/druid/java/util/emitter/core/HttpEmitterTest.java b/processing/src/test/java/org/apache/druid/java/util/emitter/core/HttpEmitterTest.java index b589455b4d83..b80a35af5a33 100644 --- a/processing/src/test/java/org/apache/druid/java/util/emitter/core/HttpEmitterTest.java +++ b/processing/src/test/java/org/apache/druid/java/util/emitter/core/HttpEmitterTest.java @@ -30,6 +30,7 @@ import org.junit.Test; import java.io.IOException; +import java.time.Duration; import java.util.concurrent.atomic.AtomicLong; public class HttpEmitterTest @@ -56,8 +57,8 @@ public void setup() @Override protected ListenableFuture go(Request request) { - int timeout = request.getRequestTimeout(); - timeoutUsed.set(timeout); + Duration timeout = request.getRequestTimeout(); + timeoutUsed.set(timeout.toMillis()); return GoHandlers.immediateFuture(EmitterTest.okResponse()); } }); diff --git a/processing/src/test/java/org/apache/druid/java/util/http/client/AsyncHttpClientTest.java b/processing/src/test/java/org/apache/druid/java/util/http/client/AsyncHttpClientTest.java index aa20c0eaf84e..817eeb5a8d18 100644 --- a/processing/src/test/java/org/apache/druid/java/util/http/client/AsyncHttpClientTest.java +++ b/processing/src/test/java/org/apache/druid/java/util/http/client/AsyncHttpClientTest.java @@ -30,6 +30,7 @@ import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.time.Duration; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -81,7 +82,7 @@ public void run() requestStart = System.currentTimeMillis(); Future future = client .prepareGet(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort())) - .setRequestTimeout(2000) + .setRequestTimeout(Duration.ofMillis(2000)) .execute(); System.out.println("created future in: " + (System.currentTimeMillis() - requestStart)); future.get(3000, TimeUnit.MILLISECONDS); @@ -103,7 +104,7 @@ private void warmUp(ServerSocket serverSocket, DefaultAsyncHttpClient client) try { Future future = client .prepareGet(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort())) - .setRequestTimeout(100) + .setRequestTimeout(Duration.ofMillis(100)) .execute(); future.get(); }