Fix httpsSegmentFetcher to use the configurable timeouts (#15485) (#15499)
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcher.java b/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcher.java
index 6a77611..010b43e 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcher.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcher.java
@@ -44,9 +44,9 @@
public class HttpSegmentFetcher extends BaseSegmentFetcher {
protected FileUploadDownloadClient _httpClient;
- private static final String CONNECTION_REQUEST_TIMEOUT_CONFIG_KEY =
+ public static final String CONNECTION_REQUEST_TIMEOUT_CONFIG_KEY =
"http.request.connectionRequestTimeoutMs";
- private static final String SOCKET_TIMEOUT_CONFIG_KEY = "http.request.socketTimeoutMs";
+ public static final String SOCKET_TIMEOUT_CONFIG_KEY = "http.request.socketTimeoutMs";
private int _connectionRequestTimeoutMs;
private int _socketTimeoutMs;
@@ -55,6 +55,17 @@
_httpClient = httpClient;
}
+ @VisibleForTesting
+ public int getConnectionRequestTimeoutMs() {
+ return _connectionRequestTimeoutMs;
+ }
+
+ @VisibleForTesting
+ public int getSocketTimeoutMs() {
+ return _socketTimeoutMs;
+ }
+
+
@Override
protected void doInit(PinotConfiguration config) {
if (_httpClient == null) {
diff --git a/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpsSegmentFetcher.java b/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpsSegmentFetcher.java
index 7152859..e6b0853 100644
--- a/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpsSegmentFetcher.java
+++ b/pinot-common/src/main/java/org/apache/pinot/common/utils/fetcher/HttpsSegmentFetcher.java
@@ -71,5 +71,6 @@
SSLContext sslContext = new ClientSSLContextGenerator(sslConfig).generate();
_httpClient = new FileUploadDownloadClient(HttpClientConfig.newBuilder(config).build(), sslContext);
+ super.doInit(config);
}
}
diff --git a/pinot-common/src/test/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcherTest.java b/pinot-common/src/test/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcherTest.java
index 1a56790..c83036a 100644
--- a/pinot-common/src/test/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcherTest.java
+++ b/pinot-common/src/test/java/org/apache/pinot/common/utils/fetcher/HttpSegmentFetcherTest.java
@@ -21,14 +21,17 @@
import java.io.File;
import java.net.URI;
import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;
import org.apache.commons.io.FileUtils;
import org.apache.pinot.common.utils.FileUploadDownloadClient;
import org.apache.pinot.spi.env.PinotConfiguration;
import org.apache.pinot.spi.utils.retry.AttemptsExceededException;
+import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import static org.apache.pinot.common.utils.fetcher.HttpSegmentFetcher.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -46,12 +49,23 @@
_fetcherConfig.setProperty(BaseSegmentFetcher.RETRY_COUNT_CONFIG_KEY, 3);
_fetcherConfig.setProperty(BaseSegmentFetcher.RETRY_WAIT_MS_CONFIG_KEY, 10);
_fetcherConfig.setProperty(BaseSegmentFetcher.RETRY_DELAY_SCALE_FACTOR_CONFIG_KEY, 1.1);
+ _fetcherConfig.setProperty(CONNECTION_REQUEST_TIMEOUT_CONFIG_KEY, 1000);
+ _fetcherConfig.setProperty(SOCKET_TIMEOUT_CONFIG_KEY, 1000);
}
private HttpSegmentFetcher getSegmentFetcher(FileUploadDownloadClient client) {
- HttpSegmentFetcher segmentFetcher = new HttpSegmentFetcher();
- segmentFetcher.setHttpClient(client);
+ HttpSegmentFetcher segmentFetcher;
+ if (ThreadLocalRandom.current().nextBoolean()) {
+ segmentFetcher = new HttpsSegmentFetcher();
+ } else {
+ segmentFetcher = new HttpSegmentFetcher();
+ }
+
segmentFetcher.init(_fetcherConfig);
+ segmentFetcher.setHttpClient(client);
+
+ Assert.assertEquals(segmentFetcher.getSocketTimeoutMs(), 1000);
+ Assert.assertEquals(segmentFetcher.getConnectionRequestTimeoutMs(), 1000);
return segmentFetcher;
}