Migrate AWS tests to JUnit5#10086
Conversation
| AwsClientFactory factory = AwsClientFactories.from(properties); | ||
| GlueClient glueClient = factory.glue(); | ||
| Assertions.assertThatThrownBy( | ||
| assertThatThrownBy( |
There was a problem hiding this comment.
Can't we avoid these cleanups with this PR? IMO, this PR should have only Migration from Junit4 to Junit5 . WDYT?
There was a problem hiding this comment.
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 .
|
@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())); |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
rather than using fail with a try-catch, it's better to have something like assertThatNoException().isThrownBy(() -> glueCatalog.createNamespace(allowedNamespace))
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
nit: Just wondering why cast to asString() here ? Other Object comparison we are doing using isEqualTo
There was a problem hiding this comment.
It's necessary because the testing the comparisons between objects fail.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
As commented above, it's necessary because the testing the comparisons between objects fail.
3ae68a2 to
3f88d69
Compare
Migrate AWS integration tests to JUnit 5 for #9080
All tests in
iceberg-aws/testalready use JUnit5 and AssertJ.The following integration tests need to be migrated.
iceberg-aws/integration/java/org.apache.iceberg.aws/:dynamodb/TestDynamoDbCatalogTestDynamoDbLockManagerglue/GlueTestBaseTestGlueCatalogCommitFailureTestGlueCatalogLockTestGlueCatalogNamespaceTestGlueCatalogTablelakeformation/LakeFormationTestBaseTestLakeFormationAwsClientFactoryTestLakeFormationDataOperationsTestLakeFormationMetadataOperationss3/S3TestUtil(not a test file)TestS3FileIOIntegrationTestS3MultipartUploadAwsIntegTestUtil(not a test file)TestAssumeRoleAwsClientFactoryTestDefaultAwsClientFactory