From 12cf09b5309d6293ed42f4dcf7a77ef3df87ad21 Mon Sep 17 00:00:00 2001 From: haocao Date: Wed, 1 Aug 2018 19:46:25 +0800 Subject: [PATCH] for #601, removed useless codes for integrate database type codes from AbstractSQLTest --- .../core/common/base/AbstractSQLTest.java | 17 ++++++----------- ...bstractShardingJDBCDatabaseAndTableTest.java | 6 +++--- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java index 11b046c50e75b..8d284582b1410 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractSQLTest.java @@ -50,7 +50,7 @@ public abstract class AbstractSQLTest { - private static Map shardingDataSources = new HashMap<>(); + protected static ShardingDataSource shardingDataSource; private static Set databaseTypes = Sets.newHashSet(DatabaseType.H2); @@ -60,10 +60,6 @@ public abstract class AbstractSQLTest { init(); } - protected static Map getShardingDataSources() { - return shardingDataSources; - } - private static synchronized void init() { try { Properties prop = new Properties(); @@ -131,13 +127,12 @@ private static Connection initialConnection(final String dbName, final DatabaseT @AfterClass public static void clear() throws SQLException, ReflectiveOperationException { - if (!shardingDataSources.isEmpty()) { - for (ShardingDataSource each : shardingDataSources.values()) { - each.close(); - closeDataSources(getDataSourceMap(each).values()); - } - shardingDataSources.clear(); + if (shardingDataSource == null) { + return; } + shardingDataSource.close(); + closeDataSources(getDataSourceMap(shardingDataSource).values()); + shardingDataSource = null; } private void createDataSources(final String dbName, final DatabaseType type) { diff --git a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java index c7006f949e813..d1334efffb3a9 100644 --- a/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java +++ b/sharding-jdbc/src/test/java/io/shardingsphere/core/common/base/AbstractShardingJDBCDatabaseAndTableTest.java @@ -45,7 +45,7 @@ public void cleanAndInitTable() throws Exception { @Before public void initShardingDataSources() throws SQLException { - if (!getShardingDataSources().isEmpty()) { + if (null != shardingDataSource) { return; } @@ -77,7 +77,7 @@ public void initShardingDataSources() throws SQLException { shardingRuleConfig.setDefaultTableShardingStrategyConfig(new StandardShardingStrategyConfiguration("order_id", new PreciseOrderShardingAlgorithm(), new RangeOrderShardingAlgorithm())); shardingRuleConfig.setDefaultDatabaseShardingStrategyConfig(new StandardShardingStrategyConfiguration("user_id", new PreciseOrderShardingAlgorithm(), new RangeOrderShardingAlgorithm())); ShardingRule shardingRule = new ShardingRule(shardingRuleConfig, entry.getValue().keySet()); - getShardingDataSources().put(entry.getKey(), new ShardingDataSource(entry.getValue(), shardingRule)); + shardingDataSource = new ShardingDataSource(entry.getValue(), shardingRule); } } @@ -87,6 +87,6 @@ protected List getInitDataSetFiles() { } protected ShardingDataSource getShardingDataSource() { - return getShardingDataSources().get(DatabaseType.H2); + return shardingDataSource; } }