Repository navigation
Add real production credential renwal integration test. #1119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5b32ee9
821145b
838b135
ac6a52f
bb6f4f2
ce88557
c532f36
6a9a32c
4f0c265
562c6b5
f2fb395
856254c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ lazy val scala213 = "2.13.16" | |
|
|
||
| lazy val deltaVersion = "4.0.0" | ||
| lazy val sparkVersion = "4.0.0" | ||
| lazy val hadoopVersion = "3.4.0" | ||
|
|
||
| // Library versions | ||
| lazy val jacksonVersion = "2.17.0" | ||
|
|
@@ -503,14 +504,14 @@ lazy val cli = (project in file("examples") / "cli") | |
| "io.delta" % "delta-kernel-api" % deltaVersion, | ||
| "io.delta" % "delta-kernel-defaults" % deltaVersion, | ||
| "io.delta" % "delta-storage" % deltaVersion, | ||
| "org.apache.hadoop" % "hadoop-client-api" % "3.4.0", | ||
| "org.apache.hadoop" % "hadoop-client-runtime" % "3.4.0", | ||
| "org.apache.hadoop" % "hadoop-client-api" % hadoopVersion, | ||
| "org.apache.hadoop" % "hadoop-client-runtime" % hadoopVersion, | ||
| "de.vandermeer" % "asciitable" % "0.3.2", | ||
| // for s3 access | ||
| "org.fusesource.jansi" % "jansi" % "2.4.1", | ||
| "com.amazonaws" % "aws-java-sdk-core" % "1.12.728", | ||
| "org.apache.hadoop" % "hadoop-aws" % "3.4.0", | ||
| "org.apache.hadoop" % "hadoop-azure" % "3.4.0", | ||
| "org.apache.hadoop" % "hadoop-aws" % hadoopVersion, | ||
| "org.apache.hadoop" % "hadoop-azure" % hadoopVersion, | ||
| "com.google.guava" % "guava" % "31.0.1-jre", | ||
| // Test dependencies | ||
| "org.junit.jupiter" % "junit-jupiter" % "5.10.3" % Test, | ||
|
|
@@ -572,7 +573,7 @@ lazy val spark = (project in file("connectors/spark")) | |
| "org.antlr" % "antlr4-runtime" % "4.13.1", | ||
| "org.antlr" % "antlr4" % "4.13.1", | ||
| "com.google.cloud.bigdataoss" % "util-hadoop" % "3.0.2" % Provided, | ||
| "org.apache.hadoop" % "hadoop-azure" % "3.4.0" % Provided, | ||
| "org.apache.hadoop" % "hadoop-azure" % hadoopVersion % Provided, | ||
| "software.amazon.awssdk" % "auth" % "2.25.37" % Provided, | ||
| ), | ||
| libraryDependencies ++= Seq( | ||
|
|
@@ -583,8 +584,8 @@ lazy val spark = (project in file("connectors/spark")) | |
| "org.mockito" % "mockito-inline" % "5.2.0" % Test, | ||
| "org.mockito" % "mockito-junit-jupiter" % "5.12.0" % Test, | ||
| "net.aichler" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test, | ||
| "org.apache.hadoop" % "hadoop-client-runtime" % "3.4.0", | ||
| "org.apache.hadoop" % "hadoop-aws" % "3.4.0" % Test, | ||
| "org.apache.hadoop" % "hadoop-client-runtime" % hadoopVersion, | ||
| "org.apache.hadoop" % "hadoop-aws" % hadoopVersion % Test, | ||
| "io.delta" %% "delta-spark" % deltaVersion % Test, | ||
| ), | ||
| dependencyOverrides ++= Seq( | ||
|
|
@@ -622,6 +623,7 @@ lazy val spark = (project in file("connectors/spark")) | |
|
|
||
| lazy val integrationTests = (project in file("integration-tests")) | ||
| .enablePlugins(CheckstylePlugin) | ||
| .dependsOn(spark) | ||
| .settings( | ||
| name := s"$artifactNamePrefix-integration-tests", | ||
| commonSettings, | ||
|
|
@@ -639,10 +641,9 @@ lazy val integrationTests = (project in file("integration-tests")) | |
| "org.projectlombok" % "lombok" % "1.18.32" % Provided, | ||
| "org.apache.spark" %% "spark-sql" % sparkVersion % Test, | ||
| "io.delta" %% "delta-spark" % deltaVersion % Test, | ||
| "org.apache.hadoop" % "hadoop-aws" % "3.3.6" % Test, | ||
| "org.apache.hadoop" % "hadoop-azure" % "3.3.6" % Test, | ||
| "org.apache.hadoop" % "hadoop-aws" % hadoopVersion % Test, | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this PR, we use the I think I will need a separate PR to address the cross-hadoop version issue. |
||
| "org.apache.hadoop" % "hadoop-azure" % hadoopVersion % Test, | ||
| "com.google.cloud.bigdataoss" % "gcs-connector" % "3.0.2" % Test classifier "shaded", | ||
| "io.unitycatalog" %% "unitycatalog-spark" % "0.2.0" % Test, | ||
| ), | ||
| dependencyOverrides ++= Seq( | ||
| "com.fasterxml.jackson.core" % "jackson-databind" % "2.15.0", | ||
|
|
@@ -652,7 +653,7 @@ lazy val integrationTests = (project in file("integration-tests")) | |
| "com.fasterxml.jackson.dataformat" % "jackson-dataformat-xml" % "2.15.0", | ||
| "org.antlr" % "antlr4-runtime" % "4.13.1", | ||
| "org.antlr" % "antlr4" % "4.13.1", | ||
| "org.apache.hadoop" % "hadoop-client-api" % "3.3.6", | ||
| "org.apache.hadoop" % "hadoop-client-api" % hadoopVersion, | ||
| ), | ||
| Test / javaOptions += s"-Duser.dir=${((ThisBuild / baseDirectory).value / "integration-tests").getAbsolutePath}", | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package io.unitycatalog.integrationtests; | ||
|
|
||
| import static io.unitycatalog.integrationtests.TestUtils.AUTH_TOKEN; | ||
| import static io.unitycatalog.integrationtests.TestUtils.CATALOG_NAME; | ||
| import static io.unitycatalog.integrationtests.TestUtils.S3_BASE_LOCATION; | ||
| import static io.unitycatalog.integrationtests.TestUtils.SERVER_URL; | ||
| import static io.unitycatalog.integrationtests.TestUtils.envAsBoolean; | ||
| import static io.unitycatalog.integrationtests.TestUtils.envAsLong; | ||
| import static io.unitycatalog.integrationtests.TestUtils.randomName; | ||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| import io.unitycatalog.spark.UCSingleCatalog; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import org.apache.spark.api.java.function.MapPartitionsFunction; | ||
| import org.apache.spark.sql.Encoders; | ||
| import org.apache.spark.sql.Row; | ||
| import org.apache.spark.sql.SparkSession; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.sparkproject.guava.collect.Iterators; | ||
|
|
||
| /** | ||
| * Typically, cloud vendor credentials (used to access cloud storage) issued by the UC server expire | ||
| * after one hour. This integration test launches a long-running read-write job whose duration | ||
| * (controlled by the 'CREDENTIAL_RENEWAL_TEST_DURATION_SECONDS' environment variable) exceeds the | ||
| * credential’s expiration time. If the job completes successfully, it verifies that the credential | ||
| * renewal mechanism works as expected, seamlessly refreshing credentials without interrupting the | ||
| * ongoing job. | ||
| * | ||
| * <p> | ||
| * | ||
| * <p><b>To run this tests: </b> | ||
| * | ||
| * <pre> | ||
| * export CATALOG_URI=... | ||
| * export CATALOG_AUTH_TOKEN=... | ||
| * export CATALOG_NAME=... | ||
| * export S3_BASE_LOCATION=... | ||
| * SBT_OPTS="-Xmx8G -XX:+UseG1GC" \ | ||
| * ./build/sbt \ | ||
| * "integrationTests/testOnly io.unitycatalog.integrationtests.SparkCredentialRenewalTest" | ||
| * </pre> | ||
| */ | ||
| public class SparkCredentialRenewalTest { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the credential renewal long-running job. We can run this command to do the integrtation test. env \
CATALOG_URI="$UC_URI" \
CATALOG_AUTH_TOKEN="$UC_TOKEN" \
CATALOG_NAME="main" \
S3_BASE_LOCATION="$UC_S3_LOCATION" \
SBT_OPTS="-Xmx8G -XX:+UseG1GC" \
"$PWD/build/sbt" "integrationTests/testOnly io.unitycatalog.integrationtests.SparkCredentialRenewalTest"
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if we set the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thsi should be in the class docs as instructions on how to run this manually. not in comments.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it's good to add in class docs. Done ! |
||
| private static final String PREFIX = "CREDENTIAL_RENEWAL_TEST_"; | ||
|
|
||
| // Define the CREDENTIAL_RENEWAL_TEST_RENEWAL_ENABLED environment variable. | ||
| private static final boolean RENEW_CRED_ENABLED = envAsBoolean(PREFIX + "RENEWAL_ENABLED", true); | ||
|
|
||
| // Define the CREDENTIAL_RENEWAL_TEST_DURATION_SECONDS environment variable, which control how | ||
| // long will the test run. 90 minutes by default. | ||
| private static final long DURATION_SECONDS = envAsLong(PREFIX + "DURATION_SECONDS", 5600L); | ||
|
|
||
| // Define the schema name and table name. | ||
| private static final String SCHEMA_NAME = randomName(); | ||
| private static final String SRC_TABLE = | ||
| String.format("%s.%s.src_%s", CATALOG_NAME, SCHEMA_NAME, randomName()); | ||
| private static final String DST_TABLE = | ||
| String.format("%s.%s.dst_%s", CATALOG_NAME, SCHEMA_NAME, randomName()); | ||
|
|
||
| private static SparkSession spark; | ||
|
|
||
| @BeforeAll | ||
| public static void beforeAll() { | ||
| String testCatalogKey = String.format("spark.sql.catalog.%s", CATALOG_NAME); | ||
| spark = | ||
| SparkSession.builder() | ||
| .appName("test-credential-renewal-in-long-running-job") | ||
| .master("local[1]") // Make it single-threaded explicitly. | ||
| .config("spark.hadoop.fs.s3.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem") | ||
| .config("spark.sql.extensions", "io.delta.sql.DeltaSparkSessionExtension") | ||
| .config( | ||
| "spark.sql.catalog.spark_catalog", | ||
| "org.apache.spark.sql.delta.catalog.DeltaCatalog") | ||
| .config(testCatalogKey, UCSingleCatalog.class.getName()) | ||
| .config(testCatalogKey + ".uri", SERVER_URL) | ||
| .config(testCatalogKey + ".token", AUTH_TOKEN) | ||
| .config(testCatalogKey + ".warehouse", CATALOG_NAME) | ||
| .config(testCatalogKey + ".renewCredential.enabled", String.valueOf(RENEW_CRED_ENABLED)) | ||
| .getOrCreate(); | ||
|
|
||
| sql("CREATE SCHEMA %s.%s", CATALOG_NAME, SCHEMA_NAME); | ||
| sql( | ||
| "CREATE TABLE %s (id INT) USING delta LOCATION '%s/%s' PARTITIONED BY (partition INT)", | ||
| SRC_TABLE, S3_BASE_LOCATION, UUID.randomUUID()); | ||
| sql( | ||
| "CREATE TABLE %s (id INT) USING delta LOCATION '%s/%s'", | ||
| DST_TABLE, S3_BASE_LOCATION, UUID.randomUUID()); | ||
| } | ||
|
|
||
| @AfterAll | ||
| public static void afterAll() { | ||
| sql("DROP TABLE IF EXISTS %s", SRC_TABLE); | ||
| sql("DROP TABLE IF EXISTS %s", DST_TABLE); | ||
| sql("DROP SCHEMA IF EXISTS %s.%s", CATALOG_NAME, SCHEMA_NAME); | ||
| spark.stop(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLongRunningJob() { | ||
| // Every 100 seconds produce a row, because we don't want to produce massive small files. | ||
| long rowCount = DURATION_SECONDS / 100 + (DURATION_SECONDS % 100 == 0 ? 0 : 1); | ||
|
|
||
| // Generate data for the delta source table. | ||
| sql("INSERT INTO %s SELECT id, id FROM range(0, %s)", SRC_TABLE, rowCount); | ||
|
|
||
| // Read from the Delta source table, mapping each partition to a separate task, and finally | ||
| // write back to the destination table. With parallelism set to 1, tasks for each partition | ||
| // execute sequentially. Every partition task will sleep 100 seconds, and the accumulated | ||
| // elapsed time will finally trigger the renewal of credentials. | ||
|
|
||
| // The spark job should be success because we've enabled the credential renewal. | ||
| spark | ||
| .read() | ||
| .format("delta") | ||
| .table(SRC_TABLE) | ||
| .mapPartitions( | ||
| (MapPartitionsFunction<Row, Integer>) | ||
| input -> { | ||
| Thread.sleep(100 * 1000L); | ||
| return Iterators.transform(input, row -> row.getInt(0)); | ||
| }, | ||
| Encoders.INT()) | ||
| .withColumnRenamed("value", "id") | ||
| .write() | ||
| .format("delta") | ||
| .mode("append") | ||
| .saveAsTable(DST_TABLE); | ||
|
|
||
| List<Row> results = sql("SELECT COUNT(*) FROM %s", DST_TABLE); | ||
| assertThat(results.size()).isEqualTo(1); | ||
| assertThat(results.get(0).getLong(0)).isEqualTo(rowCount); | ||
| } | ||
|
|
||
| private static List<Row> sql(String statement, Object... args) { | ||
| return spark.sql(String.format(statement, args)).collectAsList(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package io.unitycatalog.integrationtests; | ||
|
|
||
| import org.apache.commons.lang3.RandomStringUtils; | ||
|
|
||
| public class TestUtils { | ||
| public static final String SERVER_URL = envAsString("CATALOG_URI", "http://localhost:8080"); | ||
| public static final String AUTH_TOKEN = envAsString("CATALOG_AUTH_TOKEN", ""); | ||
| public static final String CATALOG_NAME = envAsString("CATALOG_NAME", "unity"); | ||
| public static final String S3_BASE_LOCATION = envAsString("S3_BASE_LOCATION", "s3://bucket/key"); | ||
| public static final String GS_BASE_LOCATION = envAsString("GS_BASE_LOCATION", "gs://bucket/key"); | ||
| public static final String ABFSS_BASE_LOCATION = | ||
| envAsString("ABFSS_BASE_LOCATION", "abfss://bucket/key"); | ||
|
|
||
| public static String envAsString(String key, String defaultValue) { | ||
| return System.getenv().getOrDefault(key, defaultValue); | ||
| } | ||
|
|
||
| public static long envAsLong(String key, long defaultValue) { | ||
| String value = System.getenv().get(key); | ||
| return value == null ? defaultValue : Long.parseLong(value); | ||
| } | ||
|
|
||
| public static boolean envAsBoolean(String key, boolean defaultValue) { | ||
| String value = System.getenv().get(key); | ||
| return value == null ? defaultValue : Boolean.parseBoolean(value); | ||
| } | ||
|
|
||
| public static String randomName() { | ||
| return RandomStringUtils.secure().nextAlphabetic(8); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will be better to use the cross module depending here than configured the static
io.unitycatalog:unitycatalog-sparkhere. https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-5634c415cd8c8504fdb973a3ed092300b43c4b8fc1e184f7249eb29a55511f91L645Since for the later one, we need to manually publish the
unitycatalog-sparkinto local maven repo, which will makes theintegrationTestsmore hard to run.With the former one, if we make any changes in the
unitycatalog-sparkconnector, then we can simply use the command./build/sbt integrationTests/testto run theintegrationTestswithout publishing.