yuqi1129 commented on code in PR #13855:
URL: https://github.com/apache/gravitino/pull/13855#discussion_r4278417742
##########
catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/TestJdbcCatalogOperationsProbe.java:
##########
@@ -201,4 +238,89 @@ public java.util.logging.Logger getParentLogger() throws
SQLFeatureNotSupportedE
throw new SQLFeatureNotSupportedException();
}
}
+
+ /**
+ * Runs the probe from inside the catalog class loader, the way a catalog
does in the server, and
+ * returns the connection-failure message.
+ */
+ public static class IsolatedProbe implements Callable<String> {
+ @Override
+ public String call() {
+ JdbcCatalogOperations ops =
+ new JdbcCatalogOperations(
+ new SqliteExceptionConverter(),
+ new SqliteTypeConverter(),
+ new SqliteDatabaseOperations(":memory:"),
+ new SqliteTableOperations(),
+ new SqliteColumnDefaultValueConverter());
+ Map<String, String> config = new HashMap<>();
+ config.put(JdbcConfig.JDBC_DRIVER.getKey(),
SelfRegisteringDriver.class.getName());
+ config.put(JdbcConfig.JDBC_URL.getKey(),
SelfRegisteringDriver.URL_PREFIX + "//db:1/test");
+ config.put(JdbcConfig.USERNAME.getKey(), "u");
+ config.put(JdbcConfig.PASSWORD.getKey(), "p");
+ ops.setProbeConfigForTest(new JdbcConfig(config));
+ ConnectionFailedException e =
+ Assertions.assertThrows(
+ ConnectionFailedException.class,
+ () -> ops.probeConnection(NameIdentifier.of("m", "c")));
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * A driver that, like real JDBC drivers, registers itself with {@link
DriverManager} when its
+ * class is initialized. It has no {@code META-INF/services/java.sql.Driver}
entry, so nothing
+ * registers it automatically.
+ */
+ public static class SelfRegisteringDriver implements Driver {
+ static final String URL_PREFIX = "jdbc:selfregistering:";
+ static final String REACHED = "reached the catalog driver";
+
+ static {
+ try {
+ DriverManager.registerDriver(new SelfRegisteringDriver());
+ } catch (SQLException e) {
+ throw new ExceptionInInitializerError(e);
+ }
+ }
+
+ @Override
+ public Connection connect(String url, Properties info) throws SQLException
{
+ if (!acceptsURL(url)) {
+ return null;
+ }
+ throw new SQLException(REACHED);
+ }
+
+ @Override
+ public boolean acceptsURL(String url) {
+ return url != null && url.startsWith(URL_PREFIX);
+ }
+
+ @Override
+ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) {
+ return new DriverPropertyInfo[0];
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return 1;
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public boolean jdbcCompliant() {
+ return false;
+ }
+
+ @Override
+ public java.util.logging.Logger getParentLogger() throws
SQLFeatureNotSupportedException {
+ // FQN for the same reason as in SocketReadingDriver.
Review Comment:
Tried this, but spotless rewrites the import: the root `build.gradle.kts`
rule "Use SLF4J Logger instead of other logging frameworks" replaces any
`import ...Logger;` with `org.slf4j.Logger`, which then fails to compile
against `java.sql.Driver#getParentLogger`. So the FQN has to stay. I updated
the comments on both fake drivers to state this actual reason (adac73db).
--
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]