hudi-agent commented on code in PR #20020:
URL: https://github.com/apache/hudi/pull/20020#discussion_r4135456641


##########
packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.hudi.gcp.bundle;
+
+import com.google.cloud.NoCredentials;
+import com.google.cloud.bigquery.BigQueryOptions;
+import com.google.cloud.storage.StorageOptions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ITGcpBundleCompatibility {
+
+  private enum ClasspathOrder {
+    HOST_FIRST,
+    BUNDLE_FIRST
+  }
+
+  @Test
+  void testHostDependenciesBeforeBundle() throws Exception {
+    runSmokeTest(ClasspathOrder.HOST_FIRST);
+  }
+
+  @Test
+  void testBundleBeforeHostDependencies() throws Exception {
+    runSmokeTest(ClasspathOrder.BUNDLE_FIRST);
+  }
+
+  private static void runSmokeTest(ClasspathOrder order) throws Exception {
+    String bundleJar = System.getProperty("gcp.bundle.jar");
+    String testClasses = System.getProperty("gcp.test.classes");
+    String hostProtobuf = System.getProperty("host.protobuf.jar");
+    String hostGuava = System.getProperty("host.guava.jar");
+    String hostJacksonCore = System.getProperty("host.jackson.core.jar");
+
+    List<String> orderedClasspath = new ArrayList<>();
+    orderedClasspath.add(testClasses);
+    if (order == ClasspathOrder.HOST_FIRST) {
+      orderedClasspath.add(hostProtobuf);
+      orderedClasspath.add(hostGuava);
+    }
+    orderedClasspath.add(bundleJar);
+    if (order == ClasspathOrder.BUNDLE_FIRST) {
+      orderedClasspath.add(hostProtobuf);
+      orderedClasspath.add(hostGuava);
+    }
+    orderedClasspath.add(hostJacksonCore);
+
+    Process process = new ProcessBuilder(
+        new File(System.getProperty("java.home"), 
"bin/java").getAbsolutePath(),
+        "-cp",
+        String.join(File.pathSeparator, orderedClasspath),
+        ITGcpBundleCompatibility.class.getName(),
+        "smoke")
+        .inheritIO()
+        .start();
+    assertEquals(0, process.waitFor(), "GCP bundle compatibility smoke test 
failed");
+  }
+
+  public static void main(String[] args) throws Exception {
+    if (args.length != 1 || !"smoke".equals(args[0])) {
+      throw new IllegalArgumentException("Expected smoke mode");
+    }
+
+    verifyShadedProtobuf();
+    verifyShadedGuava();
+    verifyHostGuava();
+    verifyStorageClient();
+    verifyBigQueryClient();
+    verifyThreeTenExtra();
+  }
+
+  private static void verifyShadedProtobuf() throws Exception {
+    Class<?> timestampClass = Class.forName(
+        "org.apache.hudi.gcp.shaded.com.google.protobuf.Timestamp");
+    Object timestampBuilder = 
timestampClass.getMethod("newBuilder").invoke(null);
+    Method setSeconds = timestampBuilder.getClass().getMethod("setSeconds", 
long.class);
+    Object timestamp = timestampBuilder.getClass().getMethod("build")
+        .invoke(setSeconds.invoke(timestampBuilder, 1L));
+    byte[] timestampBytes = (byte[]) 
timestampClass.getMethod("toByteArray").invoke(timestamp);
+    if (timestampBytes.length == 0) {
+      throw new AssertionError("Protobuf serialization returned no bytes");
+    }
+  }
+
+  private static void verifyShadedGuava() throws Exception {
+    Class<?> domainNameClass = Class.forName(

Review Comment:
   🤖 nit: `verifyShadedGuava` and `verifyHostGuava` are the same apart from the 
class name. Could you fold them into one `verifyPublicSuffix(String 
internetDomainNameClass)` helper?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
packaging/hudi-gcp-bundle/src/test/java/org/apache/hudi/gcp/bundle/ITGcpBundleCompatibility.java:
##########
@@ -0,0 +1,155 @@
+/*
+ * 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.hudi.gcp.bundle;
+
+import com.google.cloud.NoCredentials;
+import com.google.cloud.bigquery.BigQueryOptions;
+import com.google.cloud.storage.StorageOptions;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class ITGcpBundleCompatibility {
+
+  private enum ClasspathOrder {
+    HOST_FIRST,
+    BUNDLE_FIRST
+  }
+
+  @Test
+  void testHostDependenciesBeforeBundle() throws Exception {
+    runSmokeTest(ClasspathOrder.HOST_FIRST);
+  }
+
+  @Test
+  void testBundleBeforeHostDependencies() throws Exception {
+    runSmokeTest(ClasspathOrder.BUNDLE_FIRST);
+  }
+
+  private static void runSmokeTest(ClasspathOrder order) throws Exception {
+    String bundleJar = System.getProperty("gcp.bundle.jar");
+    String testClasses = System.getProperty("gcp.test.classes");
+    String hostProtobuf = System.getProperty("host.protobuf.jar");
+    String hostGuava = System.getProperty("host.guava.jar");
+    String hostJacksonCore = System.getProperty("host.jackson.core.jar");
+
+    List<String> orderedClasspath = new ArrayList<>();
+    orderedClasspath.add(testClasses);
+    if (order == ClasspathOrder.HOST_FIRST) {

Review Comment:
   🤖 nit: the host jars get added in two mirrored `if` blocks. Have you 
considered building `hostJars = Arrays.asList(hostProtobuf, hostGuava)` once 
and adding it before or after `bundleJar` depending on `order`?
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



##########
packaging/hudi-gcp-bundle/pom.xml:
##########
@@ -114,6 +182,24 @@
                   <pattern>org.openjdk.jol.</pattern>
                   
<shadedPattern>org.apache.hudi.org.openjdk.jol.</shadedPattern>
                 </relocation>
+                <relocation>
+                  <pattern>com.google.common.</pattern>
+                  
<shadedPattern>org.apache.hudi.com.google.common.</shadedPattern>
+                </relocation>
+                <relocation>
+                  <pattern>com.google.thirdparty.</pattern>
+                  
<shadedPattern>org.apache.hudi.com.google.thirdparty.</shadedPattern>
+                </relocation>
+                <!-- hudi-io already uses org.apache.hudi.com.google.protobuf, 
so keep the GCP
+                     protobuf and gRPC copies in a separate namespace. -->
+                <relocation>
+                  <pattern>com.google.protobuf.</pattern>

Review Comment:
   🤖 This relocation also rewrites the bundled `OrcUtils.readFooter` (from 
hudi-hadoop-common). In the shaded jar, the call becomes 
`OrcProto$UserMetadataItem.getValue:()Lorg/apache/hudi/gcp/shaded/com/google/protobuf/ByteString;`,
 and orc-core isn't bundled, so that method doesn't exist anywhere. Reading an 
ORC footer through this bundle's copy of the class would then throw 
`NoSuchMethodError`. Could `readFooter` use 
`reader.getMetadataKeys()`/`getMetadataValue(key)` instead? Those return a 
`ByteBuffer` and don't expose protobuf types.
   
   <sub><i>⚠️ AI-generated; verify before applying. React 👍/👎 to flag 
quality.</i></sub>



-- 
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]

Reply via email to