World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#219] test: Improve E2E metalake tests (#409)
Qi Yuf7015d2bd7a6
diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.javaindex 6813893489..936a96f35c 100644--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/CatalogHiveIT.java@@ -51,7 +51,6 @@ public class CatalogHiveIT extends AbstractIT {public static String HIVE_COL_NAME1 = "hive_col_name1";public static String HIVE_COL_NAME2 = "hive_col_name2";public static String HIVE_COL_NAME3 = "hive_col_name3";-static String HIVE_METASTORE_URIS = "thrift://localhost:9083";private static HiveClientPool hiveClientPool;@@ -62,10 +61,8 @@ public class CatalogHiveIT extends AbstractIT {@BeforeAllpublic static void startup() throws Exception {- HiveConf hiveConf = new HiveConf();- hiveConf.set(HiveConf.ConfVars.METASTOREURIS.varname, HIVE_METASTORE_URIS);+ HiveConf hiveConf = GravitonITUtils.hiveConfig();hiveClientPool = new HiveClientPool(1, hiveConf);-createMetalake();createCatalog();createSchema();diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.javaindex 2d19af737c..1db1b36b97 100644--- a/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/e2e/MetalakeIT.java@@ -4,124 +4,186 @@*/package com.datastrato.graviton.integration.e2e;+import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertFalse;+import static org.junit.jupiter.api.Assertions.assertThrows;+import static org.junit.jupiter.api.Assertions.assertTrue;+import com.datastrato.graviton.MetalakeChange;import com.datastrato.graviton.NameIdentifier;import com.datastrato.graviton.client.GravitonMetaLake;-import com.datastrato.graviton.dto.MetalakeDTO;+import com.datastrato.graviton.exceptions.IllegalNameIdentifierException;+import com.datastrato.graviton.exceptions.IllegalNamespaceException;import com.datastrato.graviton.exceptions.MetalakeAlreadyExistsException;import com.datastrato.graviton.exceptions.NoSuchMetalakeException;import com.datastrato.graviton.integration.util.AbstractIT;import com.datastrato.graviton.integration.util.GravitonITUtils;-import java.util.Arrays;+import java.util.ArrayList;import java.util.Collections;-import java.util.List;-import java.util.stream.Collectors;-import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.AfterEach;import org.junit.jupiter.api.Assertions;-import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.BeforeEach;import org.junit.jupiter.api.MethodOrderer;-import org.junit.jupiter.api.Order;import org.junit.jupiter.api.Test;import org.junit.jupiter.api.TestMethodOrder;@TestMethodOrder(MethodOrderer.OrderAnnotation.class)public class MetalakeIT extends AbstractIT {- public static String metalakeName = GravitonITUtils.genRandomName("metalake");-- @BeforeAll- private static void start() {- // Prepare create a metalake test record,- // This way it can support `Run all tests` or `Run test in separated` to test `list`, `load`,- // `alter`, `drop` methods.- createMetalake();+ public static String metalakeNameA = GravitonITUtils.genRandomName("metalakeA");+ public static String metalakeNameB = GravitonITUtils.genRandomName("metalakeB");++ @BeforeEach+ private void start() {+ // Just in case clean up is needed due to a test failure+ dropMetalakes();}- @AfterAll- private static void stop() {- // Always drop the test record here.- // This allows metalake to be safe deleted metalake when `Run all tests` or `Run test in- // separated`- dropMetalake();+ @AfterEach+ private void stop() {+ dropMetalakes();}- @Order(1)@Testpublic void testListMetalake() {+ // no metalakes to start withGravitonMetaLake[] metaLakes = client.listMetalakes();- List<MetalakeDTO> result =- Arrays.stream(metaLakes)- .filter(metalakeDTO -> metalakeDTO.name().equals(metalakeName))- .collect(Collectors.toList());-- Assertions.assertEquals(result.size(), 1);+ assertEquals(0, metaLakes.length);++ // one metalakes+ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());+ metaLakes = client.listMetalakes();+ assertEquals(1, metaLakes.length);+ assertEquals(metaLakes[0].name(), metalakeNameA);++ // two metalakes+ client.createMetalake(+ NameIdentifier.parse(metalakeNameB), "metalake B comment", Collections.emptyMap());+ metaLakes = client.listMetalakes();+ ArrayList<String> names = new ArrayList<>(2);+ assertEquals(2, metaLakes.length);+ names.add(metaLakes[0].name());+ names.add(metaLakes[1].name());+ assertTrue(names.contains(metalakeNameA));+ assertTrue(names.contains(metalakeNameB));}- @Order(2)@Testpublic void testLoadMetalake() {- GravitonMetaLake metaLake = client.loadMetalake(NameIdentifier.of(metalakeName));- Assertions.assertEquals(metaLake.name(), metalakeName);+ // metalake exists+ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());+ GravitonMetaLake metaLakeA = client.loadMetalake(NameIdentifier.of(metalakeNameA));+ assertEquals(metaLakeA.name(), metalakeNameA);++ // metalake does not exist+ assertThrows(+ NoSuchMetalakeException.class, () -> client.loadMetalake(NameIdentifier.of(metalakeNameB)));++ // metalake empty name+ assertThrows(+ IllegalNameIdentifierException.class, () -> client.loadMetalake(NameIdentifier.of("")));++ // metalake bad name+ assertThrows(+ IllegalNamespaceException.class,+ () -> client.loadMetalake(NameIdentifier.of("A", "B", "C")));}- @Order(3)@Testpublic void testAlterMetalake() {- String alterMetalakeName = GravitonITUtils.genRandomName("metalake");+ String newName = GravitonITUtils.genRandomName("newmetaname");++ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());++ MetalakeChange[] changes =+ new MetalakeChange[] {+ MetalakeChange.rename(newName), MetalakeChange.updateComment("new metalake comment")+ };+ GravitonMetaLake metaLake = client.alterMetalake(NameIdentifier.of(metalakeNameA), changes);+ assertEquals(newName, metaLake.name());+ assertEquals("new metalake comment", metaLake.comment());+ assertEquals("graviton", metaLake.auditInfo().creator());++ // Reload metadata via new name to check if the changes are applied+ GravitonMetaLake newMetalake = client.loadMetalake(NameIdentifier.of(newName));+ assertEquals(newName, newMetalake.name());+ assertEquals("new metalake comment", newMetalake.comment());++ // Old name does not exist+ assertThrows(+ NoSuchMetalakeException.class, () -> client.loadMetalake(NameIdentifier.of(metalakeNameA)));+ }++ @Test+ public void testAlterNonExistantMetalake() {+ String newName = GravitonITUtils.genRandomName("newmetaname");++ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());- // TODO: Add more test cases for alter metalake- MetalakeChange[] changes1 =+ MetalakeChange[] changes =new MetalakeChange[] {- MetalakeChange.rename(alterMetalakeName), MetalakeChange.updateComment("newComment")+ MetalakeChange.rename(newName), MetalakeChange.updateComment("new metalake comment")};- GravitonMetaLake metaLake = client.alterMetalake(NameIdentifier.of(metalakeName), changes1);- Assertions.assertEquals(alterMetalakeName, metaLake.name());- Assertions.assertEquals("newComment", metaLake.comment());- Assertions.assertEquals("graviton", metaLake.auditInfo().creator());-- // Reload metatada from backend to check if the changes are applied- GravitonMetaLake metaLake1 = client.loadMetalake(NameIdentifier.of(alterMetalakeName));- Assertions.assertEquals(alterMetalakeName, metaLake1.name());- Assertions.assertEquals("newComment", metaLake1.comment());- Assertions.assertEquals("graviton", metaLake1.auditInfo().creator());-- // Test return not found- Throwable excep =- Assertions.assertThrows(- NoSuchMetalakeException.class,- () -> client.alterMetalake(NameIdentifier.of(metalakeName + "mock"), changes1));- Assertions.assertTrue(excep.getMessage().contains("does not exist"));-- // Restore test record- MetalakeChange[] changes2 = new MetalakeChange[] {MetalakeChange.rename(metalakeName)};- client.alterMetalake(NameIdentifier.of(alterMetalakeName), changes2);++ // rename non existent metalake+ assertThrows(+ NoSuchMetalakeException.class,+ () -> client.alterMetalake(NameIdentifier.of(metalakeNameB), changes));}- public static void createMetalake() {- GravitonMetaLake metaLake =+ @Test+ public void testCreateMetalake() {+ GravitonMetaLake metaLakeA =client.createMetalake(- NameIdentifier.parse(metalakeName), "comment", Collections.emptyMap());- Assertions.assertEquals(metalakeName, metaLake.name());- Assertions.assertEquals("comment", metaLake.comment());- Assertions.assertEquals("graviton", metaLake.auditInfo().creator());+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());+ GravitonMetaLake metalake = client.loadMetalake(NameIdentifier.of(metalakeNameA));+ assertEquals(metalakeNameA, metalake.name());+ assertEquals("metalake A comment", metalake.comment());+ assertEquals("graviton", metalake.auditInfo().creator());// Test metalake name already exists- Throwable excep =- Assertions.assertThrows(- MetalakeAlreadyExistsException.class,- () ->- client.createMetalake(- NameIdentifier.parse(metalakeName), "comment", Collections.emptyMap()));- Assertions.assertTrue(excep.getMessage().contains("already exists"));+ assertThrows(+ MetalakeAlreadyExistsException.class,+ () ->+ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap()));}- public static void dropMetalake() {- Assertions.assertTrue(client.dropMetalake(NameIdentifier.of(metalakeName)));+ @Test+ public void testDropMetalakes() {+ GravitonMetaLake metalakeA =+ client.createMetalake(+ NameIdentifier.parse(metalakeNameA), "metalake A comment", Collections.emptyMap());+ assertTrue(client.dropMetalake(NameIdentifier.of(metalakeA.name())));+ assertThrows(+ NoSuchMetalakeException.class, () -> client.loadMetalake(NameIdentifier.of(metalakeNameA)));++ // Metalake does not exist, so we return false+ assertFalse(client.dropMetalake(NameIdentifier.of(metalakeA.name())));- // Reload metatada from backend to check if the drop are applied- Assertions.assertThrows(- NoSuchMetalakeException.class, () -> client.loadMetalake(NameIdentifier.of(metalakeName)));+ // Bad metalake name+ assertThrows(+ IllegalNamespaceException.class, () -> client.dropMetalake(NameIdentifier.of("A", "B")));+ }- // Return false if the metalake has been dropped already- Assertions.assertFalse(client.dropMetalake(NameIdentifier.of(metalakeName)));+ public void dropMetalakes() {+ GravitonMetaLake[] metaLakes = client.listMetalakes();+ for (GravitonMetaLake metalake : metaLakes) {+ assertTrue(client.dropMetalake(NameIdentifier.of(metalake.name())));+ }++ // Reload metadata from backend to check if the drop operations are applied+ for (GravitonMetaLake metalake : metaLakes) {+ Assertions.assertThrows(+ NoSuchMetalakeException.class,+ () -> client.loadMetalake(NameIdentifier.of(metalake.name())));+ }++ for (GravitonMetaLake metalake : metaLakes) {+ Assertions.assertFalse(client.dropMetalake(NameIdentifier.of(metalake.name())));+ }}}diff --git a/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java b/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.javaindex d88c326dae..d260d8d5d0 100644--- a/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java+++ b/integration-test/src/test/java/com/datastrato/graviton/integration/util/GravitonITUtils.java@@ -4,13 +4,22 @@*/package com.datastrato.graviton.integration.util;+import com.google.common.collect.Maps;+import java.util.Map;import java.util.UUID;+import org.apache.hadoop.hive.conf.HiveConf;import org.slf4j.Logger;import org.slf4j.LoggerFactory;public class GravitonITUtils {public static final Logger LOG = LoggerFactory.getLogger(GravitonITUtils.class);+ public static String HIVE_METASTORE_URIS = "thrift://localhost:9083";++ private GravitonITUtils() {+ throw new IllegalStateException("Utility class");+ }+public static void startGravitonServer() {CommandExecutor.executeCommandLocalHost(System.getenv("GRAVITON_HOME") + "/bin/graviton.sh start",@@ -47,4 +56,22 @@ public class GravitonITUtils {public static String genRandomName(String prefix) {return prefix + "_" + UUID.randomUUID().toString().replace("-", "");}++ public static HiveConf hiveConfig() {+ HiveConf hiveConf = new HiveConf();+ hiveConf.set(HiveConf.ConfVars.METASTOREURIS.varname, HIVE_METASTORE_URIS);++ return hiveConf;+ }++ public static Map<String, String> hiveConfigProperties() {+ Map<String, String> catalogProps = Maps.newHashMap();+ catalogProps.put("provider", "hive");+ catalogProps.put(HiveConf.ConfVars.METASTOREURIS.varname, HIVE_METASTORE_URIS);+ catalogProps.put(HiveConf.ConfVars.METASTORETHRIFTCONNECTIONRETRIES.varname, "30");+ catalogProps.put(HiveConf.ConfVars.METASTORETHRIFTFAILURERETRIES.varname, "30");+ catalogProps.put(HiveConf.ConfVars.METASTORE_CLIENT_CONNECT_RETRY_DELAY.varname, "5");++ return catalogProps;+ }}