From ff0e2b187fb0e7a90e0e41444f0d67bc468f3eae Mon Sep 17 00:00:00 2001 From: zhangliang Date: Sun, 5 Nov 2023 20:02:08 +0800 Subject: [PATCH] Add spi for MockedDriver --- .../DataSourcePoolPropertiesValidatorTest.java | 7 ------- .../ingest/MySQLIncrementalDumperTest.java | 3 +-- ...ImportDatabaseConfigurationUpdaterTest.java | 7 ------- .../META-INF/services/java.sql.Driver | 18 ++++++++++++++++++ 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 test/fixture/database/src/main/resources/META-INF/services/java.sql.Driver diff --git a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidatorTest.java b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidatorTest.java index 548c50901f895..550db2e08ee43 100644 --- a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidatorTest.java +++ b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/props/validator/DataSourcePoolPropertiesValidatorTest.java @@ -19,8 +19,6 @@ import com.zaxxer.hikari.HikariDataSource; import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties; -import org.apache.shardingsphere.test.fixture.jdbc.MockedDriver; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import java.util.Collections; @@ -29,11 +27,6 @@ class DataSourcePoolPropertiesValidatorTest { - @BeforeAll - static void setUp() throws ClassNotFoundException { - Class.forName(MockedDriver.class.getName()); - } - @Test void assertValidate() { assertTrue(DataSourcePoolPropertiesValidator.validate( diff --git a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java index 5ed2365d713ef..93f6d1623ad49 100644 --- a/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java +++ b/kernel/data-pipeline/dialect/mysql/src/test/java/org/apache/shardingsphere/data/pipeline/mysql/ingest/MySQLIncrementalDumperTest.java @@ -82,7 +82,6 @@ class MySQLIncrementalDumperTest { void setUp() throws SQLException { IncrementalDumperContext dumperContext = createDumperContext(); initTableData(dumperContext); - dumperContext.getCommonContext().setDataSourceConfig(new StandardPipelineDataSourceConfiguration("jdbc:mock://127.0.0.1:3306/test", "root", "root")); PipelineTableMetaDataLoader metaDataLoader = mock(PipelineTableMetaDataLoader.class); SimpleMemoryPipelineChannel channel = new SimpleMemoryPipelineChannel(10000, new EmptyAckCallback()); incrementalDumper = new MySQLIncrementalDumper(dumperContext, new BinlogPosition("binlog-000001", 4L, 0L), channel, metaDataLoader); @@ -92,7 +91,7 @@ void setUp() throws SQLException { private IncrementalDumperContext createDumperContext() { DumperCommonContext commonContext = new DumperCommonContext(); - commonContext.setDataSourceConfig(new StandardPipelineDataSourceConfiguration("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL", "root", "root")); + commonContext.setDataSourceConfig(new StandardPipelineDataSourceConfiguration("jdbc:mock://127.0.0.1:3306/test", "root", "root")); commonContext.setTableNameMapper(new ActualAndLogicTableNameMapper(Collections.singletonMap(new ActualTableName("t_order"), new LogicTableName("t_order")))); commonContext.setTableAndSchemaNameMapper(new TableAndSchemaNameMapper(Collections.emptyMap())); return new IncrementalDumperContext(commonContext); diff --git a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java index 561df445c2855..0e4172ab153ee 100644 --- a/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java +++ b/proxy/backend/core/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ImportDatabaseConfigurationUpdaterTest.java @@ -34,10 +34,8 @@ import org.apache.shardingsphere.mode.manager.ContextManager; import org.apache.shardingsphere.proxy.backend.context.ProxyContext; import org.apache.shardingsphere.proxy.backend.util.YamlDatabaseConfigurationImportExecutor; -import org.apache.shardingsphere.test.fixture.jdbc.MockedDriver; import org.apache.shardingsphere.test.mock.AutoMockExtension; import org.apache.shardingsphere.test.mock.StaticMockSettings; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.internal.configuration.plugins.Plugins; @@ -60,11 +58,6 @@ class ImportDatabaseConfigurationUpdaterTest { private ImportDatabaseConfigurationUpdater importDatabaseConfigUpdater; - @BeforeAll - static void setUp() throws ClassNotFoundException { - Class.forName(MockedDriver.class.getName()); - } - @Test void assertImportDatabaseExecutorForSharding() throws SQLException { assertExecute("sharding_db", "/conf/import/config-sharding.yaml"); diff --git a/test/fixture/database/src/main/resources/META-INF/services/java.sql.Driver b/test/fixture/database/src/main/resources/META-INF/services/java.sql.Driver new file mode 100644 index 0000000000000..72fac4d815d5f --- /dev/null +++ b/test/fixture/database/src/main/resources/META-INF/services/java.sql.Driver @@ -0,0 +1,18 @@ +# +# 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. +# + +org.apache.shardingsphere.test.fixture.jdbc.MockedDriver