diff --git a/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceFunctionalTest.java b/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceFunctionalTest.java index 476396d9d..ee145129b 100644 --- a/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceFunctionalTest.java +++ b/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceFunctionalTest.java @@ -28,8 +28,7 @@ @Slf4j @ExtendWith(SpringExtension.class) @SpringBootTest(classes = {PolarisPersistenceConfig.class}) -@ActiveProfiles(profiles = {"polarisconnectortest"}) -@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) +@ActiveProfiles(profiles = {"polaris_functional_test"}) @AutoConfigureDataJpa public class PolarisConnectorDatabaseServiceFunctionalTest extends PolarisConnectorDatabaseServiceTest { private void simulateDelay() { @@ -48,56 +47,56 @@ private void simulateDelay() { public void testSimpleListDb() { final DatabaseInfo db1 = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).uri("uri1").build(); final DatabaseInfo db2 = DatabaseInfo.builder().name(DB2_QUALIFIED_NAME).uri("uri2").build(); - polarisDBService.create(requestContext, db1); - polarisDBService.create(requestContext, db2); - Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); - Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); + getPolarisDBService().create(getRequestContext(), db1); + getPolarisDBService().create(getRequestContext(), db2); + Assert.assertTrue(getPolarisDBService().exists(getRequestContext(), DB1_QUALIFIED_NAME)); + Assert.assertTrue(getPolarisDBService().exists(getRequestContext(), DB2_QUALIFIED_NAME)); // Since now list dbs use follower_read_timestamp, we will not immediately get the newly created dbs List dbNames = - polarisDBService.listNames( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); + getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); Assert.assertEquals(Sets.newHashSet(dbNames), Sets.newHashSet(DB1_QUALIFIED_NAME, DB2_QUALIFIED_NAME)); List dbs = - polarisDBService.list( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); + getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); Assert.assertTrue("Expected dbNames to be empty", dbNames.isEmpty()); Assert.assertTrue("Expected dbs to be empty", dbs.isEmpty()); // After sufficient time, the dbs should return using follower_read_timestamp simulateDelay(); - dbNames = polarisDBService.listNames( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); + dbNames = getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); Assert.assertEquals(dbNames, Arrays.asList(DB1_QUALIFIED_NAME, DB2_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); + dbs = getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); Assert.assertEquals(dbs, Arrays.asList(db1, db2)); // Test Prefix - dbNames = polarisDBService.listNames( - requestContext, + dbNames = getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), QualifiedName.ofDatabase(CATALOG_NAME, "db"), null, null); Assert.assertEquals(dbNames, Arrays.asList(DB1_QUALIFIED_NAME, DB2_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, + dbs = getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), QualifiedName.ofDatabase(CATALOG_NAME, "db"), null, null); Assert.assertEquals(dbs, Arrays.asList(db1, db2)); - dbNames = polarisDBService.listNames( - requestContext, + dbNames = getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), QualifiedName.ofDatabase(CATALOG_NAME, "db1_"), null, null); Assert.assertEquals(dbNames, Arrays.asList(DB1_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, + dbs = getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), QualifiedName.ofDatabase(CATALOG_NAME, "db1_"), null, @@ -105,15 +104,15 @@ public void testSimpleListDb() { Assert.assertEquals(dbs, Arrays.asList(db1)); // Test Order desc - dbNames = polarisDBService.listNames( - requestContext, + dbNames = getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, new Sort("name", SortOrder.DESC), null); Assert.assertEquals(dbNames, Arrays.asList(DB2_QUALIFIED_NAME, DB1_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, + dbs = getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, new Sort("name", SortOrder.DESC), @@ -121,40 +120,46 @@ public void testSimpleListDb() { Assert.assertEquals(dbs, Arrays.asList(db2, db1)); // Test pageable - dbNames = polarisDBService.listNames( - requestContext, + dbNames = getPolarisDBService().listNames( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 0)); Assert.assertEquals(dbNames, Arrays.asList(DB1_QUALIFIED_NAME, DB2_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, + dbs = getPolarisDBService().list( + getRequestContext(), QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 0)); Assert.assertEquals(dbs, Arrays.asList(db1, db2)); - dbNames = polarisDBService.listNames( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 0)); + dbNames = getPolarisDBService().listNames( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 0)); Assert.assertEquals(dbNames, Arrays.asList(DB1_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 0)); + dbs = getPolarisDBService().list( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 0)); Assert.assertEquals(dbs, Arrays.asList(db1)); - dbNames = polarisDBService.listNames( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 1)); + dbNames = getPolarisDBService().listNames( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 1)); Assert.assertEquals(dbNames, Arrays.asList(DB2_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 1)); + dbs = getPolarisDBService().list( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(1, 1)); Assert.assertEquals(dbs, Arrays.asList(db2)); - dbNames = polarisDBService.listNames( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 1)); + dbNames = getPolarisDBService().listNames( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 1)); Assert.assertEquals(dbNames, Arrays.asList(DB2_QUALIFIED_NAME)); - dbs = polarisDBService.list( - requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 1)); + dbs = getPolarisDBService().list( + getRequestContext(), + QualifiedName.ofCatalog(CATALOG_NAME), null, null, new Pageable(5, 1)); Assert.assertEquals(dbs, Arrays.asList(db2)); } } diff --git a/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisStoreConnectorFunctionalTest.java b/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisStoreConnectorFunctionalTest.java index 223e978cc..551033490 100644 --- a/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisStoreConnectorFunctionalTest.java +++ b/metacat-connector-polaris/src/functionalTest/java/com/netflix/metacat/connector/polaris/PolarisStoreConnectorFunctionalTest.java @@ -6,6 +6,7 @@ import com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity; import com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity; import lombok.extern.slf4j.Slf4j; +import org.hibernate.boot.model.relational.QualifiedName; import org.junit.Assert; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -121,7 +122,7 @@ public void testGetTableEntities() { } /** - * Test testListDbPage. + * test list database with different db page size config. */ @Test public void testListDbPage() { @@ -131,28 +132,28 @@ public void testListDbPage() { simulateDelay(); - List dbNames = getPolarisConnector().getDatabaseNames(null, null, 1); - List dbs = getPolarisConnector().getDatabases(null, null, 1); + List dbNames = getPolarisConnector().getDatabaseNames("db", null, 1); + List dbs = getPolarisConnector().getDatabases("db", null, 1); Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), dbNames); - Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), + Assert.assertEquals("Expected dbs ", Arrays.asList("db1", "db2", "db3"), dbs.stream().map(PolarisDatabaseEntity::getDbName).collect(Collectors.toList())); - dbNames = getPolarisConnector().getDatabaseNames(null, null, 2); - dbs = getPolarisConnector().getDatabases(null, null, 2); + dbNames = getPolarisConnector().getDatabaseNames("db", null, 2); + dbs = getPolarisConnector().getDatabases("db", null, 2); Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), dbNames); - Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), + Assert.assertEquals("Expected dbs ", Arrays.asList("db1", "db2", "db3"), dbs.stream().map(PolarisDatabaseEntity::getDbName).collect(Collectors.toList())); - dbNames = getPolarisConnector().getDatabaseNames(null, null, 3); - dbs = getPolarisConnector().getDatabases(null, null, 3); + dbNames = getPolarisConnector().getDatabaseNames("db", null, 3); + dbs = getPolarisConnector().getDatabases("db", null, 3); Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), dbNames); - Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), + Assert.assertEquals("Expected dbs ", Arrays.asList("db1", "db2", "db3"), dbs.stream().map(PolarisDatabaseEntity::getDbName).collect(Collectors.toList())); - dbNames = getPolarisConnector().getDatabaseNames(null, null, 4); - dbs = getPolarisConnector().getDatabases(null, null, 4); + dbNames = getPolarisConnector().getDatabaseNames("db", null, 4); + dbs = getPolarisConnector().getDatabases("db", null, 4); Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), dbNames); - Assert.assertEquals("Expected dbNames ", Arrays.asList("db1", "db2", "db3"), + Assert.assertEquals("Expected dbs ", Arrays.asList("db1", "db2", "db3"), dbs.stream().map(PolarisDatabaseEntity::getDbName).collect(Collectors.toList())); } } diff --git a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnector.java b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnector.java index 53d7983b6..94341ca6a 100644 --- a/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnector.java +++ b/metacat-connector-polaris/src/main/java/com/netflix/metacat/connector/polaris/store/PolarisStoreConnector.java @@ -63,13 +63,16 @@ public void deleteDatabase(final String dbName) { public List getDatabases( @Nullable final String dbNamePrefix, @Nullable final Sort sort, - int pageSize) { + final int pageSize) { return (List) dbRepo.getAllDatabases(dbNamePrefix, sort, pageSize, true); } @Override @Transactional(propagation = Propagation.SUPPORTS) - public List getDatabaseNames(@Nullable final String dbNamePrefix, @Nullable final Sort sort, int pageSize) { + public List getDatabaseNames( + @Nullable final String dbNamePrefix, + @Nullable final Sort sort, + final int pageSize) { return (List) dbRepo.getAllDatabases(dbNamePrefix, sort, pageSize, false); } diff --git a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java index e3db66228..98fb0eca7 100644 --- a/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java +++ b/metacat-connector-polaris/src/test/java/com/netflix/metacat/connector/polaris/PolarisConnectorDatabaseServiceTest.java @@ -2,7 +2,6 @@ package com.netflix.metacat.connector.polaris; import com.google.common.collect.Maps; -import com.google.common.collect.Sets; import com.netflix.metacat.common.QualifiedName; import com.netflix.metacat.common.server.connectors.ConnectorContext; import com.netflix.metacat.common.server.connectors.ConnectorRequestContext; @@ -15,6 +14,7 @@ import com.netflix.metacat.connector.polaris.configs.PolarisPersistenceConfig; import com.netflix.metacat.connector.polaris.store.PolarisStoreService; import com.netflix.spectator.api.NoopRegistry; +import lombok.Getter; import org.junit.Assert; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -27,10 +27,8 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; import spock.lang.Shared; -import spock.lang.Unroll; import java.util.Date; -import java.util.List; /** @@ -41,6 +39,7 @@ @ActiveProfiles(profiles = {"polarisconnectortest"}) @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD) @AutoConfigureDataJpa +@Getter public class PolarisConnectorDatabaseServiceTest { public static final String CATALOG_NAME = "catalog_name"; public static final String DB1_NAME = "db1_name"; @@ -49,16 +48,16 @@ public class PolarisConnectorDatabaseServiceTest { public static final QualifiedName DB2_QUALIFIED_NAME = QualifiedName.ofDatabase(CATALOG_NAME, DB2_NAME); @Autowired - public PolarisStoreService polarisStoreService; + private PolarisStoreService polarisStoreService; @Shared - public ConnectorContext connectorContext; + private ConnectorContext connectorContext; @Shared - public ConnectorRequestContext requestContext = new ConnectorRequestContext(); + private ConnectorRequestContext requestContext = new ConnectorRequestContext(); @Shared - public PolarisConnectorDatabaseService polarisDBService; + private PolarisConnectorDatabaseService polarisDBService; /** * Initialization. @@ -167,24 +166,5 @@ public void testDeleteDb() { polarisDBService.delete(requestContext, DB1_QUALIFIED_NAME); Assert.assertFalse(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); } - - /** - * Test list databases. - */ - @Test - public void testListDb() { - final DatabaseInfo db1 = DatabaseInfo.builder().name(DB1_QUALIFIED_NAME).uri("uri1").build(); - final DatabaseInfo db2 = DatabaseInfo.builder().name(DB2_QUALIFIED_NAME).uri("uri2").build(); - polarisDBService.create(requestContext, db1); - polarisDBService.create(requestContext, db2); - Assert.assertTrue(polarisDBService.exists(requestContext, DB1_QUALIFIED_NAME)); - Assert.assertTrue(polarisDBService.exists(requestContext, DB2_QUALIFIED_NAME)); - final List dbNames = - polarisDBService.listNames(requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); - Assert.assertEquals(Sets.newHashSet(dbNames), Sets.newHashSet(DB1_QUALIFIED_NAME, DB2_QUALIFIED_NAME)); - final List dbs = - polarisDBService.list(requestContext, QualifiedName.ofCatalog(CATALOG_NAME), null, null, null); - Assert.assertEquals(Sets.newHashSet(dbs), Sets.newHashSet(db1, db2)); - } }