dimas-b commented on code in PR #4588: URL: https://github.com/apache/polaris/pull/4588#discussion_r3338046925
########## plugins/spark/v3.5/integration/src/intTest/java/org/apache/polaris/spark/quarkus/it/BundleSanityChecker.java: ########## @@ -0,0 +1,41 @@ +/* + * 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 org.apache.spark.sql.SparkSession; + +public class BundleSanityChecker { + public static void main(String[] args) { + try (SparkSession spark = SparkSession.builder().getOrCreate()) { + spark.sql("USE polaris"); + spark.sql("CREATE NAMESPACE bundle_ns"); + spark.sql("CREATE TABLE bundle_ns.t (id INT, value STRING) USING ICEBERG"); + spark.sql("INSERT INTO bundle_ns.t VALUES (1, 'a'), (2, 'b')"); + long count = spark.sql("SELECT * FROM bundle_ns.t").count(); + if (count != 2) { + throw new IllegalStateException("Excepted 2 rows, got " + count); Review Comment: I suppose we can still use AssertJ here, WDYT? ########## plugins/spark/v3.5/integration/src/intTest/java/org/apache/polaris/spark/quarkus/it/BundleJarSanityIT.java: ########## @@ -0,0 +1,144 @@ +/* + * 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 org.assertj.core.api.Assertions.assertThat; + +import io.quarkus.test.junit.QuarkusIntegrationTest; +import java.io.BufferedReader; +import java.io.File; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; +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.ManagementApi; +import org.apache.polaris.service.it.env.PolarisApiEndpoints; +import org.apache.polaris.service.it.ext.PolarisIntegrationTestExtension; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; + +@QuarkusIntegrationTest +@ExtendWith(PolarisIntegrationTestExtension.class) +public class BundleJarSanityIT { + + /** + * This test verifies that the Polaris Spark bundle jar can be loaded in a fresh JVM with only + * Spark dependencies, and be able to interact with the Polaris server. + */ + @Test + void testBundleJarLoading( + @TempDir Path tempDir, PolarisApiEndpoints endpoints, ClientCredentials credentials) + throws Exception { + String bundleJarPath = System.getProperty("polaris.spark.bundle.jar"); + assertThat(bundleJarPath) + .withFailMessage("polaris.spark.bundle.jar property not set") + .isNotNull(); + + File bundleJar = new File(bundleJarPath); + assertThat(bundleJar).exists(); + + try (PolarisManagementClient client = PolarisManagementClient.managementClient(endpoints)) { + String catalogName = client.newEntityName("bundle_test_catalog"); + ManagementApi managementApi = client.managementApi(credentials); + + String catalogBaseLocation = tempDir.resolve("catalog").toUri().toString(); + FileStorageConfigInfo storageConfig = + FileStorageConfigInfo.builder() + .setStorageType(StorageConfigInfo.StorageTypeEnum.FILE) + .setAllowedLocations(List.of(catalogBaseLocation)) + .build(); + Catalog catalog = + PolarisCatalog.builder() + .setType(Catalog.TypeEnum.INTERNAL) + .setName(catalogName) + .setProperties(new CatalogProperties(catalogBaseLocation)) + .setStorageConfigInfo(storageConfig) + .build(); + + managementApi.createCatalog(catalog); + try { + runIsolatedSparkCheck( + bundleJar, tempDir, catalogName, endpoints, client.obtainToken(credentials)); + } finally { + managementApi.deleteCatalog(catalogName); + } + } + } + + private void runIsolatedSparkCheck( + File bundleJar, Path tempDir, String catalogName, PolarisApiEndpoints endpoints, String token) + throws Exception { + // Filter the current classpath: drop polaris-spark / polaris-core so the bundle jar + // is the sole source of those classes; keep external jars (spark-sql, iceberg, etc.). + String[] parts = System.getProperty("java.class.path").split(File.pathSeparator); Review Comment: This is a neat idea... yet, I was thinking about using Gradle to build the class path (from test dependencies, without `polaris-*` artifacts) then run `*IT` tests via JUnit. If other classes inside `intTest` need Polaris code, we can create a new test dir (e.g. `sparkTest`) for these new test cases (similar to `cloudTest`). Then we could make a `SparkSession` directly here. I hope the presence of JUnit on the class path is not a concern. WDYT? ########## plugins/spark/v3.5/integration/src/intTest/java/org/apache/polaris/spark/quarkus/it/BundleSanityChecker.java: ########## @@ -0,0 +1,41 @@ +/* + * 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 org.apache.spark.sql.SparkSession; + +public class BundleSanityChecker { + public static void main(String[] args) { + try (SparkSession spark = SparkSession.builder().getOrCreate()) { + spark.sql("USE polaris"); + spark.sql("CREATE NAMESPACE bundle_ns"); + spark.sql("CREATE TABLE bundle_ns.t (id INT, value STRING) USING ICEBERG"); Review Comment: What happens if/when this SQL fails? -- 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]
