Skip to content

Commit

Permalink
Fix test case
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Sep 30, 2023
1 parent 13e54cf commit 1bab8bd
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.config.database.DatabaseConfiguration;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
import org.apache.shardingsphere.infra.config.props.ConfigurationPropertyKey;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeFactory;
import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager;
import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.apache.shardingsphere.infra.state.datasource.DataSourceStateManager;

import javax.sql.DataSource;
import java.sql.Connection;
Expand All @@ -42,7 +41,6 @@
* Database type engine.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
public final class DatabaseTypeEngine {

private static final String DEFAULT_DATABASE_TYPE = "MySQL";
Expand Down Expand Up @@ -112,7 +110,6 @@ public static DatabaseType getStorageType(final Collection<DataSource> dataSourc

private static DatabaseType getStorageType(final DataSource dataSource) {
try (Connection connection = dataSource.getConnection()) {
log.error("=========URL=======:" + connection.getMetaData().getURL());
return DatabaseTypeFactory.get(connection.getMetaData().getURL());
} catch (final SQLException ex) {
throw new SQLWrapperException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.shardingsphere.infra.metadata.database.resource.unit;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
import org.apache.shardingsphere.infra.database.core.connector.ConnectionProperties;
import org.apache.shardingsphere.infra.database.core.connector.ConnectionPropertiesParser;
Expand All @@ -38,7 +37,6 @@
* Storage unit.
*/
@Getter
@Slf4j
public final class StorageUnit {

private final DataSource dataSource;
Expand All @@ -56,9 +54,7 @@ public StorageUnit(final String databaseName, final DataSource dataSource, final
this.dataSourcePoolProperties = dataSourcePoolProperties;
this.storageNode = storageNode;
boolean isDataSourceEnabled = !DataSourceStateManager.getInstance().getEnabledDataSources(databaseName, Collections.singletonMap(storageNode.getName().getName(), dataSource)).isEmpty();
log.error("========isDataSourceEnabled======" + isDataSourceEnabled);
storageType = createStorageType(isDataSourceEnabled);
log.error("========storageType======" + storageType);
connectionProperties = createConnectionProperties(isDataSourceEnabled);
}

Expand Down
4 changes: 0 additions & 4 deletions proxy/backend/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,5 @@
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
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;
Expand All @@ -59,6 +61,11 @@ 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: sharding_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -26,7 +26,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: encrypt_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: sharding_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: mask_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: readwrite_splitting_db

dataSources:
write_ds:
url: jdbc:mysql://127.0.0.1:3306/demo_write_ds?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_write_ds
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
read_ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_read_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -37,7 +37,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
read_ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_read_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_read_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: shadow_db

dataSources:
ds:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
shadow_ds:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ databaseName: sharding_db

dataSources:
ds_0:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_0
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand All @@ -28,7 +28,7 @@ dataSources:
maxPoolSize: 50
minPoolSize: 1
ds_1:
url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
url: jdbc:mock://127.0.0.1/demo_ds_1
username: root
password:
connectionTimeoutMilliseconds: 30000
Expand Down

0 comments on commit 1bab8bd

Please sign in to comment.