dimas-b commented on code in PR #4588:
URL: https://github.com/apache/polaris/pull/4588#discussion_r3389226419


##########
plugins/spark/v3.5/integration/src/sparkBundleTest/java/org/apache/polaris/spark/quarkus/it/BundleJarSanityIT.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.polaris.spark.quarkus.it;
+
+import static jakarta.ws.rs.core.Response.Status.CREATED;
+import static jakarta.ws.rs.core.Response.Status.NO_CONTENT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.iceberg.rest.HTTPClient;
+import org.apache.iceberg.rest.RESTClient;
+import org.apache.iceberg.rest.auth.AuthSession;
+import org.apache.iceberg.rest.auth.OAuth2Util;
+import org.apache.iceberg.rest.responses.OAuthTokenResponse;
+import org.apache.polaris.core.admin.model.Catalog;
+import org.apache.polaris.core.admin.model.CatalogProperties;
+import org.apache.polaris.core.admin.model.FileStorageConfigInfo;
+import org.apache.polaris.core.admin.model.PolarisCatalog;
+import org.apache.polaris.core.admin.model.StorageConfigInfo;
+import org.apache.polaris.service.it.env.ClientCredentials;
+import org.apache.polaris.service.it.env.PolarisApiEndpoints;
+import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension;
+import org.apache.spark.deploy.SparkSubmitUtils;
+import org.apache.spark.sql.SparkSession;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.junit.jupiter.api.io.TempDir;
+import scala.Option;
+import scala.collection.JavaConverters;
+import scala.collection.Seq;
+import scala.collection.immutable.Nil$;
+
+/** Sanity tests exercising the deployment modes for the polaris-spark client. 
*/
+@QuarkusIntegrationTest
+@ExtendWith(PolarisIntegrationTestExtension.class)
+public class BundleJarSanityIT {
+
+  private static final ObjectMapper MAPPER = new ObjectMapper();
+  private static final String SPARK_MAJOR_VERSION = "3.5";
+
+  @Test
+  void testBundleJarLoading(
+      @TempDir Path tempDir, PolarisApiEndpoints endpoints, ClientCredentials 
credentials)
+      throws Exception {
+    String bundleJar = System.getProperty("polaris.spark.bundle.jar");
+    assertThat(bundleJar).as("polaris.spark.bundle.jar system 
property").isNotBlank();
+    runSparkSqlExercise(
+        tempDir, endpoints, credentials, new URL[] 
{Paths.get(bundleJar).toUri().toURL()});
+  }
+
+  @Test
+  void testPackagesResolution(
+      @TempDir Path tempDir, PolarisApiEndpoints endpoints, ClientCredentials 
credentials)
+      throws Exception {
+    String version = System.getProperty("polaris.version");
+    assertThat(version).as("polaris.version system property").isNotBlank();
+    String scalaversion = System.getProperty("polaris.scala.version");
+    assertThat(version).as("polaris.scala.version system 
property").isNotBlank();
+    String coordinate =
+        String.format(
+            "org.apache.polaris:polaris-spark-%s_%s:%s",
+            SPARK_MAJOR_VERSION, scalaversion, version);
+    URL[] urls = resolveMavenCoordinate(coordinate);
+    runSparkSqlExercise(tempDir, endpoints, credentials, urls);
+  }
+
+  private static void runSparkSqlExercise(
+      Path tempDir, PolarisApiEndpoints endpoints, ClientCredentials 
credentials, URL[] urls)
+      throws Exception {
+    String catalogName = "bundle_test_catalog_" + 
UUID.randomUUID().toString().replace("-", "");
+    String token = obtainToken(endpoints, credentials);
+    String catalogBaseLocation = tempDir.resolve("catalog").toUri().toString();
+    createFileCatalog(endpoints, token, catalogName, catalogBaseLocation);
+    ClassLoader previous = Thread.currentThread().getContextClassLoader();
+    URLClassLoader loader = new URLClassLoader(urls, previous);
+    Thread.currentThread().setContextClassLoader(loader);
+    try (SparkSession spark =
+        SparkSession.builder()
+            .master("local")
+            .config("spark.sql.catalog.polaris", 
"org.apache.polaris.spark.SparkCatalog")
+            .config("spark.sql.catalog.polaris.type", "rest")
+            .config("spark.sql.catalog.polaris.uri", 
endpoints.catalogApiEndpoint().toString())
+            .config("spark.sql.catalog.polaris.warehouse", catalogName)
+            .config("spark.sql.catalog.polaris.token", token)
+            .config("spark.sql.warehouse.dir", 
tempDir.resolve("warehouse").toString())
+            .getOrCreate()) {
+      spark.sql("USE polaris");
+      spark.sql("CREATE NAMESPACE bundle_ns");
+      spark.sql("CREATE TABLE bundle_ns.t (id INT, name STRING) USING 
ICEBERG");
+      spark.sql("INSERT INTO bundle_ns.t VALUES (1, 'a'), (2, 'b')");
+      assertThat(spark.sql("SELECT * FROM bundle_ns.t").count()).isEqualTo(2);
+      spark.sql("DROP TABLE bundle_ns.t");
+      spark.sql("DROP NAMESPACE bundle_ns");
+    } finally {
+      Thread.currentThread().setContextClassLoader(previous);
+      loader.close();
+      deleteCatalog(endpoints, token, catalogName);
+    }
+  }
+
+  /**
+   * Resolves a Maven coordinate to local jar paths via Spark's own Ivy 
machinery — the same code
+   * path that backs {@code spark-submit --packages}. With {@code 
useLocalM2=true}, artifacts
+   * published by {@code publishToMavenLocal} are picked up from {@code 
~/.m2/repository};
+   * transitives not in the local repo (e.g. iceberg-spark-runtime) fall 
through to Maven Central.
+   */
+  @SuppressWarnings({"unchecked", "rawtypes", "deprecation"})
+  private static URL[] resolveMavenCoordinate(String coordinate) throws 
Exception {
+    scala.collection.immutable.Seq<String> emptyExclusions =
+        (scala.collection.immutable.Seq) Nil$.MODULE$;
+    Seq<String> resolved =
+        SparkSubmitUtils.resolveMavenCoordinates(
+            coordinate,
+            SparkSubmitUtils.buildIvySettings(Option.empty(), Option.empty(), 
true),
+            Option.empty(),
+            true,
+            emptyExclusions,
+            false);
+    List<URL> urls = new ArrayList<>();

Review Comment:
   @gh-yzou @flyrain @collado-mike : As I commented on `dev`, if you find value 
in docker-based regtests, we could run then periodically on `main` on a less 
frequent schedule in addition to this new gradle-based IT.
   
   If someone hits an issue with the Polaris Spark Plugin that is missed by 
this test, I'd think we can simply enhance the test to provide better coverage.
   
   That said, from my POV the new test in this PR provides enough coverage for 
Spark sessions ATM.



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