Skip to content

Commit c7e7acb

Browse files
GH-3482: parquet-hadoop tests to work behind a web proxy (#3483)
* parquet-hadoop tests to work behind a web proxy * parquet-hadoop to use separate JVM propertied not to clash with existing CI * syntax fix * parquet-hadoop: another test provisioned to run behind a web proxy * safer condition, catching NPE at InterOpTester.java * better proxy misconfig diagnostic for testing offered by Copilot Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent e440cff commit c7e7acb

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

parquet-hadoop/src/test/java/org/apache/parquet/hadoop/InterOpTester.java

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
package org.apache.parquet.hadoop;
2121

2222
import java.io.IOException;
23+
import java.net.InetSocketAddress;
24+
import java.net.Proxy;
2325
import okhttp3.OkHttpClient;
2426
import okhttp3.Request;
2527
import okhttp3.Response;
@@ -34,7 +36,37 @@ public class InterOpTester {
3436
private static final String PARQUET_TESTING_REPO = "https://github.com/apache/parquet-testing/raw/";
3537
private static final String PARQUET_TESTING_PATH = "target/parquet-testing/";
3638
private static final Logger LOG = LoggerFactory.getLogger(InterOpTester.class);
37-
private OkHttpClient httpClient = new OkHttpClient();
39+
// since PARQUET_TESTING_REPO might be beyond a web proxy ...
40+
public static OkHttpClient createOkHttpClientOptProxy() {
41+
/* We use a different JVM property set,
42+
* because CI may define JVM properties
43+
* "https.proxyHost" and "https.proxyPort"
44+
* and that proxy won't support some compressions
45+
* (e.g. gzip/snappy on github.com CI).
46+
*/
47+
String proxyHost = System.getProperty("parquet.https.proxyHost");
48+
String proxyPort = System.getProperty("parquet.https.proxyPort");
49+
OkHttpClient client = null;
50+
if (proxyHost != null && proxyPort != null) {
51+
try {
52+
int port = Integer.valueOf(proxyPort);
53+
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, port));
54+
client = new OkHttpClient.Builder().proxy(proxy).build();
55+
} catch (NumberFormatException e) {
56+
LOG.warn(
57+
"Ignoring proxy configuration because proxy port could not be parsed: "
58+
+ "parquet.https.proxyHost='{}', parquet.https.proxyPort='{}'. "
59+
+ "Falling back to a direct connection.",
60+
proxyHost,
61+
proxyPort,
62+
e);
63+
}
64+
}
65+
if (client == null) client = new OkHttpClient();
66+
return client;
67+
}
68+
69+
private OkHttpClient httpClient = createOkHttpClientOptProxy();
3870

3971
public Path GetInterOpFile(String fileName, String changeset) throws IOException {
4072
return GetInterOpFile(fileName, changeset, "data");

parquet-hadoop/src/test/java/org/apache/parquet/hadoop/TestInteropBloomFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class TestInteropBloomFilter {
5757
private static String DATA_INDEX_BLOOM_WITH_LENGTH_FILE = "data_index_bloom_encoding_with_length.parquet";
5858

5959
private static final Logger LOG = LoggerFactory.getLogger(TestInteropBloomFilter.class);
60-
private OkHttpClient httpClient = new OkHttpClient();
60+
private OkHttpClient httpClient = InterOpTester.createOkHttpClientOptProxy();
6161

6262
@Test
6363
public void testReadDataIndexBloomParquetFiles() throws IOException {

0 commit comments

Comments
 (0)