Repository navigation
Refactor BaseTableCRUDTest to split the testing table preparation into a new base class #1153
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
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 |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| package io.unitycatalog.server.base.table; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import io.unitycatalog.client.ApiException; | ||
| import io.unitycatalog.client.model.ColumnInfo; | ||
| import io.unitycatalog.client.model.ColumnTypeName; | ||
| import io.unitycatalog.client.model.CreateCatalog; | ||
| import io.unitycatalog.client.model.CreateSchema; | ||
| import io.unitycatalog.client.model.CreateTable; | ||
| import io.unitycatalog.client.model.DataSourceFormat; | ||
| import io.unitycatalog.client.model.SchemaInfo; | ||
| import io.unitycatalog.client.model.TableInfo; | ||
| import io.unitycatalog.client.model.TableType; | ||
| import io.unitycatalog.server.base.BaseCRUDTest; | ||
| import io.unitycatalog.server.base.ServerConfig; | ||
| import io.unitycatalog.server.base.schema.SchemaOperations; | ||
| import io.unitycatalog.server.utils.TestUtils; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
|
|
||
| /** | ||
| * Abstract base class that provides the test environment setup for table CRUD operations. | ||
| * | ||
| * <p>This class extends {@link BaseCRUDTest} and serves as a foundation for testing table-related | ||
| * operations in Unity Catalog. It's useful for any CRUD test that needs to create test tables. | ||
| */ | ||
| public abstract class BaseTableCRUDTestEnv extends BaseCRUDTest { | ||
|
|
||
| protected SchemaOperations schemaOperations; | ||
| protected TableOperations tableOperations; | ||
| protected String schemaId; | ||
|
|
||
| protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); | ||
|
|
||
| protected abstract TableOperations createTableOperations(ServerConfig serverConfig); | ||
|
|
||
| @BeforeEach | ||
| @Override | ||
| public void setUp() { | ||
| super.setUp(); | ||
| schemaOperations = createSchemaOperations(serverConfig); | ||
| tableOperations = createTableOperations(serverConfig); | ||
| createCommonResources(); | ||
|
Collaborator
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. Do we need to clean those created common resources after each test ?
Collaborator
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. Otherwise, I assume it will conflicts if we create those resources for the next test cases, right ?
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. The entire catalog is deleted by |
||
| } | ||
|
|
||
| private void createCommonResources() { | ||
| CreateCatalog createCatalog = | ||
| new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT); | ||
| try { | ||
| catalogOperations.createCatalog(createCatalog); | ||
| SchemaInfo schemaInfo = | ||
| schemaOperations.createSchema( | ||
| new CreateSchema().name(TestUtils.SCHEMA_NAME).catalogName(TestUtils.CATALOG_NAME)); | ||
| schemaId = schemaInfo.getSchemaId(); | ||
| } catch (ApiException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| protected TableInfo createAndVerifyTable() throws IOException, ApiException { | ||
| TableInfo tableInfo = | ||
| createTestingTable(TestUtils.TABLE_NAME, TestUtils.STORAGE_LOCATION, tableOperations); | ||
| assertThat(tableInfo.getName()).isEqualTo(TestUtils.TABLE_NAME); | ||
| assertThat(tableInfo.getCatalogName()).isEqualTo(TestUtils.CATALOG_NAME); | ||
| assertThat(tableInfo.getSchemaName()).isEqualTo(TestUtils.SCHEMA_NAME); | ||
| assertThat(tableInfo.getTableId()).isNotNull(); | ||
| return tableInfo; | ||
| } | ||
|
|
||
| public static TableInfo createTestingTable( | ||
| String tableName, String storageLocation, TableOperations tableOperations) | ||
| throws IOException, ApiException { | ||
| ColumnInfo columnInfo1 = | ||
| new ColumnInfo() | ||
| .name("as_int") | ||
| .typeText("INTEGER") | ||
| .typeJson("{\"type\": \"integer\"}") | ||
| .typeName(ColumnTypeName.INT) | ||
| .position(0) | ||
| .comment("Integer column") | ||
| .nullable(true); | ||
|
|
||
| ColumnInfo columnInfo2 = | ||
| new ColumnInfo() | ||
| .name("as_string") | ||
| .typeText("VARCHAR(255)") | ||
| .typeJson("{\"type\": \"string\", \"length\": \"255\"}") | ||
| .typeName(ColumnTypeName.STRING) | ||
| .position(1) | ||
| .comment("String column") | ||
| .nullable(true); | ||
|
|
||
| CreateTable createTableRequest = | ||
| new CreateTable() | ||
| .name(tableName) | ||
| .catalogName(TestUtils.CATALOG_NAME) | ||
| .schemaName(TestUtils.SCHEMA_NAME) | ||
| .columns(List.of(columnInfo1, columnInfo2)) | ||
| .properties(TestUtils.PROPERTIES) | ||
| .comment(TestUtils.COMMENT) | ||
| .storageLocation(storageLocation) | ||
| .tableType(TableType.EXTERNAL) | ||
|
Collaborator
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. Since we don't support
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. That's right. This will soon be changed to a parameter by the following PR. |
||
| .dataSourceFormat(DataSourceFormat.DELTA); | ||
|
|
||
| return tableOperations.createTable(createTableRequest); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,7 +73,6 @@ private StagingTableDAO getStagingTable(String tableId) { | |
|
|
||
| @Test | ||
| public void testListTablesWithNoNextPageTokenShouldReturnNull() throws Exception { | ||
| createCommonResources(); | ||
|
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 function is now called inside setUp() for these tests.
Collaborator
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. Sounds good to me. |
||
| TableInfo testingTable = | ||
| createTestingTable(TestUtils.TABLE_NAME, TestUtils.STORAGE_LOCATION, tableOperations); | ||
| ListTablesResponse resp = | ||
|
|
@@ -90,7 +89,6 @@ public void testListTablesWithNoNextPageTokenShouldReturnNull() throws Exception | |
|
|
||
| @Test | ||
| public void testListTablesWithNextPageTokenShouldReturnNextPageToken() throws Exception { | ||
| createCommonResources(); | ||
| List<TableInfo> testingTables = createMultipleTestingTables(11); | ||
| ListTablesResponse resp = | ||
| localTablesApi.listTables( | ||
|
|
@@ -114,7 +112,6 @@ public void testListTablesWithNextPageTokenShouldReturnNextPageToken() throws Ex | |
| */ | ||
| @Test | ||
| public void testStagingTableCreationAndManagedTableFromStagingLocation() throws Exception { | ||
| createCommonResources(); | ||
| String stagingTableName = "staging_test_table"; | ||
|
|
||
| // Step 1: Create a staging table | ||
|
|
@@ -200,8 +197,6 @@ public void testStagingTableCreationAndManagedTableFromStagingLocation() throws | |
| */ | ||
| @Test | ||
| public void testManagedTableCreationFromNonExistentStagingLocationShouldFail() throws Exception { | ||
| createCommonResources(); | ||
|
|
||
| // Use a fake staging location that doesn't exist | ||
| String fakeLocationUuid = "00000000-0000-0000-0000-000000000000"; | ||
| String fakeStagingLocation = "file:///tmp/ucroot/tables/" + fakeLocationUuid; | ||
|
|
@@ -228,8 +223,6 @@ public void testManagedTableCreationFromNonExistentStagingLocationShouldFail() t | |
| /** Test that attempting to create a duplicate staging table fails with ALREADY_EXISTS error. */ | ||
| @Test | ||
| public void testDuplicateStagingTableCreationShouldFail() throws Exception { | ||
| createCommonResources(); | ||
|
|
||
| // Create an external table | ||
| String externalTableName = "duplicate_table"; | ||
| CreateTable createTableRequest = | ||
|
|
@@ -286,8 +279,6 @@ public void testDuplicateStagingTableCreationShouldFail() throws Exception { | |
| */ | ||
| @Test | ||
| public void testMultipleStagingTableCreation() throws Exception { | ||
| createCommonResources(); | ||
|
|
||
| String stagingTable1 = "staging_table_1"; | ||
| String stagingTable2 = "staging_table_2"; | ||
|
|
||
|
|
@@ -315,8 +306,6 @@ public void testMultipleStagingTableCreation() throws Exception { | |
| /** Test that staging table creation fails when the schema doesn't exist. */ | ||
| @Test | ||
| public void testStagingTableCreationWithNonExistentSchemaShouldFail() throws Exception { | ||
| createCommonResources(); | ||
|
|
||
| CreateStagingTable createStagingTableRequest = | ||
| new CreateStagingTable() | ||
| .catalogName(TestUtils.CATALOG_NAME) | ||
|
|
||
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 file is split from BaseTableCRUDTest.java