diff --git a/server/src/test/java/io/unitycatalog/server/base/BaseCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/BaseCRUDTest.java index 230c989aa..28a1d8a92 100644 --- a/server/src/test/java/io/unitycatalog/server/base/BaseCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/BaseCRUDTest.java @@ -1,41 +1,40 @@ package io.unitycatalog.server.base; +import static io.unitycatalog.server.utils.TestUtils.CATALOG_NAME; +import static io.unitycatalog.server.utils.TestUtils.CATALOG_NEW_NAME; + import io.unitycatalog.server.base.catalog.CatalogOperations; +import java.util.Optional; import org.junit.After; import org.junit.Before; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.Optional; - -import static io.unitycatalog.server.utils.TestUtils.CATALOG_NAME; -import static io.unitycatalog.server.utils.TestUtils.CATALOG_NEW_NAME; - @RunWith(Parameterized.class) public abstract class BaseCRUDTest extends BaseServerTest { - protected CatalogOperations catalogOperations; + protected CatalogOperations catalogOperations; - @After - public void cleanUp() { - try { - catalogOperations.deleteCatalog(CATALOG_NAME, Optional.of(true)); - } catch (Exception e) { - // Ignore - } - try { - catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(true)); - } catch (Exception e) { - // Ignore - } + @After + public void cleanUp() { + try { + catalogOperations.deleteCatalog(CATALOG_NAME, Optional.of(true)); + } catch (Exception e) { + // Ignore } - - @Before - @Override - public void setUp() { - super.setUp(); - catalogOperations = createCatalogOperations(serverConfig); + try { + catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(true)); + } catch (Exception e) { + // Ignore } + } + + @Before + @Override + public void setUp() { + super.setUp(); + catalogOperations = createCatalogOperations(serverConfig); + } - protected abstract CatalogOperations createCatalogOperations(ServerConfig serverConfig); + protected abstract CatalogOperations createCatalogOperations(ServerConfig serverConfig); } diff --git a/server/src/test/java/io/unitycatalog/server/base/BaseServerTest.java b/server/src/test/java/io/unitycatalog/server/base/BaseServerTest.java index 37e11380a..501f959b0 100644 --- a/server/src/test/java/io/unitycatalog/server/base/BaseServerTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/BaseServerTest.java @@ -1,64 +1,58 @@ package io.unitycatalog.server.base; -import java.util.Collection; -import java.util.List; - import io.unitycatalog.server.UnityCatalogServer; import io.unitycatalog.server.utils.TestUtils; +import java.util.Collection; +import java.util.List; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @RunWith(Parameterized.class) public abstract class BaseServerTest { - @Parameterized.Parameter - public static ServerConfig serverConfig; - private static UnityCatalogServer unityCatalogServer; + @Parameterized.Parameter public static ServerConfig serverConfig; + private static UnityCatalogServer unityCatalogServer; - /** - * To test against UC server, add - * UC server endpoint as server URL and PAT token as auth token - * e.g. ServerConfig("https://", "") - * Multiple server configurations can be added to test against multiple servers - * @return - */ - @Parameterized.Parameters - public static Collection data() { - return List.of( - new ServerConfig("http://localhost", "") - ); - } + /** + * To test against UC server, add UC server endpoint as server URL and PAT token as auth token + * e.g. ServerConfig("https://", "") Multiple server configurations can be + * added to test against multiple servers + * + * @return + */ + @Parameterized.Parameters + public static Collection data() { + return List.of(new ServerConfig("http://localhost", "")); + } - @Before - public void setUp() { - if (serverConfig == null) { - throw new IllegalArgumentException("Server config is required"); - } - if (serverConfig.getServerUrl() == null) { - throw new IllegalArgumentException("Server URL is required"); - } - if (serverConfig.getAuthToken() == null) { - throw new IllegalArgumentException("Auth token is required"); - } - if (serverConfig.getServerUrl().contains("localhost")) { - System.out.println("Running tests on localhost.."); - // start the server on a random port - int port = TestUtils.getRandomPort(); - System.setProperty("server.env", "test"); - unityCatalogServer = new UnityCatalogServer(port); - unityCatalogServer.start(); - serverConfig.setServerUrl("http://localhost:" + port); - } + @Before + public void setUp() { + if (serverConfig == null) { + throw new IllegalArgumentException("Server config is required"); + } + if (serverConfig.getServerUrl() == null) { + throw new IllegalArgumentException("Server URL is required"); + } + if (serverConfig.getAuthToken() == null) { + throw new IllegalArgumentException("Auth token is required"); + } + if (serverConfig.getServerUrl().contains("localhost")) { + System.out.println("Running tests on localhost.."); + // start the server on a random port + int port = TestUtils.getRandomPort(); + System.setProperty("server.env", "test"); + unityCatalogServer = new UnityCatalogServer(port); + unityCatalogServer.start(); + serverConfig.setServerUrl("http://localhost:" + port); } + } - @After - public void tearDown() { - if (unityCatalogServer != null) { - unityCatalogServer.stop(); - } + @After + public void tearDown() { + if (unityCatalogServer != null) { + unityCatalogServer.stop(); } + } } diff --git a/server/src/test/java/io/unitycatalog/server/base/ServerConfig.java b/server/src/test/java/io/unitycatalog/server/base/ServerConfig.java index 0e72810d6..9cfeae357 100644 --- a/server/src/test/java/io/unitycatalog/server/base/ServerConfig.java +++ b/server/src/test/java/io/unitycatalog/server/base/ServerConfig.java @@ -6,11 +6,11 @@ @Getter @Setter public class ServerConfig { - private String serverUrl; - private String authToken; + private String serverUrl; + private String authToken; - public ServerConfig(String serverUrl, String authToken) { - this.serverUrl = serverUrl; - this.authToken = authToken; - } -} \ No newline at end of file + public ServerConfig(String serverUrl, String authToken) { + this.serverUrl = serverUrl; + this.authToken = authToken; + } +} diff --git a/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java index 449ad8114..856337b97 100644 --- a/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/catalog/BaseCatalogCRUDTest.java @@ -1,85 +1,83 @@ package io.unitycatalog.server.base.catalog; +import static io.unitycatalog.server.utils.TestUtils.*; + import io.unitycatalog.client.ApiException; +import io.unitycatalog.client.model.CatalogInfo; import io.unitycatalog.client.model.CreateCatalog; import io.unitycatalog.client.model.UpdateCatalog; import io.unitycatalog.server.base.BaseCRUDTest; -import io.unitycatalog.server.persist.PropertyRepository; -import org.junit.*; - -import io.unitycatalog.client.model.CatalogInfo; - import java.util.List; import java.util.Objects; import java.util.Optional; - -import static io.unitycatalog.server.utils.TestUtils.*; +import org.junit.*; public abstract class BaseCatalogCRUDTest extends BaseCRUDTest { - protected void assertCatalog(CatalogInfo catalogInfo, String name, String comment) { - Assert.assertEquals(name, catalogInfo.getName()); - Assert.assertEquals(comment, catalogInfo.getComment()); - Assert.assertNotNull(catalogInfo.getCreatedAt()); - // TODO: Also assert properties once CLI supports it - } + protected void assertCatalog(CatalogInfo catalogInfo, String name, String comment) { + Assert.assertEquals(name, catalogInfo.getName()); + Assert.assertEquals(comment, catalogInfo.getComment()); + Assert.assertNotNull(catalogInfo.getCreatedAt()); + // TODO: Also assert properties once CLI supports it + } - protected void assertCatalogExists(List catalogList, String name, String comment) { - Assert.assertTrue(catalogList.stream().anyMatch(c -> - Objects.equals(c.getName(), name) && Objects.equals(c.getComment(), comment))); - } + protected void assertCatalogExists(List catalogList, String name, String comment) { + Assert.assertTrue( + catalogList.stream() + .anyMatch( + c -> Objects.equals(c.getName(), name) && Objects.equals(c.getComment(), comment))); + } - protected void assertCatalogNotExists(List catalogList, String name) { - Assert.assertFalse(catalogList.stream().anyMatch(c -> - Objects.equals(c.getName(), name))); - } + protected void assertCatalogNotExists(List catalogList, String name) { + Assert.assertFalse(catalogList.stream().anyMatch(c -> Objects.equals(c.getName(), name))); + } - @Test - public void testCatalogCRUD() throws ApiException { - // Create a catalog - System.out.println("Testing create catalog.."); - CreateCatalog createCatalog = new CreateCatalog() - .name(CATALOG_NAME) - .comment(COMMENT) - .properties(PROPERTIES); - CatalogInfo catalogInfo = catalogOperations.createCatalog(createCatalog); - assertCatalog(catalogInfo, CATALOG_NAME, COMMENT); + @Test + public void testCatalogCRUD() throws ApiException { + // Create a catalog + System.out.println("Testing create catalog.."); + CreateCatalog createCatalog = + new CreateCatalog().name(CATALOG_NAME).comment(COMMENT).properties(PROPERTIES); + CatalogInfo catalogInfo = catalogOperations.createCatalog(createCatalog); + assertCatalog(catalogInfo, CATALOG_NAME, COMMENT); - // List catalogs - System.out.println("Testing list catalogs.."); - List catalogList = catalogOperations.listCatalogs(); - Assert.assertNotNull(catalogList); - assertCatalogExists(catalogList, CATALOG_NAME, COMMENT); + // List catalogs + System.out.println("Testing list catalogs.."); + List catalogList = catalogOperations.listCatalogs(); + Assert.assertNotNull(catalogList); + assertCatalogExists(catalogList, CATALOG_NAME, COMMENT); - // Get catalog - System.out.println("Testing get catalog.."); - CatalogInfo catalogInfo2 = catalogOperations.getCatalog(CATALOG_NAME); - Assert.assertEquals(catalogInfo, catalogInfo2); + // Get catalog + System.out.println("Testing get catalog.."); + CatalogInfo catalogInfo2 = catalogOperations.getCatalog(CATALOG_NAME); + Assert.assertEquals(catalogInfo, catalogInfo2); - // Calling update catalog with nothing to update should not change anything - System.out.println("Testing updating catalog with nothing to update.."); - UpdateCatalog emptyUpdateCatalog = new UpdateCatalog(); - CatalogInfo emptyUpdateCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, emptyUpdateCatalog); - CatalogInfo catalogInfo3 = catalogOperations.getCatalog(CATALOG_NAME); - Assert.assertEquals(catalogInfo, catalogInfo3); + // Calling update catalog with nothing to update should not change anything + System.out.println("Testing updating catalog with nothing to update.."); + UpdateCatalog emptyUpdateCatalog = new UpdateCatalog(); + CatalogInfo emptyUpdateCatalogInfo = + catalogOperations.updateCatalog(CATALOG_NAME, emptyUpdateCatalog); + CatalogInfo catalogInfo3 = catalogOperations.getCatalog(CATALOG_NAME); + Assert.assertEquals(catalogInfo, catalogInfo3); - // Update catalog name without updating comment - System.out.println("Testing update catalog: changing name.."); - UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); - CatalogInfo updatedCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); - assertCatalog(updatedCatalogInfo, CATALOG_NEW_NAME, COMMENT); + // Update catalog name without updating comment + System.out.println("Testing update catalog: changing name.."); + UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); + CatalogInfo updatedCatalogInfo = catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); + assertCatalog(updatedCatalogInfo, CATALOG_NEW_NAME, COMMENT); - // Update catalog comment without updating name - System.out.println("Testing update catalog: changing comment.."); - UpdateCatalog updateCatalog2 = new UpdateCatalog().comment(CATALOG_NEW_COMMENT); - CatalogInfo updatedCatalogInfo2 = catalogOperations.updateCatalog(CATALOG_NEW_NAME, updateCatalog2); - assertCatalog(updatedCatalogInfo2, CATALOG_NEW_NAME, CATALOG_NEW_COMMENT); + // Update catalog comment without updating name + System.out.println("Testing update catalog: changing comment.."); + UpdateCatalog updateCatalog2 = new UpdateCatalog().comment(CATALOG_NEW_COMMENT); + CatalogInfo updatedCatalogInfo2 = + catalogOperations.updateCatalog(CATALOG_NEW_NAME, updateCatalog2); + assertCatalog(updatedCatalogInfo2, CATALOG_NEW_NAME, CATALOG_NEW_COMMENT); - // Delete catalog - System.out.println("Testing delete catalog.."); - catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(false)); - catalogList = catalogOperations.listCatalogs(); - Assert.assertNotNull(catalogList); - assertCatalogNotExists(catalogList, CATALOG_NEW_NAME); - } -} \ No newline at end of file + // Delete catalog + System.out.println("Testing delete catalog.."); + catalogOperations.deleteCatalog(CATALOG_NEW_NAME, Optional.of(false)); + catalogList = catalogOperations.listCatalogs(); + Assert.assertNotNull(catalogList); + assertCatalogNotExists(catalogList, CATALOG_NEW_NAME); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/base/catalog/CatalogOperations.java b/server/src/test/java/io/unitycatalog/server/base/catalog/CatalogOperations.java index 65865f3d0..7bdad803a 100644 --- a/server/src/test/java/io/unitycatalog/server/base/catalog/CatalogOperations.java +++ b/server/src/test/java/io/unitycatalog/server/base/catalog/CatalogOperations.java @@ -1,18 +1,20 @@ package io.unitycatalog.server.base.catalog; - import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.CatalogInfo; import io.unitycatalog.client.model.CreateCatalog; import io.unitycatalog.client.model.UpdateCatalog; - import java.util.List; import java.util.Optional; public interface CatalogOperations { - CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException; - List listCatalogs() throws ApiException; - CatalogInfo getCatalog(String name) throws ApiException; - CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException; - void deleteCatalog(String name, Optional force) throws ApiException; -} \ No newline at end of file + CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException; + + List listCatalogs() throws ApiException; + + CatalogInfo getCatalog(String name) throws ApiException; + + CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException; + + void deleteCatalog(String name, Optional force) throws ApiException; +} diff --git a/server/src/test/java/io/unitycatalog/server/base/function/BaseFunctionCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/function/BaseFunctionCRUDTest.java index 1d0380e41..a1725b74c 100644 --- a/server/src/test/java/io/unitycatalog/server/base/function/BaseFunctionCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/function/BaseFunctionCRUDTest.java @@ -1,109 +1,120 @@ package io.unitycatalog.server.base.function; +import static io.unitycatalog.server.utils.TestUtils.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; + import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.*; import io.unitycatalog.server.base.BaseCRUDTest; -import io.unitycatalog.server.utils.TestUtils; -import org.junit.*; - import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.base.schema.SchemaOperations; - import java.util.List; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; -import static io.unitycatalog.server.utils.TestUtils.*; +import org.junit.*; public abstract class BaseFunctionCRUDTest extends BaseCRUDTest { - protected SchemaOperations schemaOperations; - protected FunctionOperations functionOperations; - - protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); - - protected abstract FunctionOperations createFunctionOperations(ServerConfig serverConfig); - - @Before - @Override - public void setUp() { - super.setUp(); - schemaOperations = createSchemaOperations(serverConfig); - functionOperations = createFunctionOperations(serverConfig); - } - - protected void createCommonResources() throws ApiException { - CreateCatalog createCatalog = new CreateCatalog().name(CATALOG_NAME).comment(COMMENT); - catalogOperations.createCatalog(createCatalog); - schemaOperations.createSchema(new CreateSchema().name(SCHEMA_NAME).catalogName(CATALOG_NAME)); - } - - @Test - public void testFunctionCRUD() throws ApiException { - Assert.assertThrows(Exception.class, () -> functionOperations.getFunction(FUNCTION_FULL_NAME)); - // Create a catalog - createCommonResources(); - - FunctionParameterInfos functionParameterInfos = new FunctionParameterInfos() - .parameters(List.of(new FunctionParameterInfo() + protected SchemaOperations schemaOperations; + protected FunctionOperations functionOperations; + + protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); + + protected abstract FunctionOperations createFunctionOperations(ServerConfig serverConfig); + + @Before + @Override + public void setUp() { + super.setUp(); + schemaOperations = createSchemaOperations(serverConfig); + functionOperations = createFunctionOperations(serverConfig); + } + + protected void createCommonResources() throws ApiException { + CreateCatalog createCatalog = new CreateCatalog().name(CATALOG_NAME).comment(COMMENT); + catalogOperations.createCatalog(createCatalog); + schemaOperations.createSchema(new CreateSchema().name(SCHEMA_NAME).catalogName(CATALOG_NAME)); + } + + @Test + public void testFunctionCRUD() throws ApiException { + Assert.assertThrows(Exception.class, () -> functionOperations.getFunction(FUNCTION_FULL_NAME)); + // Create a catalog + createCommonResources(); + + FunctionParameterInfos functionParameterInfos = + new FunctionParameterInfos() + .parameters( + List.of( + new FunctionParameterInfo() .name("param1") .typeName(ColumnTypeName.INT) .typeText("int") .typeJson("{\"type\":\"int\"}") .position(0))); - CreateFunction createFunction = new CreateFunction() - .name(FUNCTION_NAME) - .catalogName(CATALOG_NAME) - .schemaName(SCHEMA_NAME) - .parameterStyle(CreateFunction.ParameterStyleEnum.S) - .isDeterministic(true) - .comment(COMMENT) - .externalLanguage("python") - .dataType(ColumnTypeName.INT) - .fullDataType("Integer") - .isNullCall(false) - .routineBody(CreateFunction.RoutineBodyEnum.EXTERNAL) - .routineDefinition("def test():\n return 1") - .securityType(CreateFunction.SecurityTypeEnum.DEFINER) - .specificName("test") - .sqlDataAccess(CreateFunction.SqlDataAccessEnum.NO_SQL) - .inputParams(functionParameterInfos); - CreateFunctionRequest createFunctionRequest = new CreateFunctionRequest().functionInfo(createFunction); - - // Create a function - FunctionInfo functionInfo = functionOperations.createFunction(createFunctionRequest); - assertEquals(FUNCTION_NAME, functionInfo.getName()); - assertEquals(CATALOG_NAME, functionInfo.getCatalogName()); - assertEquals(SCHEMA_NAME, functionInfo.getSchemaName()); - assertNotNull(functionInfo.getFunctionId()); - - // List functions - Iterable functionInfos = functionOperations.listFunctions(CATALOG_NAME, SCHEMA_NAME); - assertTrue(contains(functionInfos, functionInfo, f -> { - assertThat(f.getFunctionId()).isNotNull(); - if (!f.getFunctionId().equals(functionInfo.getFunctionId())) return false; - if (f.getInputParams() != null && f.getInputParams().getParameters() != null) { - return f.getInputParams().getParameters().stream().anyMatch(p -> p.getName().equals("param1")); - } - return true; - })); - - // Get function - FunctionInfo retrievedFunctionInfo = functionOperations.getFunction(FUNCTION_FULL_NAME); - assertEquals(functionInfo, retrievedFunctionInfo); - - // now update the parent catalog - UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); - catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); - // get the function again - FunctionInfo retrievedFunctionInfoAfterCatUpdate = functionOperations.getFunction( - CATALOG_NEW_NAME + "." + SCHEMA_NAME + "." + FUNCTION_NAME); - assertEquals(retrievedFunctionInfo.getFunctionId(), - retrievedFunctionInfoAfterCatUpdate.getFunctionId()); - - // Delete function - functionOperations.deleteFunction(CATALOG_NEW_NAME + "." + SCHEMA_NAME + "." + FUNCTION_NAME, true); - assertFalse(contains(functionOperations.listFunctions(CATALOG_NEW_NAME, SCHEMA_NAME), - functionInfo, f -> f.getFunctionId().equals(functionInfo.getFunctionId()))); - } + CreateFunction createFunction = + new CreateFunction() + .name(FUNCTION_NAME) + .catalogName(CATALOG_NAME) + .schemaName(SCHEMA_NAME) + .parameterStyle(CreateFunction.ParameterStyleEnum.S) + .isDeterministic(true) + .comment(COMMENT) + .externalLanguage("python") + .dataType(ColumnTypeName.INT) + .fullDataType("Integer") + .isNullCall(false) + .routineBody(CreateFunction.RoutineBodyEnum.EXTERNAL) + .routineDefinition("def test():\n return 1") + .securityType(CreateFunction.SecurityTypeEnum.DEFINER) + .specificName("test") + .sqlDataAccess(CreateFunction.SqlDataAccessEnum.NO_SQL) + .inputParams(functionParameterInfos); + CreateFunctionRequest createFunctionRequest = + new CreateFunctionRequest().functionInfo(createFunction); + + // Create a function + FunctionInfo functionInfo = functionOperations.createFunction(createFunctionRequest); + assertEquals(FUNCTION_NAME, functionInfo.getName()); + assertEquals(CATALOG_NAME, functionInfo.getCatalogName()); + assertEquals(SCHEMA_NAME, functionInfo.getSchemaName()); + assertNotNull(functionInfo.getFunctionId()); + + // List functions + Iterable functionInfos = + functionOperations.listFunctions(CATALOG_NAME, SCHEMA_NAME); + assertTrue( + contains( + functionInfos, + functionInfo, + f -> { + assertThat(f.getFunctionId()).isNotNull(); + if (!f.getFunctionId().equals(functionInfo.getFunctionId())) return false; + if (f.getInputParams() != null && f.getInputParams().getParameters() != null) { + return f.getInputParams().getParameters().stream() + .anyMatch(p -> p.getName().equals("param1")); + } + return true; + })); + + // Get function + FunctionInfo retrievedFunctionInfo = functionOperations.getFunction(FUNCTION_FULL_NAME); + assertEquals(functionInfo, retrievedFunctionInfo); + + // now update the parent catalog + UpdateCatalog updateCatalog = new UpdateCatalog().newName(CATALOG_NEW_NAME); + catalogOperations.updateCatalog(CATALOG_NAME, updateCatalog); + // get the function again + FunctionInfo retrievedFunctionInfoAfterCatUpdate = + functionOperations.getFunction(CATALOG_NEW_NAME + "." + SCHEMA_NAME + "." + FUNCTION_NAME); + assertEquals( + retrievedFunctionInfo.getFunctionId(), retrievedFunctionInfoAfterCatUpdate.getFunctionId()); + + // Delete function + functionOperations.deleteFunction( + CATALOG_NEW_NAME + "." + SCHEMA_NAME + "." + FUNCTION_NAME, true); + assertFalse( + contains( + functionOperations.listFunctions(CATALOG_NEW_NAME, SCHEMA_NAME), + functionInfo, + f -> f.getFunctionId().equals(functionInfo.getFunctionId()))); + } } diff --git a/server/src/test/java/io/unitycatalog/server/base/function/FunctionOperations.java b/server/src/test/java/io/unitycatalog/server/base/function/FunctionOperations.java index 428593561..4df5f9fd4 100644 --- a/server/src/test/java/io/unitycatalog/server/base/function/FunctionOperations.java +++ b/server/src/test/java/io/unitycatalog/server/base/function/FunctionOperations.java @@ -3,12 +3,14 @@ import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.CreateFunctionRequest; import io.unitycatalog.client.model.FunctionInfo; - import java.util.List; public interface FunctionOperations { - FunctionInfo createFunction(CreateFunctionRequest createFunctionRequest) throws ApiException; - List listFunctions(String catalogName, String schemaName) throws ApiException; - FunctionInfo getFunction(String functionFullName) throws ApiException; - void deleteFunction(String functionFullName, boolean force) throws ApiException; + FunctionInfo createFunction(CreateFunctionRequest createFunctionRequest) throws ApiException; + + List listFunctions(String catalogName, String schemaName) throws ApiException; + + FunctionInfo getFunction(String functionFullName) throws ApiException; + + void deleteFunction(String functionFullName, boolean force) throws ApiException; } diff --git a/server/src/test/java/io/unitycatalog/server/base/schema/BaseSchemaCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/schema/BaseSchemaCRUDTest.java index d995ba83d..b81fca216 100644 --- a/server/src/test/java/io/unitycatalog/server/base/schema/BaseSchemaCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/schema/BaseSchemaCRUDTest.java @@ -1,103 +1,110 @@ package io.unitycatalog.server.base.schema; +import static org.junit.Assert.*; + import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.*; import io.unitycatalog.server.base.BaseCRUDTest; import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.utils.TestUtils; -import org.junit.*; - -import java.util.List; import java.util.Optional; - -import static org.junit.Assert.*; +import org.junit.*; public abstract class BaseSchemaCRUDTest extends BaseCRUDTest { - protected SchemaOperations schemaOperations; - - protected abstract SchemaOperations createSchemaOperations(ServerConfig config); - - @Before - @Override - public void setUp() { - super.setUp(); - schemaOperations = createSchemaOperations(serverConfig); - } - - @Test - public void testSchemaCRUDL() throws ApiException { - // Create a schema - System.out.println("Testing create schema.."); - CreateSchema createSchema = new CreateSchema() - .name(TestUtils.SCHEMA_NAME) - .catalogName(TestUtils.CATALOG_NAME) - .properties(TestUtils.PROPERTIES); - assertThrows(Exception.class, () -> schemaOperations.createSchema(createSchema)); - - CreateCatalog createCatalog = new CreateCatalog().name(TestUtils.CATALOG_NAME); - catalogOperations.createCatalog(createCatalog); - SchemaInfo schemaInfo = schemaOperations.createSchema(createSchema); - assertEquals(createSchema.getName(), schemaInfo.getName()); - assertEquals(createSchema.getCatalogName(), schemaInfo.getCatalogName()); - assertEquals(TestUtils.SCHEMA_FULL_NAME, schemaInfo.getFullName()); - // TODO: Assert properties once CLI supports it - assertNotNull(schemaInfo.getCreatedAt()); - - // List schemas - System.out.println("Testing list schemas.."); - Iterable schemaList = schemaOperations.listSchemas(TestUtils.CATALOG_NAME); - assertTrue(TestUtils.contains(schemaList, schemaInfo, (schema) -> schema.equals(schemaInfo))); - - // Get schema - System.out.println("Testing get schema.."); - SchemaInfo retrievedSchemaInfo = schemaOperations.getSchema(TestUtils.SCHEMA_FULL_NAME); - assertEquals(schemaInfo, retrievedSchemaInfo); - - // Update schema - System.out.println("Testing update schema.."); - UpdateSchema updateSchema = new UpdateSchema() - .newName(TestUtils.SCHEMA_NEW_NAME) - .comment(TestUtils.SCHEMA_COMMENT); - - // Set update details - SchemaInfo updatedSchemaInfo = schemaOperations.updateSchema(TestUtils.SCHEMA_FULL_NAME, updateSchema); - assertEquals(updateSchema.getNewName(), updatedSchemaInfo.getName()); - assertEquals(updateSchema.getComment(), updatedSchemaInfo.getComment()); - Assert.assertEquals(TestUtils.SCHEMA_NEW_FULL_NAME, updatedSchemaInfo.getFullName()); - assertNotNull(updatedSchemaInfo.getUpdatedAt()); - - //Now update the parent catalog name - UpdateCatalog updateCatalog = new UpdateCatalog().newName(TestUtils.CATALOG_NEW_NAME); - catalogOperations.updateCatalog(TestUtils.CATALOG_NAME, updateCatalog); - SchemaInfo updatedSchemaInfo2 = schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME - + "." + TestUtils.SCHEMA_NEW_NAME); - assertEquals(retrievedSchemaInfo.getSchemaId(), updatedSchemaInfo2.getSchemaId()); - - // Delete schema - System.out.println("Testing delete schema.."); - schemaOperations.deleteSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(false)); - assertFalse(TestUtils.contains(schemaOperations.listSchemas(TestUtils.CATALOG_NEW_NAME), updatedSchemaInfo, (schema) -> - schema.getName().equals(TestUtils.SCHEMA_NEW_NAME))); - - // Delete parent entity when schema exists - SchemaInfo schemaInfo2 = schemaOperations.createSchema(new CreateSchema().name(TestUtils.SCHEMA_NAME) - .catalogName(TestUtils.CATALOG_NEW_NAME)); - assertThrows(Exception.class , () -> - catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(false))); - catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(true)); - assertThrows(Exception.class , () -> - schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NAME)); - - // Test force delete of parent entity when schema exists - - catalogOperations.createCatalog(new CreateCatalog().name(TestUtils.CATALOG_NEW_NAME) - .comment("Common catalog for schemas")); - SchemaInfo schemaInfo3 = schemaOperations.createSchema(new CreateSchema().name(TestUtils.SCHEMA_NAME) - .catalogName(TestUtils.CATALOG_NEW_NAME)); - catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(true)); - assertThrows(Exception.class , () -> - schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NAME)); - - } + protected SchemaOperations schemaOperations; + + protected abstract SchemaOperations createSchemaOperations(ServerConfig config); + + @Before + @Override + public void setUp() { + super.setUp(); + schemaOperations = createSchemaOperations(serverConfig); + } + + @Test + public void testSchemaCRUDL() throws ApiException { + // Create a schema + System.out.println("Testing create schema.."); + CreateSchema createSchema = + new CreateSchema() + .name(TestUtils.SCHEMA_NAME) + .catalogName(TestUtils.CATALOG_NAME) + .properties(TestUtils.PROPERTIES); + assertThrows(Exception.class, () -> schemaOperations.createSchema(createSchema)); + + CreateCatalog createCatalog = new CreateCatalog().name(TestUtils.CATALOG_NAME); + catalogOperations.createCatalog(createCatalog); + SchemaInfo schemaInfo = schemaOperations.createSchema(createSchema); + assertEquals(createSchema.getName(), schemaInfo.getName()); + assertEquals(createSchema.getCatalogName(), schemaInfo.getCatalogName()); + assertEquals(TestUtils.SCHEMA_FULL_NAME, schemaInfo.getFullName()); + // TODO: Assert properties once CLI supports it + assertNotNull(schemaInfo.getCreatedAt()); + + // List schemas + System.out.println("Testing list schemas.."); + Iterable schemaList = schemaOperations.listSchemas(TestUtils.CATALOG_NAME); + assertTrue(TestUtils.contains(schemaList, schemaInfo, (schema) -> schema.equals(schemaInfo))); + + // Get schema + System.out.println("Testing get schema.."); + SchemaInfo retrievedSchemaInfo = schemaOperations.getSchema(TestUtils.SCHEMA_FULL_NAME); + assertEquals(schemaInfo, retrievedSchemaInfo); + + // Update schema + System.out.println("Testing update schema.."); + UpdateSchema updateSchema = + new UpdateSchema().newName(TestUtils.SCHEMA_NEW_NAME).comment(TestUtils.SCHEMA_COMMENT); + + // Set update details + SchemaInfo updatedSchemaInfo = + schemaOperations.updateSchema(TestUtils.SCHEMA_FULL_NAME, updateSchema); + assertEquals(updateSchema.getNewName(), updatedSchemaInfo.getName()); + assertEquals(updateSchema.getComment(), updatedSchemaInfo.getComment()); + Assert.assertEquals(TestUtils.SCHEMA_NEW_FULL_NAME, updatedSchemaInfo.getFullName()); + assertNotNull(updatedSchemaInfo.getUpdatedAt()); + + // Now update the parent catalog name + UpdateCatalog updateCatalog = new UpdateCatalog().newName(TestUtils.CATALOG_NEW_NAME); + catalogOperations.updateCatalog(TestUtils.CATALOG_NAME, updateCatalog); + SchemaInfo updatedSchemaInfo2 = + schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NEW_NAME); + assertEquals(retrievedSchemaInfo.getSchemaId(), updatedSchemaInfo2.getSchemaId()); + + // Delete schema + System.out.println("Testing delete schema.."); + schemaOperations.deleteSchema( + TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(false)); + assertFalse( + TestUtils.contains( + schemaOperations.listSchemas(TestUtils.CATALOG_NEW_NAME), + updatedSchemaInfo, + (schema) -> schema.getName().equals(TestUtils.SCHEMA_NEW_NAME))); + + // Delete parent entity when schema exists + SchemaInfo schemaInfo2 = + schemaOperations.createSchema( + new CreateSchema().name(TestUtils.SCHEMA_NAME).catalogName(TestUtils.CATALOG_NEW_NAME)); + assertThrows( + Exception.class, + () -> catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(false))); + catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(true)); + assertThrows( + Exception.class, + () -> schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NAME)); + + // Test force delete of parent entity when schema exists + + catalogOperations.createCatalog( + new CreateCatalog().name(TestUtils.CATALOG_NEW_NAME).comment("Common catalog for schemas")); + SchemaInfo schemaInfo3 = + schemaOperations.createSchema( + new CreateSchema().name(TestUtils.SCHEMA_NAME).catalogName(TestUtils.CATALOG_NEW_NAME)); + catalogOperations.deleteCatalog(TestUtils.CATALOG_NEW_NAME, Optional.of(true)); + assertThrows( + Exception.class, + () -> schemaOperations.getSchema(TestUtils.CATALOG_NEW_NAME + "." + TestUtils.SCHEMA_NAME)); + } } diff --git a/server/src/test/java/io/unitycatalog/server/base/schema/SchemaOperations.java b/server/src/test/java/io/unitycatalog/server/base/schema/SchemaOperations.java index dc65e6cab..83a7995a5 100644 --- a/server/src/test/java/io/unitycatalog/server/base/schema/SchemaOperations.java +++ b/server/src/test/java/io/unitycatalog/server/base/schema/SchemaOperations.java @@ -1,19 +1,20 @@ package io.unitycatalog.server.base.schema; - - import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.CreateSchema; import io.unitycatalog.client.model.SchemaInfo; import io.unitycatalog.client.model.UpdateSchema; - import java.util.List; import java.util.Optional; public interface SchemaOperations { - SchemaInfo createSchema(CreateSchema createSchema) throws ApiException; - List listSchemas(String catalogName) throws ApiException; - SchemaInfo getSchema(String schemaFullName) throws ApiException; - SchemaInfo updateSchema(String name, UpdateSchema updateSchema) throws ApiException; - void deleteSchema(String schemaFullName, Optional force) throws ApiException; + SchemaInfo createSchema(CreateSchema createSchema) throws ApiException; + + List listSchemas(String catalogName) throws ApiException; + + SchemaInfo getSchema(String schemaFullName) throws ApiException; + + SchemaInfo updateSchema(String name, UpdateSchema updateSchema) throws ApiException; + + void deleteSchema(String schemaFullName, Optional force) throws ApiException; } diff --git a/server/src/test/java/io/unitycatalog/server/base/table/BaseTableCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/table/BaseTableCRUDTest.java index dd3be679e..01f4d1e73 100644 --- a/server/src/test/java/io/unitycatalog/server/base/table/BaseTableCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/table/BaseTableCRUDTest.java @@ -1,193 +1,228 @@ package io.unitycatalog.server.base.table; +import static org.junit.Assert.*; + import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.*; import io.unitycatalog.server.base.BaseCRUDTest; import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.base.schema.SchemaOperations; -import io.unitycatalog.server.persist.utils.FileUtils; -import io.unitycatalog.server.persist.utils.HibernateUtils; import io.unitycatalog.server.persist.dao.ColumnInfoDAO; import io.unitycatalog.server.persist.dao.TableInfoDAO; +import io.unitycatalog.server.persist.utils.FileUtils; +import io.unitycatalog.server.persist.utils.HibernateUtils; import io.unitycatalog.server.utils.TestUtils; +import java.io.IOException; +import java.util.*; import org.hibernate.Session; import org.hibernate.Transaction; import org.junit.*; -import java.io.IOException; -import java.util.*; - -import static org.junit.Assert.*; - public abstract class BaseTableCRUDTest extends BaseCRUDTest { - protected SchemaOperations schemaOperations; - protected TableOperations tableOperations; - private String schemaId = null; - - protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); - protected abstract TableOperations createTableOperations(ServerConfig serverConfig); - - @Before - @Override - public void setUp() { - super.setUp(); - schemaOperations = createSchemaOperations(serverConfig); - tableOperations = createTableOperations(serverConfig); - } - - protected void createCommonResources() throws ApiException { - // Common setup operations such as creating a catalog and schema - CreateCatalog createCatalog = new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT); - catalogOperations.createCatalog(createCatalog); - SchemaInfo schemaInfo = schemaOperations.createSchema(new CreateSchema().name(TestUtils.SCHEMA_NAME).catalogName(TestUtils.CATALOG_NAME)); - schemaId = schemaInfo.getSchemaId(); + protected SchemaOperations schemaOperations; + protected TableOperations tableOperations; + private String schemaId = null; + + protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); + + protected abstract TableOperations createTableOperations(ServerConfig serverConfig); + + @Before + @Override + public void setUp() { + super.setUp(); + schemaOperations = createSchemaOperations(serverConfig); + tableOperations = createTableOperations(serverConfig); + } + + protected void createCommonResources() throws ApiException { + // Common setup operations such as creating a catalog and schema + CreateCatalog createCatalog = + new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT); + catalogOperations.createCatalog(createCatalog); + SchemaInfo schemaInfo = + schemaOperations.createSchema( + new CreateSchema().name(TestUtils.SCHEMA_NAME).catalogName(TestUtils.CATALOG_NAME)); + schemaId = schemaInfo.getSchemaId(); + } + + @Test + public void testTableCRUD() throws IOException, ApiException { + Assert.assertThrows(Exception.class, () -> tableOperations.getTable(TestUtils.TABLE_FULL_NAME)); + createCommonResources(); + + // Create a table + System.out.println("Testing create table.."); + TableInfo tableInfo = createDefaultTestingTable(); + assertEquals(TestUtils.TABLE_NAME, tableInfo.getName()); + Assert.assertEquals(TestUtils.CATALOG_NAME, tableInfo.getCatalogName()); + Assert.assertEquals(TestUtils.SCHEMA_NAME, tableInfo.getSchemaName()); + assertNotNull(tableInfo.getTableId()); + + // Get table + System.out.println("Testing get table.."); + TableInfo tableInfo2 = tableOperations.getTable(TestUtils.TABLE_FULL_NAME); + assertEquals(tableInfo, tableInfo2); + + Collection columnInfos2 = tableInfo2.getColumns(); + assertEquals(2, columnInfos2.size()); + assertEquals(1, columnInfos2.stream().filter(c -> c.getName().equals("as_int")).count()); + assertEquals(1, columnInfos2.stream().filter(c -> c.getName().equals("as_string")).count()); + + // List tables + System.out.println("Testing list tables.."); + Iterable tableInfos = + tableOperations.listTables(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME); + assertTrue(TestUtils.contains(tableInfos, tableInfo2, table -> table.equals(tableInfo2))); + + // Delete table + System.out.println("Testing delete table.."); + tableOperations.deleteTable(TestUtils.TABLE_FULL_NAME); + assertThrows(Exception.class, () -> tableOperations.getTable(TestUtils.TABLE_FULL_NAME)); + + try (Session session = HibernateUtils.getSessionFactory().openSession()) { + Transaction tx = session.beginTransaction(); + + UUID tableId = UUID.randomUUID(); + + TableInfoDAO managedTableInfo = + TableInfoDAO.builder() + .name(TestUtils.TABLE_NAME) + .schemaId(UUID.fromString(schemaId)) + .comment(TestUtils.COMMENT) + .url("/tmp/managedStagingLocation") + .type(TableType.MANAGED.name()) + .dataSourceFormat(DataSourceFormat.DELTA.name()) + .id(tableId) + .createdAt(new Date()) + .updatedAt(new Date()) + .build(); + + ColumnInfoDAO columnInfoDAO1 = + ColumnInfoDAO.builder() + .name("as_int") + .typeText("INTEGER") + .typeJson("{\"type\": \"integer\"}") + .typeName(ColumnTypeName.INT.name()) + .typePrecision(10) + .typeScale(0) + .ordinalPosition((short) 0) + .comment("Integer column") + .nullable(true) + .table(managedTableInfo) + .build(); + + ColumnInfoDAO columnInfoDAO2 = + ColumnInfoDAO.builder() + .name("as_string") + .typeText("VARCHAR(255)") + .typeJson("{\"type\": \"string\", \"length\": \"255\"}") + .typeName(ColumnTypeName.STRING.name()) + .ordinalPosition((short) 1) + .comment("String column") + .nullable(true) + .table(managedTableInfo) + .build(); + + managedTableInfo.setColumns(List.of(columnInfoDAO1, columnInfoDAO2)); + + session.persist(managedTableInfo); + session.flush(); + tx.commit(); + } catch (Exception e) { + fail(e.getMessage()); } - @Test - public void testTableCRUD() throws IOException, ApiException { - Assert.assertThrows(Exception.class, () -> tableOperations.getTable(TestUtils.TABLE_FULL_NAME)); - createCommonResources(); - - // Create a table - System.out.println("Testing create table.."); - TableInfo tableInfo = createDefaultTestingTable(); - assertEquals(TestUtils.TABLE_NAME, tableInfo.getName()); - Assert.assertEquals(TestUtils.CATALOG_NAME, tableInfo.getCatalogName()); - Assert.assertEquals(TestUtils.SCHEMA_NAME, tableInfo.getSchemaName()); - assertNotNull(tableInfo.getTableId()); - - // Get table - System.out.println("Testing get table.."); - TableInfo tableInfo2 = tableOperations.getTable(TestUtils.TABLE_FULL_NAME); - assertEquals(tableInfo, tableInfo2); - - Collection columnInfos2 = tableInfo2.getColumns(); - assertEquals(2, columnInfos2.size()); - assertEquals(1, columnInfos2.stream().filter(c -> c.getName().equals("as_int")).count()); - assertEquals(1, columnInfos2.stream().filter(c -> c.getName().equals("as_string")).count()); - - // List tables - System.out.println("Testing list tables.."); - Iterable tableInfos = tableOperations.listTables(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME); - assertTrue(TestUtils.contains(tableInfos, tableInfo2, table -> table.equals(tableInfo2))); - - // Delete table - System.out.println("Testing delete table.."); - tableOperations.deleteTable(TestUtils.TABLE_FULL_NAME); - assertThrows(Exception.class, () -> tableOperations.getTable(TestUtils.TABLE_FULL_NAME)); - - try (Session session = HibernateUtils.getSessionFactory().openSession()) { - Transaction tx = session.beginTransaction(); - - UUID tableId = UUID.randomUUID(); - - TableInfoDAO managedTableInfo = TableInfoDAO.builder() - .name(TestUtils.TABLE_NAME) - .schemaId(UUID.fromString(schemaId)) - .comment(TestUtils.COMMENT) - .url("/tmp/managedStagingLocation") - .type(TableType.MANAGED.name()) - .dataSourceFormat(DataSourceFormat.DELTA.name()) - .id(tableId) - .createdAt(new Date()) - .updatedAt(new Date()) - .build(); - - - ColumnInfoDAO columnInfoDAO1 = ColumnInfoDAO.builder() - .name("as_int") - .typeText("INTEGER") - .typeJson("{\"type\": \"integer\"}") - .typeName(ColumnTypeName.INT.name()) - .typePrecision(10) - .typeScale(0) - .ordinalPosition((short)0) - .comment("Integer column") - .nullable(true) - .table(managedTableInfo) - .build(); - - ColumnInfoDAO columnInfoDAO2 = ColumnInfoDAO.builder() - .name("as_string") - .typeText("VARCHAR(255)") - .typeJson("{\"type\": \"string\", \"length\": \"255\"}") - .typeName(ColumnTypeName.STRING.name()) - .ordinalPosition((short)1) - .comment("String column") - .nullable(true) - .table(managedTableInfo) - .build(); - - managedTableInfo.setColumns(List.of(columnInfoDAO1, columnInfoDAO2)); - - session.persist(managedTableInfo); - session.flush(); - tx.commit(); - } catch (Exception e) { - fail(e.getMessage()); - } - - System.out.println("Testing get managed table.."); - TableInfo managedTable = tableOperations.getTable(TestUtils.TABLE_FULL_NAME); - assertEquals(TestUtils.TABLE_NAME, managedTable.getName()); - Assert.assertEquals(TestUtils.CATALOG_NAME, managedTable.getCatalogName()); - Assert.assertEquals(TestUtils.SCHEMA_NAME, managedTable.getSchemaName()); - Assert.assertEquals(FileUtils.convertRelativePathToURI("/tmp/managedStagingLocation"), managedTable.getStorageLocation()); - Assert.assertEquals(TableType.MANAGED, managedTable.getTableType()); - Assert.assertEquals(DataSourceFormat.DELTA, managedTable.getDataSourceFormat()); - assertNotNull(managedTable.getCreatedAt()); - assertNotNull(managedTable.getTableId()); - - System.out.println("Testing list managed tables.."); - List managedTables = tableOperations.listTables(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME); - TableInfo managedListTable = managedTables.get(0); - assertEquals(TestUtils.TABLE_NAME, managedListTable.getName()); - Assert.assertEquals(TestUtils.CATALOG_NAME, managedListTable.getCatalogName()); - Assert.assertEquals(TestUtils.SCHEMA_NAME, managedListTable.getSchemaName()); - Assert.assertEquals(FileUtils.convertRelativePathToURI("/tmp/managedStagingLocation"), managedListTable.getStorageLocation()); - Assert.assertEquals(TableType.MANAGED, managedListTable.getTableType()); - Assert.assertEquals(DataSourceFormat.DELTA, managedListTable.getDataSourceFormat()); - assertNotNull(managedListTable.getCreatedAt()); - assertNotNull(managedListTable.getTableId()); - - // Now update the parent schema name - schemaOperations.updateSchema(TestUtils.SCHEMA_FULL_NAME, new UpdateSchema().newName(TestUtils.SCHEMA_NEW_NAME).comment(TestUtils.SCHEMA_COMMENT)); - // now fetch the table again - TableInfo managedTableAfterSchemaUpdate = tableOperations.getTable(TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME + "." + TestUtils.TABLE_NAME); - assertEquals(managedTable.getTableId(), managedTableAfterSchemaUpdate.getTableId()); - - // test delete parent schema when table exists - assertThrows(Exception.class, () -> schemaOperations.deleteSchema(TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(false))); - - // test force delete parent schema when table exists - String newTableFullName = TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME + "." + TestUtils.TABLE_NAME; - schemaOperations.deleteSchema(TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(true)); - assertThrows(Exception.class, () -> tableOperations.getTable(newTableFullName)); - assertThrows(Exception.class, () -> schemaOperations.getSchema(TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME)); - - } - - protected TableInfo createDefaultTestingTable() throws IOException, ApiException { - ColumnInfo columnInfo1 = new ColumnInfo().name("as_int").typeText("INTEGER") - .typeJson("{\"type\": \"integer\"}") - .typeName(ColumnTypeName.INT).typePrecision(10).typeScale(0).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(TestUtils.TABLE_NAME) - .catalogName(TestUtils.CATALOG_NAME) - .schemaName(TestUtils.SCHEMA_NAME) - .columns(List.of(columnInfo1, columnInfo2)) - .properties(TestUtils.PROPERTIES) - .comment(TestUtils.COMMENT) - .storageLocation("/tmp/stagingLocation") - .tableType(TableType.EXTERNAL) - .dataSourceFormat(DataSourceFormat.DELTA); - - return tableOperations.createTable(createTableRequest); - } -} \ No newline at end of file + System.out.println("Testing get managed table.."); + TableInfo managedTable = tableOperations.getTable(TestUtils.TABLE_FULL_NAME); + assertEquals(TestUtils.TABLE_NAME, managedTable.getName()); + Assert.assertEquals(TestUtils.CATALOG_NAME, managedTable.getCatalogName()); + Assert.assertEquals(TestUtils.SCHEMA_NAME, managedTable.getSchemaName()); + Assert.assertEquals( + FileUtils.convertRelativePathToURI("/tmp/managedStagingLocation"), + managedTable.getStorageLocation()); + Assert.assertEquals(TableType.MANAGED, managedTable.getTableType()); + Assert.assertEquals(DataSourceFormat.DELTA, managedTable.getDataSourceFormat()); + assertNotNull(managedTable.getCreatedAt()); + assertNotNull(managedTable.getTableId()); + + System.out.println("Testing list managed tables.."); + List managedTables = + tableOperations.listTables(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME); + TableInfo managedListTable = managedTables.get(0); + assertEquals(TestUtils.TABLE_NAME, managedListTable.getName()); + Assert.assertEquals(TestUtils.CATALOG_NAME, managedListTable.getCatalogName()); + Assert.assertEquals(TestUtils.SCHEMA_NAME, managedListTable.getSchemaName()); + Assert.assertEquals( + FileUtils.convertRelativePathToURI("/tmp/managedStagingLocation"), + managedListTable.getStorageLocation()); + Assert.assertEquals(TableType.MANAGED, managedListTable.getTableType()); + Assert.assertEquals(DataSourceFormat.DELTA, managedListTable.getDataSourceFormat()); + assertNotNull(managedListTable.getCreatedAt()); + assertNotNull(managedListTable.getTableId()); + + // Now update the parent schema name + schemaOperations.updateSchema( + TestUtils.SCHEMA_FULL_NAME, + new UpdateSchema().newName(TestUtils.SCHEMA_NEW_NAME).comment(TestUtils.SCHEMA_COMMENT)); + // now fetch the table again + TableInfo managedTableAfterSchemaUpdate = + tableOperations.getTable( + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME + "." + TestUtils.TABLE_NAME); + assertEquals(managedTable.getTableId(), managedTableAfterSchemaUpdate.getTableId()); + + // test delete parent schema when table exists + assertThrows( + Exception.class, + () -> + schemaOperations.deleteSchema( + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(false))); + + // test force delete parent schema when table exists + String newTableFullName = + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME + "." + TestUtils.TABLE_NAME; + schemaOperations.deleteSchema( + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME, Optional.of(true)); + assertThrows(Exception.class, () -> tableOperations.getTable(newTableFullName)); + assertThrows( + Exception.class, + () -> schemaOperations.getSchema(TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NEW_NAME)); + } + + protected TableInfo createDefaultTestingTable() throws IOException, ApiException { + ColumnInfo columnInfo1 = + new ColumnInfo() + .name("as_int") + .typeText("INTEGER") + .typeJson("{\"type\": \"integer\"}") + .typeName(ColumnTypeName.INT) + .typePrecision(10) + .typeScale(0) + .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(TestUtils.TABLE_NAME) + .catalogName(TestUtils.CATALOG_NAME) + .schemaName(TestUtils.SCHEMA_NAME) + .columns(List.of(columnInfo1, columnInfo2)) + .properties(TestUtils.PROPERTIES) + .comment(TestUtils.COMMENT) + .storageLocation("/tmp/stagingLocation") + .tableType(TableType.EXTERNAL) + .dataSourceFormat(DataSourceFormat.DELTA); + + return tableOperations.createTable(createTableRequest); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/base/table/TableOperations.java b/server/src/test/java/io/unitycatalog/server/base/table/TableOperations.java index 08702c08d..7f1262b3c 100644 --- a/server/src/test/java/io/unitycatalog/server/base/table/TableOperations.java +++ b/server/src/test/java/io/unitycatalog/server/base/table/TableOperations.java @@ -1,17 +1,17 @@ package io.unitycatalog.server.base.table; - import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.CreateTable; import io.unitycatalog.client.model.TableInfo; - import java.io.IOException; import java.util.List; public interface TableOperations { - TableInfo createTable(CreateTable createTableRequest) throws IOException, ApiException; - List listTables(String catalogName, String schemaName) throws ApiException; - TableInfo getTable(String tableFullName) throws ApiException; - //TableInfo updateTable(UpdateTableRequestContent updateTableRequest) throws IOException; - void deleteTable(String tableFullName) throws ApiException; + TableInfo createTable(CreateTable createTableRequest) throws IOException, ApiException; + + List listTables(String catalogName, String schemaName) throws ApiException; + + TableInfo getTable(String tableFullName) throws ApiException; + // TableInfo updateTable(UpdateTableRequestContent updateTableRequest) throws IOException; + void deleteTable(String tableFullName) throws ApiException; } diff --git a/server/src/test/java/io/unitycatalog/server/base/volume/BaseVolumeCRUDTest.java b/server/src/test/java/io/unitycatalog/server/base/volume/BaseVolumeCRUDTest.java index c83ecb827..e07b78fa8 100644 --- a/server/src/test/java/io/unitycatalog/server/base/volume/BaseVolumeCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/base/volume/BaseVolumeCRUDTest.java @@ -1,160 +1,179 @@ package io.unitycatalog.server.base.volume; +import static io.unitycatalog.server.utils.TestUtils.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.*; + import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.*; import io.unitycatalog.server.base.BaseCRUDTest; -import io.unitycatalog.server.persist.utils.FileUtils; -import io.unitycatalog.server.persist.utils.HibernateUtils; -import io.unitycatalog.server.persist.dao.VolumeInfoDAO; -import io.unitycatalog.server.utils.TestUtils; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.*; import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.base.schema.SchemaOperations; - +import io.unitycatalog.server.persist.dao.VolumeInfoDAO; +import io.unitycatalog.server.persist.utils.FileUtils; +import io.unitycatalog.server.persist.utils.HibernateUtils; import java.util.Date; import java.util.Optional; import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.*; -import static io.unitycatalog.server.utils.TestUtils.*; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.*; public abstract class BaseVolumeCRUDTest extends BaseCRUDTest { - protected SchemaOperations schemaOperations; - protected VolumeOperations volumeOperations; - - protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); - - protected abstract VolumeOperations createVolumeOperations(ServerConfig serverConfig); - - @Before - @Override - public void setUp() { - super.setUp(); - schemaOperations = createSchemaOperations(serverConfig); - volumeOperations = createVolumeOperations(serverConfig); + protected SchemaOperations schemaOperations; + protected VolumeOperations volumeOperations; + + protected abstract SchemaOperations createSchemaOperations(ServerConfig serverConfig); + + protected abstract VolumeOperations createVolumeOperations(ServerConfig serverConfig); + + @Before + @Override + public void setUp() { + super.setUp(); + schemaOperations = createSchemaOperations(serverConfig); + volumeOperations = createVolumeOperations(serverConfig); + } + + private SchemaInfo schemaInfo; + + protected void createCommonResources() throws ApiException { + // Common setup operations such as creating a catalog and schema + CreateCatalog createCatalog = new CreateCatalog().name(CATALOG_NAME).comment(COMMENT); + catalogOperations.createCatalog(createCatalog); + schemaInfo = + schemaOperations.createSchema( + new CreateSchema().name(SCHEMA_NAME).catalogName(CATALOG_NAME)); + } + + @Test + public void testVolumeCRUD() throws ApiException { + // Create a volume + System.out.println("Testing create volume.."); + CreateVolumeRequestContent createVolumeRequest = + new CreateVolumeRequestContent() + .name(VOLUME_NAME) + .catalogName(CATALOG_NAME) + .schemaName(SCHEMA_NAME) + .volumeType(VolumeType.EXTERNAL) + .storageLocation("/tmp/volume1"); + assertThrows(Exception.class, () -> volumeOperations.createVolume(createVolumeRequest)); + + createCommonResources(); + VolumeInfo volumeInfo = volumeOperations.createVolume(createVolumeRequest); + assertEquals(createVolumeRequest.getName(), volumeInfo.getName()); + assertEquals(createVolumeRequest.getCatalogName(), volumeInfo.getCatalogName()); + assertEquals(createVolumeRequest.getSchemaName(), volumeInfo.getSchemaName()); + assertEquals(createVolumeRequest.getVolumeType(), volumeInfo.getVolumeType()); + assertEquals( + FileUtils.convertRelativePathToURI(createVolumeRequest.getStorageLocation()), + volumeInfo.getStorageLocation()); + assertEquals(VOLUME_FULL_NAME, volumeInfo.getFullName()); + assertNotNull(volumeInfo.getCreatedAt()); + + // List volumes + System.out.println("Testing list volumes.."); + Iterable volumeInfos = volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME); + assertTrue( + contains( + volumeInfos, + volumeInfo, + (volume) -> { + assertThat(volume.getName()).isNotNull(); + return volume.getName().equals(VOLUME_NAME); + })); + + // Get volume + System.out.println("Testing get volume.."); + VolumeInfo retrievedVolumeInfo = volumeOperations.getVolume(VOLUME_FULL_NAME); + assertEquals(volumeInfo, retrievedVolumeInfo); + + // Update volume + System.out.println("Testing update volume.."); + UpdateVolumeRequestContent updateVolumeRequest = + new UpdateVolumeRequestContent().newName(VOLUME_NEW_NAME).comment(COMMENT); + // Set update details + VolumeInfo updatedVolumeInfo = + volumeOperations.updateVolume(VOLUME_FULL_NAME, updateVolumeRequest); + assertEquals(updateVolumeRequest.getNewName(), updatedVolumeInfo.getName()); + assertEquals(updateVolumeRequest.getComment(), updatedVolumeInfo.getComment()); + assertEquals(VOLUME_NEW_FULL_NAME, updatedVolumeInfo.getFullName()); + assertNotNull(updatedVolumeInfo.getUpdatedAt()); + + // Delete volume + System.out.println("Testing delete volume.."); + volumeOperations.deleteVolume(VOLUME_NEW_FULL_NAME); + assertEquals(0, getSize(volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME))); + + // Testing Managed Volume + System.out.println("Creating managed volume.."); + + SessionFactory sessionFactory = HibernateUtils.getSessionFactory(); + + try (Session session = sessionFactory.openSession()) { + session.beginTransaction(); + VolumeInfoDAO managedVolume = + VolumeInfoDAO.builder() + .volumeType(VolumeType.MANAGED.getValue()) + .storageLocation("/tmp/managed_volume") + .name(VOLUME_NAME) + .createdAt(new Date()) + .updatedAt(new Date()) + .id(UUID.randomUUID()) + .schemaId(UUID.fromString(schemaInfo.getSchemaId())) + .build(); + session.persist(managedVolume); + session.getTransaction().commit(); } - private SchemaInfo schemaInfo; - - protected void createCommonResources() throws ApiException { - // Common setup operations such as creating a catalog and schema - CreateCatalog createCatalog = new CreateCatalog().name(CATALOG_NAME).comment(COMMENT); - catalogOperations.createCatalog(createCatalog); - schemaInfo = schemaOperations.createSchema(new CreateSchema().name(SCHEMA_NAME).catalogName(CATALOG_NAME)); - } - - @Test - public void testVolumeCRUD() throws ApiException { - // Create a volume - System.out.println("Testing create volume.."); - CreateVolumeRequestContent createVolumeRequest = new CreateVolumeRequestContent() - .name(VOLUME_NAME) - .catalogName(CATALOG_NAME) - .schemaName(SCHEMA_NAME) - .volumeType(VolumeType.EXTERNAL) - .storageLocation("/tmp/volume1"); - assertThrows(Exception.class, () -> volumeOperations.createVolume(createVolumeRequest)); - - createCommonResources(); - VolumeInfo volumeInfo = volumeOperations.createVolume(createVolumeRequest); - assertEquals(createVolumeRequest.getName(), volumeInfo.getName()); - assertEquals(createVolumeRequest.getCatalogName(), volumeInfo.getCatalogName()); - assertEquals(createVolumeRequest.getSchemaName(), volumeInfo.getSchemaName()); - assertEquals(createVolumeRequest.getVolumeType(), volumeInfo.getVolumeType()); - assertEquals(FileUtils.convertRelativePathToURI(createVolumeRequest.getStorageLocation()), volumeInfo.getStorageLocation()); - assertEquals(VOLUME_FULL_NAME, volumeInfo.getFullName()); - assertNotNull(volumeInfo.getCreatedAt()); - - // List volumes - System.out.println("Testing list volumes.."); - Iterable volumeInfos = volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME); - assertTrue(contains(volumeInfos, volumeInfo, (volume) -> { - assertThat(volume.getName()).isNotNull(); - return volume.getName().equals(VOLUME_NAME); - })); - - // Get volume - System.out.println("Testing get volume.."); - VolumeInfo retrievedVolumeInfo = volumeOperations.getVolume(VOLUME_FULL_NAME); - assertEquals(volumeInfo, retrievedVolumeInfo); - - // Update volume - System.out.println("Testing update volume.."); - UpdateVolumeRequestContent updateVolumeRequest = new UpdateVolumeRequestContent() - .newName(VOLUME_NEW_NAME) - .comment(COMMENT); - // Set update details - VolumeInfo updatedVolumeInfo = volumeOperations.updateVolume(VOLUME_FULL_NAME, updateVolumeRequest); - assertEquals(updateVolumeRequest.getNewName(), updatedVolumeInfo.getName()); - assertEquals(updateVolumeRequest.getComment(), updatedVolumeInfo.getComment()); - assertEquals(VOLUME_NEW_FULL_NAME, updatedVolumeInfo.getFullName()); - assertNotNull(updatedVolumeInfo.getUpdatedAt()); - - // Delete volume - System.out.println("Testing delete volume.."); - volumeOperations.deleteVolume(VOLUME_NEW_FULL_NAME); - assertEquals(0, getSize(volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME))); - - - // Testing Managed Volume - System.out.println("Creating managed volume.."); - - SessionFactory sessionFactory = HibernateUtils.getSessionFactory(); - - try (Session session = sessionFactory.openSession()) { - session.beginTransaction(); - VolumeInfoDAO managedVolume = VolumeInfoDAO.builder() - .volumeType(VolumeType.MANAGED.getValue()) - .storageLocation("/tmp/managed_volume") - .name(VOLUME_NAME) - .createdAt(new Date()) - .updatedAt(new Date()) - .id(UUID.randomUUID()) - .schemaId(UUID.fromString(schemaInfo.getSchemaId())) - .build(); - session.persist(managedVolume); - session.getTransaction().commit(); - } - - VolumeInfo managedVolumeInfo = volumeOperations.getVolume(VOLUME_FULL_NAME); - assertEquals(VolumeType.MANAGED, managedVolumeInfo.getVolumeType()); - assertEquals(FileUtils.convertRelativePathToURI("/tmp/managed_volume"), managedVolumeInfo.getStorageLocation()); - assertEquals(VOLUME_FULL_NAME, managedVolumeInfo.getFullName()); - assertEquals(VOLUME_NAME, managedVolumeInfo.getName()); - assertEquals(CATALOG_NAME, managedVolumeInfo.getCatalogName()); - assertEquals(SCHEMA_NAME, managedVolumeInfo.getSchemaName()); - assertNotNull(managedVolumeInfo.getCreatedAt()); - assertNotNull(managedVolumeInfo.getUpdatedAt()); - - // List volumes - System.out.println("Testing list managed volumes.."); - Iterable volumeInfosManaged = volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME); - assertEquals(1, getSize(volumeInfosManaged)); - assertTrue(contains(volumeInfosManaged, managedVolumeInfo, (volume) -> { - assertThat(volume.getName()).isNotNull(); - return volume.getName().equals(VOLUME_NAME); - })); - - //NOW Update the schema name - schemaOperations.updateSchema(SCHEMA_FULL_NAME, - new UpdateSchema().newName(SCHEMA_NEW_NAME).comment(SCHEMA_COMMENT)); - // get volume - VolumeInfo volumePostSchemaNameChange = volumeOperations.getVolume - (CATALOG_NAME + "." + SCHEMA_NEW_NAME + "." + VOLUME_NAME); - assertEquals(volumePostSchemaNameChange.getVolumeId(), managedVolumeInfo.getVolumeId()); - - // test delete parent schema when volume exists - assertThrows(Exception.class, () -> schemaOperations.deleteSchema(CATALOG_NAME + "." + SCHEMA_NEW_NAME, - Optional.of(false))); - - // test force delete parent schema when volume exists - schemaOperations.deleteSchema(CATALOG_NAME + "." + SCHEMA_NEW_NAME, Optional.of(true)); - // both schema and volume should be deleted - assertThrows(Exception.class, () -> volumeOperations.getVolume(CATALOG_NAME + "." + SCHEMA_NEW_NAME + "." + VOLUME_NAME)); - assertThrows(Exception.class, () -> schemaOperations.getSchema(CATALOG_NAME + "." + SCHEMA_NEW_NAME)); - - } -} \ No newline at end of file + VolumeInfo managedVolumeInfo = volumeOperations.getVolume(VOLUME_FULL_NAME); + assertEquals(VolumeType.MANAGED, managedVolumeInfo.getVolumeType()); + assertEquals( + FileUtils.convertRelativePathToURI("/tmp/managed_volume"), + managedVolumeInfo.getStorageLocation()); + assertEquals(VOLUME_FULL_NAME, managedVolumeInfo.getFullName()); + assertEquals(VOLUME_NAME, managedVolumeInfo.getName()); + assertEquals(CATALOG_NAME, managedVolumeInfo.getCatalogName()); + assertEquals(SCHEMA_NAME, managedVolumeInfo.getSchemaName()); + assertNotNull(managedVolumeInfo.getCreatedAt()); + assertNotNull(managedVolumeInfo.getUpdatedAt()); + + // List volumes + System.out.println("Testing list managed volumes.."); + Iterable volumeInfosManaged = + volumeOperations.listVolumes(CATALOG_NAME, SCHEMA_NAME); + assertEquals(1, getSize(volumeInfosManaged)); + assertTrue( + contains( + volumeInfosManaged, + managedVolumeInfo, + (volume) -> { + assertThat(volume.getName()).isNotNull(); + return volume.getName().equals(VOLUME_NAME); + })); + + // NOW Update the schema name + schemaOperations.updateSchema( + SCHEMA_FULL_NAME, new UpdateSchema().newName(SCHEMA_NEW_NAME).comment(SCHEMA_COMMENT)); + // get volume + VolumeInfo volumePostSchemaNameChange = + volumeOperations.getVolume(CATALOG_NAME + "." + SCHEMA_NEW_NAME + "." + VOLUME_NAME); + assertEquals(volumePostSchemaNameChange.getVolumeId(), managedVolumeInfo.getVolumeId()); + + // test delete parent schema when volume exists + assertThrows( + Exception.class, + () -> + schemaOperations.deleteSchema( + CATALOG_NAME + "." + SCHEMA_NEW_NAME, Optional.of(false))); + + // test force delete parent schema when volume exists + schemaOperations.deleteSchema(CATALOG_NAME + "." + SCHEMA_NEW_NAME, Optional.of(true)); + // both schema and volume should be deleted + assertThrows( + Exception.class, + () -> volumeOperations.getVolume(CATALOG_NAME + "." + SCHEMA_NEW_NAME + "." + VOLUME_NAME)); + assertThrows( + Exception.class, () -> schemaOperations.getSchema(CATALOG_NAME + "." + SCHEMA_NEW_NAME)); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/base/volume/VolumeOperations.java b/server/src/test/java/io/unitycatalog/server/base/volume/VolumeOperations.java index fc298c2db..de33abdf0 100644 --- a/server/src/test/java/io/unitycatalog/server/base/volume/VolumeOperations.java +++ b/server/src/test/java/io/unitycatalog/server/base/volume/VolumeOperations.java @@ -1,17 +1,20 @@ package io.unitycatalog.server.base.volume; - import io.unitycatalog.client.ApiException; import io.unitycatalog.client.model.CreateVolumeRequestContent; import io.unitycatalog.client.model.UpdateVolumeRequestContent; import io.unitycatalog.client.model.VolumeInfo; - import java.util.List; public interface VolumeOperations { - VolumeInfo createVolume(CreateVolumeRequestContent createVolumeRequest) throws ApiException; - List listVolumes(String catalogName, String schemaName) throws ApiException; - VolumeInfo getVolume(String volumeFullName) throws ApiException; - VolumeInfo updateVolume(String fullName, UpdateVolumeRequestContent updateVolumeRequest) throws ApiException; - void deleteVolume(String volumeFullName) throws ApiException; + VolumeInfo createVolume(CreateVolumeRequestContent createVolumeRequest) throws ApiException; + + List listVolumes(String catalogName, String schemaName) throws ApiException; + + VolumeInfo getVolume(String volumeFullName) throws ApiException; + + VolumeInfo updateVolume(String fullName, UpdateVolumeRequestContent updateVolumeRequest) + throws ApiException; + + void deleteVolume(String volumeFullName) throws ApiException; } diff --git a/server/src/test/java/io/unitycatalog/server/iceberg/IcebergRestCatalogTest.java b/server/src/test/java/io/unitycatalog/server/iceberg/IcebergRestCatalogTest.java index cf36ac8f6..9aae1e2cc 100644 --- a/server/src/test/java/io/unitycatalog/server/iceberg/IcebergRestCatalogTest.java +++ b/server/src/test/java/io/unitycatalog/server/iceberg/IcebergRestCatalogTest.java @@ -1,5 +1,7 @@ package io.unitycatalog.server.iceberg; +import static org.assertj.core.api.Assertions.assertThat; + import com.linecorp.armeria.client.WebClient; import com.linecorp.armeria.common.AggregatedHttpResponse; import com.linecorp.armeria.common.auth.AuthToken; @@ -9,13 +11,19 @@ import io.unitycatalog.server.base.catalog.CatalogOperations; import io.unitycatalog.server.base.schema.SchemaOperations; import io.unitycatalog.server.base.table.TableOperations; -import io.unitycatalog.server.persist.utils.HibernateUtils; import io.unitycatalog.server.persist.dao.TableInfoDAO; +import io.unitycatalog.server.persist.utils.HibernateUtils; import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; import io.unitycatalog.server.sdk.schema.SdkSchemaOperations; import io.unitycatalog.server.sdk.tables.SdkTableOperations; import io.unitycatalog.server.utils.RESTObjectMapper; import io.unitycatalog.server.utils.TestUtils; +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import java.util.UUID; import org.apache.iceberg.catalog.Namespace; import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.exceptions.NoSuchTableException; @@ -30,15 +38,6 @@ import org.junit.Before; import org.junit.Test; -import java.io.IOException; -import java.net.URISyntaxException; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.UUID; - -import static org.assertj.core.api.Assertions.assertThat; - public class IcebergRestCatalogTest extends BaseServerTest { protected CatalogOperations catalogOperations; @@ -54,34 +53,30 @@ public void setUp() { catalogOperations = new SdkCatalogOperations(TestUtils.createApiClient(serverConfig)); schemaOperations = new SdkSchemaOperations(TestUtils.createApiClient(serverConfig)); tableOperations = new SdkTableOperations(TestUtils.createApiClient(serverConfig)); - client = WebClient - .builder(uri) - .auth(AuthToken.ofOAuth2(token)) - .build(); + client = WebClient.builder(uri).auth(AuthToken.ofOAuth2(token)).build(); cleanUp(); } - protected void cleanUp() { - try { - if (catalogOperations.getCatalog(TestUtils.CATALOG_NAME) != null) { - catalogOperations.deleteCatalog(TestUtils.CATALOG_NAME, Optional.of(true)); - } - } catch (Exception e) { - // Ignore + protected void cleanUp() { + try { + if (catalogOperations.getCatalog(TestUtils.CATALOG_NAME) != null) { + catalogOperations.deleteCatalog(TestUtils.CATALOG_NAME, Optional.of(true)); } + } catch (Exception e) { + // Ignore } + } @Test public void testConfig() { - AggregatedHttpResponse resp = - client.get("/v1/config").aggregate().join(); + AggregatedHttpResponse resp = client.get("/v1/config").aggregate().join(); assertThat(resp.contentUtf8()).isEqualTo("{\"defaults\":{},\"overrides\":{}}"); } @Test - public void testNamespaces() - throws ApiException, IOException { - CreateCatalog createCatalog = new CreateCatalog() + public void testNamespaces() throws ApiException, IOException { + CreateCatalog createCatalog = + new CreateCatalog() .name(TestUtils.CATALOG_NAME) .comment(TestUtils.COMMENT) .properties(TestUtils.PROPERTIES); @@ -90,7 +85,8 @@ public void testNamespaces() assertThat(catalogInfo.getComment()).isEqualTo(createCatalog.getComment()); assertThat(catalogInfo.getProperties()).isEqualTo(createCatalog.getProperties()); - CreateSchema createSchema = new CreateSchema() + CreateSchema createSchema = + new CreateSchema() .catalogName(TestUtils.CATALOG_NAME) .name(TestUtils.SCHEMA_NAME) .properties(TestUtils.PROPERTIES); @@ -102,105 +98,145 @@ public void testNamespaces() // GetNamespace for catalog { AggregatedHttpResponse resp = - client.get("/v1/namespaces/" + TestUtils.CATALOG_NAME).aggregate().join(); + client.get("/v1/namespaces/" + TestUtils.CATALOG_NAME).aggregate().join(); assertThat(resp.status().code()).isEqualTo(200); - assertThat(RESTObjectMapper.mapper().readValue(resp.contentUtf8(), GetNamespaceResponse.class)).asString() - .isEqualTo(GetNamespaceResponse.builder() - .withNamespace(Namespace.of(TestUtils.CATALOG_NAME)) - .setProperties(TestUtils.PROPERTIES) - .build() - .toString()); + assertThat( + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), GetNamespaceResponse.class)) + .asString() + .isEqualTo( + GetNamespaceResponse.builder() + .withNamespace(Namespace.of(TestUtils.CATALOG_NAME)) + .setProperties(TestUtils.PROPERTIES) + .build() + .toString()); } // GetNamespace for schema { AggregatedHttpResponse resp = - client.get("/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME) - .aggregate().join(); + client + .get("/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(200); - assertThat(RESTObjectMapper.mapper().readValue(resp.contentUtf8(), GetNamespaceResponse.class)).asString() - .isEqualTo(GetNamespaceResponse.builder() - .withNamespace(Namespace.of(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME)) - .setProperties(TestUtils.PROPERTIES) - .build() - .toString()); + assertThat( + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), GetNamespaceResponse.class)) + .asString() + .isEqualTo( + GetNamespaceResponse.builder() + .withNamespace(Namespace.of(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME)) + .setProperties(TestUtils.PROPERTIES) + .build() + .toString()); } // ListNamespaces from root { - AggregatedHttpResponse resp = - client.get("/v1/namespaces").aggregate().join(); + AggregatedHttpResponse resp = client.get("/v1/namespaces").aggregate().join(); assertThat(resp.status().code()).isEqualTo(200); - assertThat(RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)).asString() - .isEqualTo(ListNamespacesResponse.builder() - .add(Namespace.of(TestUtils.CATALOG_NAME)) - .build() - .toString()); + assertThat( + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)) + .asString() + .isEqualTo( + ListNamespacesResponse.builder() + .add(Namespace.of(TestUtils.CATALOG_NAME)) + .build() + .toString()); } // ListNamespaces from catalog { AggregatedHttpResponse resp = - client.get("/v1/namespaces?parent=" + TestUtils.CATALOG_NAME).aggregate().join(); + client.get("/v1/namespaces?parent=" + TestUtils.CATALOG_NAME).aggregate().join(); assertThat(resp.status().code()).isEqualTo(200); - assertThat(RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)).asString() - .isEqualTo(ListNamespacesResponse.builder() - .add(Namespace.of(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME)) - .build() - .toString()); + assertThat( + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)) + .asString() + .isEqualTo( + ListNamespacesResponse.builder() + .add(Namespace.of(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME)) + .build() + .toString()); } // ListNamespaces from schema { AggregatedHttpResponse resp = - client.get("/v1/namespaces?parent=" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME) - .aggregate().join(); + client + .get("/v1/namespaces?parent=" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(200); - assertThat(RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)).asString() - .isEqualTo(ListNamespacesResponse.builder() - .build() - .toString()); + assertThat( + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListNamespacesResponse.class)) + .asString() + .isEqualTo(ListNamespacesResponse.builder().build().toString()); } } @Test public void testTable() throws ApiException, IOException, URISyntaxException { - CreateCatalog createCatalog = new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT); + CreateCatalog createCatalog = + new CreateCatalog().name(TestUtils.CATALOG_NAME).comment(TestUtils.COMMENT); catalogOperations.createCatalog(createCatalog); schemaOperations.createSchema( - new CreateSchema() - .catalogName(TestUtils.CATALOG_NAME) - .name(TestUtils.SCHEMA_NAME) - ); - ColumnInfo columnInfo1 = new ColumnInfo().name("as_int").typeText("INTEGER") - .typeJson("{\"type\": \"integer\"}") - .typeName(ColumnTypeName.INT).typePrecision(10).typeScale(0).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(TestUtils.TABLE_NAME) - .catalogName(TestUtils.CATALOG_NAME) - .schemaName(TestUtils.SCHEMA_NAME) - .columns(List.of(columnInfo1, columnInfo2)) - .comment(TestUtils.COMMENT) - .storageLocation("/tmp/stagingLocation") - .tableType(TableType.EXTERNAL) - .dataSourceFormat(DataSourceFormat.DELTA); + new CreateSchema().catalogName(TestUtils.CATALOG_NAME).name(TestUtils.SCHEMA_NAME)); + ColumnInfo columnInfo1 = + new ColumnInfo() + .name("as_int") + .typeText("INTEGER") + .typeJson("{\"type\": \"integer\"}") + .typeName(ColumnTypeName.INT) + .typePrecision(10) + .typeScale(0) + .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(TestUtils.TABLE_NAME) + .catalogName(TestUtils.CATALOG_NAME) + .schemaName(TestUtils.SCHEMA_NAME) + .columns(List.of(columnInfo1, columnInfo2)) + .comment(TestUtils.COMMENT) + .storageLocation("/tmp/stagingLocation") + .tableType(TableType.EXTERNAL) + .dataSourceFormat(DataSourceFormat.DELTA); TableInfo tableInfo = tableOperations.createTable(createTableRequest); // Uniform table doesn't exist at this point { AggregatedHttpResponse resp = - client.head( - "/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME + "/tables/" + - TestUtils.TABLE_NAME).aggregate().join(); + client + .head( + "/v1/namespaces/" + + TestUtils.CATALOG_NAME + + "." + + TestUtils.SCHEMA_NAME + + "/tables/" + + TestUtils.TABLE_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(404); } { AggregatedHttpResponse resp = - client.get( - "/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME + "/tables/" + - TestUtils.TABLE_NAME).aggregate().join(); + client + .get( + "/v1/namespaces/" + + TestUtils.CATALOG_NAME + + "." + + TestUtils.SCHEMA_NAME + + "/tables/" + + TestUtils.TABLE_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(404); ErrorResponse errorResponse = ErrorResponseParser.fromJson(resp.contentUtf8()); assertThat(errorResponse.type()).isEqualTo(NoSuchTableException.class.getSimpleName()); @@ -212,8 +248,8 @@ public void testTable() throws ApiException, IOException, URISyntaxException { TableInfoDAO tableInfoDAO = TableInfoDAO.builder().build(); assertThat(tableInfo.getTableId()).isNotNull(); session.load(tableInfoDAO, UUID.fromString(tableInfo.getTableId())); - String metadataLocation = Objects.requireNonNull( - this.getClass().getResource("/metadata.json")).toURI().toString(); + String metadataLocation = + Objects.requireNonNull(this.getClass().getResource("/metadata.json")).toURI().toString(); tableInfoDAO.setUniformIcebergMetadataLocation(metadataLocation); session.merge(tableInfoDAO); tx.commit(); @@ -222,39 +258,64 @@ public void testTable() throws ApiException, IOException, URISyntaxException { // Now the uniform table exists { AggregatedHttpResponse resp = - client.head( - "/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME + "/tables/" + - TestUtils.TABLE_NAME).aggregate().join(); + client + .head( + "/v1/namespaces/" + + TestUtils.CATALOG_NAME + + "." + + TestUtils.SCHEMA_NAME + + "/tables/" + + TestUtils.TABLE_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(200); } // metadata is valid metadata content and metadata location matches { AggregatedHttpResponse resp = - client.get( - "/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME + "/tables/" + - TestUtils.TABLE_NAME).aggregate().join(); + client + .get( + "/v1/namespaces/" + + TestUtils.CATALOG_NAME + + "." + + TestUtils.SCHEMA_NAME + + "/tables/" + + TestUtils.TABLE_NAME) + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(200); LoadTableResponse loadTableResponse = - RESTObjectMapper.mapper().readValue(resp.contentUtf8(), LoadTableResponse.class); + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), LoadTableResponse.class); assertThat(loadTableResponse.tableMetadata().metadataFileLocation()) - .isEqualTo(this.getClass().getResource("/metadata.json").toURI().toString()); + .isEqualTo(this.getClass().getResource("/metadata.json").toURI().toString()); } // List uniform tables { AggregatedHttpResponse resp = - client.get( - "/v1/namespaces/" + TestUtils.CATALOG_NAME + "." + TestUtils.SCHEMA_NAME + "/tables").aggregate().join(); + client + .get( + "/v1/namespaces/" + + TestUtils.CATALOG_NAME + + "." + + TestUtils.SCHEMA_NAME + + "/tables") + .aggregate() + .join(); assertThat(resp.status().code()).isEqualTo(200); ListTablesResponse loadTableResponse = - RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListTablesResponse.class); - assertThat(loadTableResponse.identifiers()).containsExactly(TableIdentifier.of(TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME, TestUtils.TABLE_NAME)); + RESTObjectMapper.mapper().readValue(resp.contentUtf8(), ListTablesResponse.class); + assertThat(loadTableResponse.identifiers()) + .containsExactly( + TableIdentifier.of( + TestUtils.CATALOG_NAME, TestUtils.SCHEMA_NAME, TestUtils.TABLE_NAME)); } } @Test public void testLoadTablesInvalidNamespace() { - AggregatedHttpResponse resp = client.get("/v1/namespaces/incomplete_namespace/tables/some_table").aggregate().join(); + AggregatedHttpResponse resp = + client.get("/v1/namespaces/incomplete_namespace/tables/some_table").aggregate().join(); assertThat(resp.status().code()).isEqualTo(400); ErrorResponse errorResponse = ErrorResponseParser.fromJson(resp.contentUtf8()); assertThat(errorResponse.type()).isEqualTo(IllegalArgumentException.class.getSimpleName()); @@ -262,7 +323,8 @@ public void testLoadTablesInvalidNamespace() { @Test public void testListTablesInvalidNamespace() { - AggregatedHttpResponse resp = client.get("/v1/namespaces/incomplete_namespace/tables").aggregate().join(); + AggregatedHttpResponse resp = + client.get("/v1/namespaces/incomplete_namespace/tables").aggregate().join(); assertThat(resp.status().code()).isEqualTo(400); ErrorResponse errorResponse = ErrorResponseParser.fromJson(resp.contentUtf8()); assertThat(errorResponse.type()).isEqualTo(IllegalArgumentException.class.getSimpleName()); @@ -270,7 +332,8 @@ public void testListTablesInvalidNamespace() { @Test public void testTableExistsInvalidNamespace() { - AggregatedHttpResponse resp = client.head("/v1/namespaces/incomplete_namespace/tables").aggregate().join(); + AggregatedHttpResponse resp = + client.head("/v1/namespaces/incomplete_namespace/tables").aggregate().join(); assertThat(resp.status().code()).isEqualTo(400); } } diff --git a/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogCRUDTest.java b/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogCRUDTest.java index 5a858880f..37298bda7 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogCRUDTest.java @@ -7,8 +7,8 @@ public class SdkCatalogCRUDTest extends BaseCatalogCRUDTest { - @Override - protected CatalogOperations createCatalogOperations(ServerConfig config) { - return new SdkCatalogOperations(TestUtils.createApiClient(config)); - } + @Override + protected CatalogOperations createCatalogOperations(ServerConfig config) { + return new SdkCatalogOperations(TestUtils.createApiClient(config)); + } } diff --git a/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogOperations.java b/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogOperations.java index 0c9c3f333..3ead90772 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogOperations.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/catalog/SdkCatalogOperations.java @@ -1,8 +1,5 @@ package io.unitycatalog.server.sdk.catalog; -import java.util.List; -import java.util.Optional; - import io.unitycatalog.client.ApiClient; import io.unitycatalog.client.ApiException; import io.unitycatalog.client.api.CatalogsApi; @@ -10,37 +7,38 @@ import io.unitycatalog.client.model.CreateCatalog; import io.unitycatalog.client.model.UpdateCatalog; import io.unitycatalog.server.base.catalog.CatalogOperations; +import java.util.List; +import java.util.Optional; public class SdkCatalogOperations implements CatalogOperations { - private final CatalogsApi catalogsApi; - - public SdkCatalogOperations(ApiClient apiClient) { - this.catalogsApi = new CatalogsApi(apiClient); - } - - @Override - public CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException { - return catalogsApi.createCatalog(createCatalog); - } - - @Override - public List listCatalogs() throws ApiException { - return catalogsApi.listCatalogs(null, 100).getCatalogs(); - } - - @Override - public CatalogInfo getCatalog(String name) throws ApiException { - return catalogsApi.getCatalog(name); - } - - @Override - public CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException { - return catalogsApi.updateCatalog(name, updateCatalog); - } - - @Override - public void deleteCatalog(String name, Optional force) throws ApiException { - catalogsApi.deleteCatalog(name, force.orElse(false)); - } - -} \ No newline at end of file + private final CatalogsApi catalogsApi; + + public SdkCatalogOperations(ApiClient apiClient) { + this.catalogsApi = new CatalogsApi(apiClient); + } + + @Override + public CatalogInfo createCatalog(CreateCatalog createCatalog) throws ApiException { + return catalogsApi.createCatalog(createCatalog); + } + + @Override + public List listCatalogs() throws ApiException { + return catalogsApi.listCatalogs(null, 100).getCatalogs(); + } + + @Override + public CatalogInfo getCatalog(String name) throws ApiException { + return catalogsApi.getCatalog(name); + } + + @Override + public CatalogInfo updateCatalog(String name, UpdateCatalog updateCatalog) throws ApiException { + return catalogsApi.updateCatalog(name, updateCatalog); + } + + @Override + public void deleteCatalog(String name, Optional force) throws ApiException { + catalogsApi.deleteCatalog(name, force.orElse(false)); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionCRUDTest.java b/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionCRUDTest.java index 80aabdd2f..a68983585 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionCRUDTest.java @@ -5,24 +5,23 @@ import io.unitycatalog.server.base.function.BaseFunctionCRUDTest; import io.unitycatalog.server.base.function.FunctionOperations; import io.unitycatalog.server.base.schema.SchemaOperations; +import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; import io.unitycatalog.server.sdk.schema.SdkSchemaOperations; import io.unitycatalog.server.utils.TestUtils; -import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; public class SdkFunctionCRUDTest extends BaseFunctionCRUDTest { - @Override - protected CatalogOperations createCatalogOperations(ServerConfig config) { - return new SdkCatalogOperations(TestUtils.createApiClient(config)); - } + @Override + protected CatalogOperations createCatalogOperations(ServerConfig config) { + return new SdkCatalogOperations(TestUtils.createApiClient(config)); + } - @Override - protected SchemaOperations createSchemaOperations(ServerConfig config) { - return new SdkSchemaOperations(TestUtils.createApiClient(config)); - } + @Override + protected SchemaOperations createSchemaOperations(ServerConfig config) { + return new SdkSchemaOperations(TestUtils.createApiClient(config)); + } - @Override - protected FunctionOperations createFunctionOperations(ServerConfig config) { - return new SdkFunctionOperations(TestUtils.createApiClient(config)); - } + @Override + protected FunctionOperations createFunctionOperations(ServerConfig config) { + return new SdkFunctionOperations(TestUtils.createApiClient(config)); + } } - diff --git a/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionOperations.java b/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionOperations.java index a02b1ade1..c1062543e 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionOperations.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/function/SdkFunctionOperations.java @@ -7,36 +7,38 @@ import io.unitycatalog.client.model.FunctionInfo; import io.unitycatalog.server.base.function.FunctionOperations; import io.unitycatalog.server.utils.TestUtils; - import java.util.List; import java.util.Objects; public class SdkFunctionOperations implements FunctionOperations { - private final FunctionsApi functionsAPI; - - public SdkFunctionOperations(ApiClient apiClient) { - this.functionsAPI = new FunctionsApi(apiClient); - } - - @Override - public FunctionInfo createFunction(CreateFunctionRequest createFunctionRequest) throws ApiException { - return functionsAPI.createFunction(createFunctionRequest); - } - - @Override - public List listFunctions(String catalogName, String schemaName) throws ApiException { - return TestUtils.toList(Objects.requireNonNull(functionsAPI - .listFunctions(catalogName, schemaName, 100, null).getFunctions())); - } - - @Override - public FunctionInfo getFunction(String functionFullName) throws ApiException { - return functionsAPI.getFunction(functionFullName); - } - - @Override - public void deleteFunction(String functionFullName, boolean force) throws ApiException { - functionsAPI.deleteFunction(functionFullName); - } -} \ No newline at end of file + private final FunctionsApi functionsAPI; + + public SdkFunctionOperations(ApiClient apiClient) { + this.functionsAPI = new FunctionsApi(apiClient); + } + + @Override + public FunctionInfo createFunction(CreateFunctionRequest createFunctionRequest) + throws ApiException { + return functionsAPI.createFunction(createFunctionRequest); + } + + @Override + public List listFunctions(String catalogName, String schemaName) + throws ApiException { + return TestUtils.toList( + Objects.requireNonNull( + functionsAPI.listFunctions(catalogName, schemaName, 100, null).getFunctions())); + } + + @Override + public FunctionInfo getFunction(String functionFullName) throws ApiException { + return functionsAPI.getFunction(functionFullName); + } + + @Override + public void deleteFunction(String functionFullName, boolean force) throws ApiException { + functionsAPI.deleteFunction(functionFullName); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaCRUDTest.java b/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaCRUDTest.java index 94af640ba..8c3d0ab6f 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaCRUDTest.java @@ -2,22 +2,20 @@ import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.base.catalog.CatalogOperations; -import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; -import org.junit.AfterClass; -import org.junit.BeforeClass; import io.unitycatalog.server.base.schema.BaseSchemaCRUDTest; import io.unitycatalog.server.base.schema.SchemaOperations; +import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; import io.unitycatalog.server.utils.TestUtils; public class SdkSchemaCRUDTest extends BaseSchemaCRUDTest { - @Override - protected CatalogOperations createCatalogOperations(ServerConfig config) { - return new SdkCatalogOperations(TestUtils.createApiClient(config)); - } + @Override + protected CatalogOperations createCatalogOperations(ServerConfig config) { + return new SdkCatalogOperations(TestUtils.createApiClient(config)); + } - @Override - protected SchemaOperations createSchemaOperations(ServerConfig config) { - return new SdkSchemaOperations(TestUtils.createApiClient(config)); - } -} \ No newline at end of file + @Override + protected SchemaOperations createSchemaOperations(ServerConfig config) { + return new SdkSchemaOperations(TestUtils.createApiClient(config)); + } +} diff --git a/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaOperations.java b/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaOperations.java index 4b8b1f446..7f2cccdc3 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaOperations.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/schema/SdkSchemaOperations.java @@ -7,41 +7,38 @@ import io.unitycatalog.client.model.SchemaInfo; import io.unitycatalog.client.model.UpdateSchema; import io.unitycatalog.server.base.schema.SchemaOperations; - import java.util.List; import java.util.Optional; -import static io.unitycatalog.server.utils.TestUtils.toList; - public class SdkSchemaOperations implements SchemaOperations { - private final SchemasApi schemasApi; - - public SdkSchemaOperations(ApiClient apiClient) { - this.schemasApi = new SchemasApi(apiClient); - } - - @Override - public SchemaInfo createSchema(CreateSchema createSchema) throws ApiException { - return schemasApi.createSchema(createSchema); - } - - @Override - public List listSchemas(String catalogName) throws ApiException { - return schemasApi.listSchemas(catalogName , 100, null).getSchemas(); - } - - @Override - public SchemaInfo getSchema(String schemaFullName) throws ApiException { - return schemasApi.getSchema(schemaFullName); - } - - @Override - public SchemaInfo updateSchema(String fullName, UpdateSchema updateSchema) throws ApiException { - return schemasApi.updateSchema(fullName, updateSchema); - } - - @Override - public void deleteSchema(String schemaFullName, Optional force) throws ApiException { - schemasApi.deleteSchema(schemaFullName, force.orElse(false)); - } + private final SchemasApi schemasApi; + + public SdkSchemaOperations(ApiClient apiClient) { + this.schemasApi = new SchemasApi(apiClient); + } + + @Override + public SchemaInfo createSchema(CreateSchema createSchema) throws ApiException { + return schemasApi.createSchema(createSchema); + } + + @Override + public List listSchemas(String catalogName) throws ApiException { + return schemasApi.listSchemas(catalogName, 100, null).getSchemas(); + } + + @Override + public SchemaInfo getSchema(String schemaFullName) throws ApiException { + return schemasApi.getSchema(schemaFullName); + } + + @Override + public SchemaInfo updateSchema(String fullName, UpdateSchema updateSchema) throws ApiException { + return schemasApi.updateSchema(fullName, updateSchema); + } + + @Override + public void deleteSchema(String schemaFullName, Optional force) throws ApiException { + schemasApi.deleteSchema(schemaFullName, force.orElse(false)); + } } diff --git a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableCRUDTest.java b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableCRUDTest.java index 85fb7701b..d7440f5e3 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableCRUDTest.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableCRUDTest.java @@ -1,58 +1,59 @@ package io.unitycatalog.server.sdk.tables; +import static org.assertj.core.api.Assertions.assertThat; + import io.unitycatalog.client.api.TablesApi; import io.unitycatalog.client.model.ListTablesResponse; import io.unitycatalog.client.model.TableInfo; import io.unitycatalog.server.base.ServerConfig; import io.unitycatalog.server.base.catalog.CatalogOperations; -import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; -import org.junit.AfterClass; -import org.junit.BeforeClass; import io.unitycatalog.server.base.schema.SchemaOperations; import io.unitycatalog.server.base.table.BaseTableCRUDTest; import io.unitycatalog.server.base.table.TableOperations; +import io.unitycatalog.server.sdk.catalog.SdkCatalogOperations; import io.unitycatalog.server.sdk.schema.SdkSchemaOperations; import io.unitycatalog.server.utils.TestUtils; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; - public class SdkTableCRUDTest extends BaseTableCRUDTest { - @Override - protected CatalogOperations createCatalogOperations(ServerConfig config) { - return new SdkCatalogOperations(TestUtils.createApiClient(config)); - } - - @Override - protected SchemaOperations createSchemaOperations(ServerConfig config) { - return new SdkSchemaOperations(TestUtils.createApiClient(config)); - } - - @Override - protected TableOperations createTableOperations(ServerConfig config) { - localTablesApi = new TablesApi(TestUtils.createApiClient(config)); - return new SdkTableOperations(TestUtils.createApiClient(config)); - } - - /** - * The SDK tests elide the `Response` object and directly return the model object. - * However, clients can interact with the REST API directly, so its signature needs to be tested as well. - *

- * The tests below use a direct `TableAPI` client to inspect the response object. - */ - private TablesApi localTablesApi; - - @Test - public void testListTablesWithNoNextPageTokenShouldReturnNull() throws Exception { - createCommonResources(); - TableInfo testingTable = createDefaultTestingTable(); - ListTablesResponse resp = localTablesApi.listTables(testingTable.getCatalogName(), testingTable.getSchemaName(), 100, null); - assertThat(resp.getNextPageToken()).isNull(); - assertThat(resp.getTables()).hasSize(1) - .first() - .usingRecursiveComparison() - .ignoringFields("columns", "storageLocation") - .isEqualTo(testingTable); - } + @Override + protected CatalogOperations createCatalogOperations(ServerConfig config) { + return new SdkCatalogOperations(TestUtils.createApiClient(config)); + } + + @Override + protected SchemaOperations createSchemaOperations(ServerConfig config) { + return new SdkSchemaOperations(TestUtils.createApiClient(config)); + } + + @Override + protected TableOperations createTableOperations(ServerConfig config) { + localTablesApi = new TablesApi(TestUtils.createApiClient(config)); + return new SdkTableOperations(TestUtils.createApiClient(config)); + } + + /** + * The SDK tests elide the `Response` object and directly return the model object. However, + * clients can interact with the REST API directly, so its signature needs to be tested as well. + * + *

The tests below use a direct `TableAPI` client to inspect the response object. + */ + private TablesApi localTablesApi; + + @Test + public void testListTablesWithNoNextPageTokenShouldReturnNull() throws Exception { + createCommonResources(); + TableInfo testingTable = createDefaultTestingTable(); + ListTablesResponse resp = + localTablesApi.listTables( + testingTable.getCatalogName(), testingTable.getSchemaName(), 100, null); + assertThat(resp.getNextPageToken()).isNull(); + assertThat(resp.getTables()) + .hasSize(1) + .first() + .usingRecursiveComparison() + .ignoringFields("columns", "storageLocation") + .isEqualTo(testingTable); + } } diff --git a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java index 8f6cf89a7..76f6ab5b8 100644 --- a/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java +++ b/server/src/test/java/io/unitycatalog/server/sdk/tables/SdkTableOperations.java @@ -3,41 +3,38 @@ import io.unitycatalog.client.ApiClient; import io.unitycatalog.client.ApiException; import io.unitycatalog.client.api.TablesApi; -import io.unitycatalog.client.model.TableInfo; import io.unitycatalog.client.model.CreateTable; +import io.unitycatalog.client.model.TableInfo; import io.unitycatalog.server.base.table.TableOperations; import io.unitycatalog.server.utils.TestUtils; - import java.util.List; import java.util.Objects; public class SdkTableOperations implements TableOperations { - private final TablesApi tablesApi; - public SdkTableOperations(ApiClient apiClient) { - this.tablesApi = new TablesApi(apiClient); - } - - public TableInfo createTable(CreateTable createTableRequest) throws ApiException { - return tablesApi.createTable(createTableRequest); - } - - @Override - public List listTables(String catalogName, String schemaName) throws ApiException { - return TestUtils.toList(Objects.requireNonNull(tablesApi.listTables( - catalogName, - schemaName, - 100, - null).getTables())); - } - - @Override - public TableInfo getTable(String tableFullName) throws ApiException { - return tablesApi.getTable(tableFullName); - } - - @Override - public void deleteTable(String tableFullName) throws ApiException { - tablesApi.deleteTable(tableFullName); - } - + private final TablesApi tablesApi; + + public SdkTableOperations(ApiClient apiClient) { + this.tablesApi = new TablesApi(apiClient); + } + + public TableInfo createTable(CreateTable createTableRequest) throws ApiException { + return tablesApi.createTable(createTableRequest); + } + + @Override + public List listTables(String catalogName, String schemaName) throws ApiException { + return TestUtils.toList( + Objects.requireNonNull( + tablesApi.listTables(catalogName, schemaName, 100, null).getTables())); + } + + @Override + public TableInfo getTable(String tableFullName) throws ApiException { + return tablesApi.getTable(tableFullName); + } + + @Override + public void deleteTable(String tableFullName) throws ApiException { + tablesApi.deleteTable(tableFullName); + } }