Skip to content

Add real production credential renwal integration test. - #1119

Merged
tdas merged 12 commits into
unitycatalog:mainfrom
openinx:1092-s3-real-integration-test
Nov 5, 2025
Merged

tdas merged 12 commits into
unitycatalog:mainfrom
openinx:1092-s3-real-integration-test

Conversation

@openinx

@openinx openinx commented Oct 20, 2025

Copy link
Copy Markdown
Collaborator

PR Checklist

  • A description of the changes is added to the description of this PR.
  • If there is a related issue, make sure it is linked to this PR.
  • If you've fixed a bug or added code that should be tested, add tests!
  • If you've added or modified a feature, documentation in docs is updated

Description of changes

For this issue, #1092. Since the credential may be expired for 30minutes, so in this PR, I designed a streaming job which will redirect the stream into the designated table in 40 min. And if all the rows are correct, and the streaming job is not been broken, then the credential renewal should be fine.

@openinx openinx changed the title 1092 s3 real integration test Add Credential renwal real integration test. Oct 20, 2025
@openinx
openinx marked this pull request as draft October 20, 2025 04:42
@openinx openinx changed the title Add Credential renwal real integration test. Add real production credential renwal integration test. Oct 20, 2025
@openinx
openinx force-pushed the 1092-s3-real-integration-test branch from 5024288 to e4b4df1 Compare October 30, 2025 19:01
@openinx
openinx marked this pull request as ready for review October 31, 2025 04:04
@openinx
openinx force-pushed the 1092-s3-real-integration-test branch from d34ac0a to 8bb0845 Compare October 31, 2025 04:04
* credential renewal mechanism works as expected, seamlessly refreshing credentials without
* interrupting the ongoing job.
*/
public class SparkCredentialRenewalTest {

@openinx openinx Oct 31, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we set the CREDENTIAL_RENEWAL_TEST_RENEWAL_ENABLED=false in this test, then the job will be failure.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The 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 boolean RENEW_CRED_ENABLED = envBoolean(PREFIX + "RENEWAL_ENABLED", true);

// Define the CREDENTIAL_RENEWAL_TEST_ROW_COUNT environment variable.
private static final long ROW_COUNT = envLong(PREFIX + "ROW_COUNT", 10_000_000_000L);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set this to 10^10, the test will be running for 1.5 hours, which trigger several rounds of the credential renewal.

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single-thread, make it run slowly, without exhausting the host's CPU resources.


@Test
public void testLongRunningJob() {
sql("INSERT INTO %s SELECT id, CONCAT('val_', id) AS val FROM range(0, %s)",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The whole job is a simple writing job.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt we test both reads and writes?
basically.. why not follow the exactly strategy that you used in the earlier PR we merged?
you just have create multiple files in the same way, it will test both reads, writes, multiple tables, etcl.
the only thing you need to change is instead of manual clock advance.. you can simply Thread.sleep(1000).
by default it can be 1 files with 1 rows that runs in 1 second. then the setting simply becomes how many seconds do you want the code to run

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done !

Comment thread build.sbt
"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,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR, we use the hadoop 3.3.6 to run the integration tests by default. while actually, I encountered a serious issue here #1092 (comment).

I think I will need a separate PR to address the cross-hadoop version issue.

@openinx openinx closed this Oct 31, 2025
@openinx openinx reopened this Oct 31, 2025
.config(testCatalogKey + ".renewCredential.enabled", String.valueOf(RENEW_CRED_ENABLED))
.getOrCreate();

sql("CREATE SCHEMA %s", SCHEMA_NAME);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will fail if the schema exists.. right? might not be the behavior we want when we point to a different UC.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Yes it will fail. I think it's better to use a random schema name, rather than the specified name via environment, otherwise it's hard for us to determine if we need to drop it or not.

By using the random schema, we can just create our own and after the test just drop it.

import org.junit.jupiter.api.Test;

/**
* Typically, cloud vendor credentials (used to access cloud storage) issued by the UC server

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test.. by default runs very fast (as it should as its always enabled) and so it really does not test anything by default... right?

only when you manually configure it to run for long it tests something.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is important context that needs to be written down.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, we use the row count as 10^10 (https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-a961fbeeb181232588b1a8b7657dff464d114c46faf6b4fd355903115601efe5R54), so it will take roughly 2 hours to finish all the tests. While if people want to do some initial testing to be confident that everything for the testing environment and configuration is fine, then it will be better to specifty the environment variable CREDENTIAL_RENEWAL_TEST_ROW_COUNT to smaller number, such as 10.

Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
@openinx
openinx force-pushed the 1092-s3-real-integration-test branch from 1e5bc9a to 4f0c265 Compare November 5, 2025 00:42
Comment thread build.sbt

lazy val integrationTests = (project in file("integration-tests"))
.enablePlugins(CheckstylePlugin)
.dependsOn(spark)

Copy link
Copy Markdown
Collaborator Author

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-spark here. https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-5634c415cd8c8504fdb973a3ed092300b43c4b8fc1e184f7249eb29a55511f91L645

Since for the later one, we need to manually publish the unitycatalog-spark into local maven repo, which will makes the integrationTests more hard to run.

With the former one, if we make any changes in the unitycatalog-spark connector, then we can simply use the command ./build/sbt integrationTests/test to run the integrationTests without publishing.

Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
* credential renewal mechanism works as expected, seamlessly refreshing credentials without
* interrupting the ongoing job.
*/
public class SparkCredentialRenewalTest {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's good to add in class docs. Done !

.config(testCatalogKey + ".renewCredential.enabled", String.valueOf(RENEW_CRED_ENABLED))
.getOrCreate();

sql("CREATE SCHEMA %s", SCHEMA_NAME);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Yes it will fail. I think it's better to use a random schema name, rather than the specified name via environment, otherwise it's hard for us to determine if we need to drop it or not.

By using the random schema, we can just create our own and after the test just drop it.

@AfterAll
public static void afterAll() {
sql("DROP TABLE IF EXISTS %s", TABLE_NAME);
sql("DROP SCHEMA IF EXISTS %s", SCHEMA_NAME);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related to this comment

import org.junit.jupiter.api.Test;

/**
* Typically, cloud vendor credentials (used to access cloud storage) issued by the UC server

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, we use the row count as 10^10 (https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-a961fbeeb181232588b1a8b7657dff464d114c46faf6b4fd355903115601efe5R54), so it will take roughly 2 hours to finish all the tests. While if people want to do some initial testing to be confident that everything for the testing environment and configuration is fine, then it will be better to specifty the environment variable CREDENTIAL_RENEWAL_TEST_ROW_COUNT to smaller number, such as 10.


@Test
public void testLongRunningJob() {
sql("INSERT INTO %s SELECT id, CONCAT('val_', id) AS val FROM range(0, %s)",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done !

@tdas tdas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@tdas
tdas merged commit 4945bd8 into unitycatalog:main Nov 5, 2025
openinx added a commit to openinx/unitycatalog that referenced this pull request Nov 13, 2025
…atalog#1119)

**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [x] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

For this issue,
unitycatalog#1092. Since the
credential may be expired for 30minutes, so in this PR, I designed a
streaming job which will redirect the stream into the designated table
in 40 min. And if all the rows are correct, and the streaming job is not
been broken, then the credential renewal should be fine.

---------

Signed-off-by: Zheng Hu <[email protected]>
tdas pushed a commit that referenced this pull request Nov 13, 2025
**PR Checklist**

- [x] A description of the changes is added to the description of this
PR.
- [x] If there is a related issue, make sure it is linked to this PR.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [ ] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

Backport the #1119 to the branch-0.3 . 
The whole backport progress is here:
#1163

Signed-off-by: Zheng Hu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants