-
Notifications
You must be signed in to change notification settings - Fork 347
Integration tests: improve support for temporary folders #987
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 1 commit
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 |
|---|---|---|
|
|
@@ -29,6 +29,8 @@ | |
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.reflect.Method; | ||
| import java.net.URI; | ||
| import java.nio.file.Path; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
@@ -92,6 +94,7 @@ | |
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInfo; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.junit.jupiter.api.io.TempDir; | ||
|
|
||
| /** | ||
| * Import the full core Iceberg catalog tests by hitting the REST service via the RESTCatalog | ||
|
|
@@ -108,9 +111,9 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests<RESTCatalog> | |
| private static final String TEST_ROLE_ARN = | ||
| Optional.ofNullable(System.getenv("INTEGRATION_TEST_ROLE_ARN")) | ||
| .orElse("arn:aws:iam::123456789012:role/my-role"); | ||
| private static final String S3_BUCKET_BASE = | ||
| Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH")) | ||
| .orElse("file:///tmp/buckets/my-bucket"); | ||
|
|
||
| private static URI s3BucketBase; | ||
| private static URI externalCatalogBase; | ||
|
|
||
| protected static final String VIEW_QUERY = "select * from ns1.layer1_table"; | ||
| private static String principalRoleName; | ||
|
|
@@ -125,7 +128,7 @@ public class PolarisRestCatalogIntegrationTest extends CatalogTests<RESTCatalog> | |
| private String currentCatalogName; | ||
|
|
||
| private final String catalogBaseLocation = | ||
| S3_BUCKET_BASE + "/" + System.getenv("USER") + "/path/to/data"; | ||
| s3BucketBase + "/" + System.getenv("USER") + "/path/to/data"; | ||
|
|
||
| private static final String[] DEFAULT_CATALOG_PROPERTIES = { | ||
| "allow.unstructured.table.location", "true", | ||
|
|
@@ -148,7 +151,8 @@ String[] properties() default { | |
| } | ||
|
|
||
| @BeforeAll | ||
| static void setup(PolarisApiEndpoints apiEndpoints, ClientCredentials credentials) { | ||
| static void setup( | ||
| PolarisApiEndpoints apiEndpoints, ClientCredentials credentials, @TempDir Path tempDir) { | ||
| adminCredentials = credentials; | ||
| endpoints = apiEndpoints; | ||
| client = polarisClient(endpoints); | ||
|
|
@@ -157,6 +161,20 @@ static void setup(PolarisApiEndpoints apiEndpoints, ClientCredentials credential | |
| principalRoleName = client.newEntityName("rest-admin"); | ||
| principalCredentials = managementApi.createPrincipalWithRole(principalName, principalRoleName); | ||
| catalogApi = client.catalogApi(principalCredentials); | ||
| URI testRootUri = | ||
| Optional.ofNullable(System.getenv("INTEGRATION_TEST_TEMP_DIR")) | ||
| .map(URI::create) | ||
| .orElse(tempDir.toUri()); | ||
| s3BucketBase = | ||
| Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH")) | ||
|
||
| .map(URI::create) | ||
| .orElse(testRootUri) | ||
| .resolve("my-bucket"); | ||
| externalCatalogBase = | ||
| Optional.ofNullable(System.getenv("INTEGRATION_TEST_S3_PATH")) | ||
| .map(URI::create) | ||
| .orElse(testRootUri) | ||
| .resolve("external-catalog"); | ||
| } | ||
|
|
||
| @AfterAll | ||
|
|
@@ -192,7 +210,7 @@ public void before(TestInfo testInfo) { | |
| for (int i = 0; i < properties.length; i += 2) { | ||
| catalogPropsBuilder.addProperty(properties[i], properties[i + 1]); | ||
| } | ||
| if (!S3_BUCKET_BASE.startsWith("file:/")) { | ||
| if (!s3BucketBase.getScheme().equals("file")) { | ||
| catalogPropsBuilder.addProperty( | ||
| CatalogEntity.REPLACE_NEW_LOCATION_PREFIX_WITH_CATALOG_DEFAULT_KEY, "file:"); | ||
| } | ||
|
|
@@ -202,7 +220,7 @@ public void before(TestInfo testInfo) { | |
| .setName(currentCatalogName) | ||
| .setProperties(catalogPropsBuilder.build()) | ||
| .setStorageConfigInfo( | ||
| S3_BUCKET_BASE.startsWith("file:/") | ||
| s3BucketBase.getScheme().equals("file") | ||
| ? new FileStorageConfigInfo( | ||
| StorageConfigInfo.StorageTypeEnum.FILE, List.of("file://")) | ||
| : awsConfigModel) | ||
|
|
@@ -541,12 +559,12 @@ public void testLoadTableWithAccessDelegationForExternalCatalogWithConfigDisable | |
| TableMetadata.newTableMetadata( | ||
| new Schema(List.of(Types.NestedField.of(1, false, "col1", new Types.StringType()))), | ||
| PartitionSpec.unpartitioned(), | ||
| "file:///tmp/ns1/my_table", | ||
| externalCatalogBase + "/ns1/my_table", | ||
| Map.of()); | ||
| try (ResolvingFileIO resolvingFileIO = new ResolvingFileIO()) { | ||
| resolvingFileIO.initialize(Map.of()); | ||
| resolvingFileIO.setConf(new Configuration()); | ||
| String fileLocation = "file:///tmp/ns1/my_table/metadata/v1.metadata.json"; | ||
| String fileLocation = externalCatalogBase + "/ns1/my_table/metadata/v1.metadata.json"; | ||
| TableMetadataParser.write(tableMetadata, resolvingFileIO.newOutputFile(fileLocation)); | ||
| restCatalog.registerTable(TableIdentifier.of(ns1, "my_table"), fileLocation); | ||
| try { | ||
|
|
@@ -576,12 +594,12 @@ public void testLoadTableWithoutAccessDelegationForExternalCatalogWithConfigDisa | |
| TableMetadata.newTableMetadata( | ||
| new Schema(List.of(Types.NestedField.of(1, false, "col1", new Types.StringType()))), | ||
| PartitionSpec.unpartitioned(), | ||
| "file:///tmp/ns1/my_table", | ||
| externalCatalogBase + "/ns1/my_table", | ||
| Map.of()); | ||
| try (ResolvingFileIO resolvingFileIO = new ResolvingFileIO()) { | ||
| resolvingFileIO.initialize(Map.of()); | ||
| resolvingFileIO.setConf(new Configuration()); | ||
| String fileLocation = "file:///tmp/ns1/my_table/metadata/v1.metadata.json"; | ||
| String fileLocation = externalCatalogBase + "/ns1/my_table/metadata/v1.metadata.json"; | ||
| TableMetadataParser.write(tableMetadata, resolvingFileIO.newOutputFile(fileLocation)); | ||
| restCatalog.registerTable(TableIdentifier.of(ns1, "my_table"), fileLocation); | ||
| try { | ||
|
|
@@ -610,12 +628,12 @@ public void testLoadTableWithAccessDelegationForExternalCatalogWithConfigEnabled | |
| TableMetadata.newTableMetadata( | ||
| new Schema(List.of(Types.NestedField.of(1, false, "col1", new Types.StringType()))), | ||
| PartitionSpec.unpartitioned(), | ||
| "file:///tmp/ns1/my_table", | ||
| externalCatalogBase + "/ns1/my_table", | ||
| Map.of()); | ||
| try (ResolvingFileIO resolvingFileIO = new ResolvingFileIO()) { | ||
| resolvingFileIO.initialize(Map.of()); | ||
| resolvingFileIO.setConf(new Configuration()); | ||
| String fileLocation = "file:///tmp/ns1/my_table/metadata/v1.metadata.json"; | ||
| String fileLocation = externalCatalogBase + "/ns1/my_table/metadata/v1.metadata.json"; | ||
| TableMetadataParser.write(tableMetadata, resolvingFileIO.newOutputFile(fileLocation)); | ||
| restCatalog.registerTable(TableIdentifier.of(ns1, "my_table"), fileLocation); | ||
| try { | ||
|
|
||
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.
This may have unexpected behaviour... IIRC
s3://bucket/a/b.resolve("realm/")will yields3://bucket/a/realm/... Did you mean that?It might be best to do a simple string append and then call
URI.normalize().Also, some valid S3 locations do not pass
URIvalidation checks cf. projectnessie/nessie#8328 .... so in the end I think it might be best to stick with string concat until Polaris gets tooling for dealing with S3 locations that are not proper URIs 😅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.
No, of course; the expectation is that
INTEGRATION_TEST_TEMP_DIRmust end with a trailing slash.Yep, let me change that.
I remember the pain, but OTOH I dislike writing stringly-typed code. Do you think the issues we had in Nessie would manifest here? Honestly I expect these URIs to be as simple as
s3://test-bucket, so they should be parsable. And also, as you said, Polaris is not ready yet to handle those problematic S3 locations.Uh oh!
There was an error while loading. Please reload this page.
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.
Good point. I think we can assume that Polaris tests use only well-formed URIs as base locations.