Copilot commented on code in PR #10081: URL: https://github.com/apache/gravitino/pull/10081#discussion_r3213166070
########## catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlCredentialIT.java: ########## @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.catalog.mysql.integration.test; + +import com.google.common.collect.Maps; +import java.sql.SQLException; +import java.util.Collections; +import java.util.Map; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; +import org.apache.gravitino.client.GravitinoMetalake; +import org.apache.gravitino.credential.Credential; +import org.apache.gravitino.credential.JdbcCredential; +import org.apache.gravitino.integration.test.container.ContainerSuite; +import org.apache.gravitino.integration.test.container.MySQLContainer; +import org.apache.gravitino.integration.test.util.BaseIT; +import org.apache.gravitino.integration.test.util.GravitinoITUtils; +import org.apache.gravitino.integration.test.util.TestDatabaseName; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Integration test for MySQL catalog credential vending. Tests that JDBC credentials can be + * retrieved through the credential API. + */ +@Tag("gravitino-docker-test") +public class CatalogMysqlCredentialIT extends BaseIT { + + private static final Logger LOG = LoggerFactory.getLogger(CatalogMysqlCredentialIT.class); + private static final ContainerSuite containerSuite = ContainerSuite.getInstance(); + private static final String provider = "jdbc-mysql"; + private static final TestDatabaseName TEST_DB_NAME = TestDatabaseName.MYSQL_CATALOG_CREDENTIAL_IT; + + private String metalakeName = GravitinoITUtils.genRandomName("mysql_credential_metalake"); + private String catalogName = GravitinoITUtils.genRandomName("mysql_credential_catalog"); + private GravitinoMetalake metalake; + private MySQLContainer mysqlContainer; + + @BeforeAll + public void startIntegrationTest() { + // Do nothing - override to prevent auto start + } + + @BeforeAll + public void startUp() throws Exception { + containerSuite.startMySQLContainer(TEST_DB_NAME); + mysqlContainer = containerSuite.getMySQLContainer(); + super.startIntegrationTest(); + + Assertions.assertFalse(client.metalakeExists(metalakeName)); + metalake = client.createMetalake(metalakeName, "metalake comment", Collections.emptyMap()); + Assertions.assertTrue(client.metalakeExists(metalakeName)); + + createCatalog(); + } + + @AfterAll + public void tearDown() { + try { + if (metalake != null && metalake.catalogExists(catalogName)) { + metalake.disableCatalog(catalogName); + metalake.dropCatalog(catalogName, true); + } + if (client != null && client.metalakeExists(metalakeName)) { + client.disableMetalake(metalakeName); + client.dropMetalake(metalakeName, true); + } + } finally { + if (client != null) { + try { + client.close(); + } catch (Exception e) { + LOG.error("Exception in closing client", e); + } + client = null; + } + try { + super.stopIntegrationTest(); + } catch (Exception e) { + LOG.error("Exception in closing BaseIT", e); + } + } + } + + @AfterAll + public void stopIntegrationTest() { + // Do nothing - override to prevent auto stop + } + + private void createCatalog() throws SQLException { + Map<String, String> catalogProperties = Maps.newHashMap(); + catalogProperties.put( + JdbcConfig.JDBC_URL.getKey(), + String.format( + "jdbc:mysql://%s:%d/", + mysqlContainer.getContainerIpAddress(), MySQLContainer.MYSQL_PORT)); + catalogProperties.put( + JdbcConfig.JDBC_DRIVER.getKey(), mysqlContainer.getDriverClassName(TEST_DB_NAME)); + catalogProperties.put(JdbcConfig.USERNAME.getKey(), mysqlContainer.getUsername()); + catalogProperties.put(JdbcConfig.PASSWORD.getKey(), mysqlContainer.getPassword()); Review Comment: The MySQL JDBC URL here is missing the connection parameters used elsewhere in this repo for MySQL 8 (e.g., `useSSL=false&allowPublicKeyRetrieval=true`). Without them, the catalog connection can fail with auth/SSL related errors (and make this IT flaky). Consider building the URL the same way as `CatalogMysqlIT` (strip the DB from `mysqlContainer.getJdbcUrl(TEST_DB_NAME)` and append the standard query parameters). ########## catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/TestJdbcCatalogCredential.java: ########## @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.catalog.jdbc; + +import com.google.common.collect.Maps; +import java.time.Instant; +import java.util.Map; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.catalog.jdbc.config.JdbcConfig; +import org.apache.gravitino.catalog.jdbc.converter.JdbcColumnDefaultValueConverter; +import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter; +import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations; +import org.apache.gravitino.catalog.jdbc.operation.JdbcTableOperations; +import org.apache.gravitino.credential.CredentialConstants; +import org.apache.gravitino.credential.JdbcCredential; +import org.apache.gravitino.meta.AuditInfo; +import org.apache.gravitino.meta.CatalogEntity; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** Tests for JdbcCatalog credential provider functionality. */ +public class TestJdbcCatalogCredential { + + /** A concrete implementation of JdbcCatalog for testing purposes. */ + private static class TestableJdbcCatalog extends JdbcCatalog { + + @Override + public String shortName() { + return "jdbc-test"; + } + + @Override + protected JdbcTypeConverter createJdbcTypeConverter() { + return null; + } + + @Override + protected JdbcDatabaseOperations createJdbcDatabaseOperations() { + return null; + } + + @Override + protected JdbcTableOperations createJdbcTableOperations() { + return null; + } + + @Override + protected JdbcColumnDefaultValueConverter createJdbcColumnDefaultValueConverter() { + return null; + } Review Comment: `TestableJdbcCatalog` overrides several factory methods to return null. If any production code path (now or in the future) ends up calling these during initialization, the test will fail with a NullPointerException that’s harder to diagnose. Prefer throwing `UnsupportedOperationException` (or providing minimal stub implementations) so failures are explicit and easier to debug. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
