Skip to content

Migrate AWS tests to JUnit5#10086

Merged
nastra merged 6 commits into
apache:mainfrom
tomtongue:mig-junit5-aws
Apr 8, 2024
Merged

Migrate AWS tests to JUnit5#10086
nastra merged 6 commits into
apache:mainfrom
tomtongue:mig-junit5-aws

Conversation

@tomtongue
Copy link
Copy Markdown
Contributor

@tomtongue tomtongue commented Apr 4, 2024

Migrate AWS integration tests to JUnit 5 for #9080

All tests in iceberg-aws/test already use JUnit5 and AssertJ.

The following integration tests need to be migrated.

iceberg-aws/integration/java/org.apache.iceberg.aws/:

  • dynamodb/
    • TestDynamoDbCatalog
    • TestDynamoDbLockManager
  • glue/
    • GlueTestBase
    • TestGlueCatalogCommitFailure
    • TestGlueCatalogLock
    • TestGlueCatalogNamespace
    • TestGlueCatalogTable
  • lakeformation/
    • LakeFormationTestBase
    • TestLakeFormationAwsClientFactory
    • TestLakeFormationDataOperations
    • TestLakeFormationMetadataOperations
  • s3/
    • S3TestUtil (not a test file)
    • TestS3FileIOIntegration
    • TestS3MultipartUpload
  • AwsIntegTestUtil (not a test file)
  • TestAssumeRoleAwsClientFactory
  • TestDefaultAwsClientFactory

@github-actions github-actions Bot added the INFRA label Apr 4, 2024
@tomtongue tomtongue changed the title [WIP] Migrate AWS tests Migrate AWS tests Apr 6, 2024
@tomtongue tomtongue changed the title Migrate AWS tests Migrate AWS tests to JUnit5 Apr 6, 2024
AwsClientFactory factory = AwsClientFactories.from(properties);
GlueClient glueClient = factory.glue();
Assertions.assertThatThrownBy(
assertThatThrownBy(
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.

Can't we avoid these cleanups with this PR? IMO, this PR should have only Migration from Junit4 to Junit5 . WDYT?

Copy link
Copy Markdown
Contributor Author

@tomtongue tomtongue Apr 8, 2024

Choose a reason for hiding this comment

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

I believe the changes for removing Assertion are very small in this package, and by the changes, it can avoid the situation that two methods like Assertions.assertThat and assertThat exist in a same file. So it won't be a big problem. If there's any reason to keep Assertions, please let me know.
Iceberg contribute guide also shows the tests without Assertions .

@tomtongue
Copy link
Copy Markdown
Contributor Author

@nastra All AWS classes are migrated to JUnit5 + AssertJ. Could you review this PR?

.as("namespace must be stored in DynamoDB")
.hasEntrySatisfying(
"namespace",
attributeValue -> assertThat(attributeValue.s()).isEqualTo(namespace.toString()));
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.

for a single key match what about simple assertion like

assertThat(response.item().get("namespace").s()).as("namespace must be stored in DynamoDB").isEqualTo(namespace.toString());

For multiple keys validation it looks good to use hasEntrySatisfying. WDYT ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion. I think your suggestion seems to be fine, but my change also checks if response.item has namespace or not. But if the value extraction byget("namespace"), it doesn't check in the test. So if this part is like your suggestion, it's better to write like:

assertThat(response.item()).containsKey("namespace")
assertThat(response.item().get("namespace").s())...

That's why I'm using hasEntrySatisfying here. If I'm wrong here, please correct me.

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.

Makes sense, I think hasEntrySatisfying sounds good as per the above reasons.

LOG.error("fail to create Glue database", e);
Assert.fail("create namespace should succeed");

fail("create namespace should succeed");
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.

rather than using fail with a try-catch, it's better to have something like assertThatNoException().isThrownBy(() -> glueCatalog.createNamespace(allowedNamespace))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Will update this line.

.containsKey(BaseMetastoreTableOperations.METADATA_LOCATION_PROP);
assertThat(response.table().storageDescriptor().columns()).hasSameSizeAs(schema.columns());
assertThat(response.table().partitionKeys()).hasSameSizeAs(partitionSpec.fields());
assertThat(response.table().storageDescriptor().additionalLocations())
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.

previously the assertion was happening after sorting the values. Do you think it can become flaky someday?
Why not somethng like
assertThat(response.table().storageDescriptor().additionalLocations()).containsAll(tableLocationProperties.values());

Copy link
Copy Markdown
Contributor Author

@tomtongue tomtongue Apr 8, 2024

Choose a reason for hiding this comment

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

thanks for the suggestion. I think the suggestion drops the sorting check. So this uses isEqualTo and it's not flaky.

Assert.assertEquals(table.spec(), renamedTable.spec());
Assert.assertEquals(table.currentSnapshot(), renamedTable.currentSnapshot());
assertThat(renamedTable.location()).isEqualTo(table.location());
assertThat(renamedTable.schema()).asString().isEqualTo(table.schema().toString());
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.

nit: Just wondering why cast to asString() here ? Other Object comparison we are doing using isEqualTo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's necessary because the testing the comparisons between objects fail.

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.

Yeah Just wondering , Why PartiotionSpec and Snapshot comparison are working.
As per my understanding isEqualTo compares object values. So ideally it should not fail unless I am missing 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.

it's because Schema doesn't implement equals()

Assert.assertEquals(table.spec(), oldTable.spec());
Assert.assertEquals(table.currentSnapshot(), oldTable.currentSnapshot());
assertThat(oldTable.location()).isEqualTo(table.location());
assertThat(oldTable.schema()).asString().isEqualTo(table.schema().toString());
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.

same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As commented above, it's necessary because the testing the comparisons between objects fail.

@nastra nastra merged commit b3261d0 into apache:main Apr 8, 2024
@tomtongue tomtongue deleted the mig-junit5-aws branch April 8, 2024 11:04
sasankpagolu pushed a commit to sasankpagolu/iceberg that referenced this pull request Oct 27, 2024
zachdisc pushed a commit to zachdisc/iceberg that referenced this pull request Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants