You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/02/05 11:52:59 UTC
[shardingsphere] branch master updated: Use DataSourcePoolCreator instead of DataSourceUtil in spring boot data source creation (#15249)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new a8a079b Use DataSourcePoolCreator instead of DataSourceUtil in spring boot data source creation (#15249)
a8a079b is described below
commit a8a079b55841bdb83f185b720ad99855613986be
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Feb 5 19:51:59 2022 +0800
Use DataSourcePoolCreator instead of DataSourceUtil in spring boot data source creation (#15249)
* Simplify ContextManagerTest
* Refactor ContextManagerTest
* Refactor DataSourceUtils
* Remove incorrect DataSourceUtil ref in spring boot metadata
* Use DataSourcePoolCreator instead of DataSourceUtil in spring boot data source creation
---
.../additional-spring-configuration-metadata.json | 5 -
.../boot/datasource/DataSourceMapSetter.java | 9 +-
.../spring/boot/util/DataSourceUtil.java | 89 -------------
.../spring/boot/util/PropertyUtil.java | 17 +++
.../spring/boot/util/DataSourceUtilTest.java | 138 ---------------------
.../spring/boot/util/PropertyUtilTest.java | 48 +++++++
.../transaction/xa/fixture/DataSourceUtils.java | 10 +-
.../mode/manager/ContextManagerTest.java | 2 +-
8 files changed, 76 insertions(+), 242 deletions(-)
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
index ab5096b..f50c5f5 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-core-spring/shardingsphere-jdbc-core-spring-boot-starter/src/main/resources/META-INF/additional-spring-configuration-metadata.json
@@ -71,11 +71,6 @@
"sourceType": "org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration"
},
{
- "name": "spring.shardingsphere.datasource",
- "type": "java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>>",
- "sourceType": "org.apache.shardingsphere.spring.boot.util.DataSourceUtil"
- },
- {
"name": "spring.shardingsphere.schema.name",
"type": "org.apache.shardingsphere.spring.boot.ShardingSphereAutoConfiguration"
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
index 7b06b7b..683a95d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/datasource/DataSourceMapSetter.java
@@ -20,10 +20,11 @@ package org.apache.shardingsphere.spring.boot.datasource;
import com.google.common.base.Preconditions;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
+import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
import org.apache.shardingsphere.infra.exception.ShardingSphereException;
import org.apache.shardingsphere.sharding.support.InlineExpressionParser;
import org.apache.shardingsphere.spring.boot.datasource.prop.impl.DataSourcePropertiesSetterHolder;
-import org.apache.shardingsphere.spring.boot.util.DataSourceUtil;
import org.apache.shardingsphere.spring.boot.util.PropertyUtil;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
@@ -89,9 +90,9 @@ public final class DataSourceMapSetter {
if (dataSourceProps.containsKey(JNDI_NAME)) {
return getJNDIDataSource(dataSourceProps.get(JNDI_NAME).toString());
}
- DataSource result = DataSourceUtil.getDataSource(dataSourceProps.get(DATA_SOURCE_TYPE).toString(), dataSourceProps);
- DataSourcePropertiesSetterHolder.getDataSourcePropertiesSetterByType(dataSourceProps.get(DATA_SOURCE_TYPE).toString()).ifPresent(
- propsSetter -> propsSetter.propertiesSet(environment, PREFIX, dataSourceName, result));
+ String dataSourceType = dataSourceProps.get(DATA_SOURCE_TYPE).toString();
+ DataSource result = DataSourcePoolCreator.create(new DataSourceProperties(dataSourceType, PropertyUtil.getCamelCaseKeys(dataSourceProps)));
+ DataSourcePropertiesSetterHolder.getDataSourcePropertiesSetterByType(dataSourceType).ifPresent(optional -> optional.propertiesSet(environment, PREFIX, dataSourceName, result));
return result;
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtil.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtil.java
deleted file mode 100644
index a1e3510..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtil.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.shardingsphere.spring.boot.util;
-
-import com.google.common.base.CaseFormat;
-import com.google.common.collect.Sets;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-
-import javax.sql.DataSource;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Map.Entry;
-
-/**
- * Data source utility class.
- */
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class DataSourceUtil {
-
- private static final String SET_METHOD_PREFIX = "set";
-
- private static final Collection<Class<?>> GENERAL_CLASS_TYPE;
-
- static {
- GENERAL_CLASS_TYPE = Sets.newHashSet(boolean.class, Boolean.class, int.class, Integer.class, long.class, Long.class, String.class, Collection.class);
- }
-
- /**
- * Get data source.
- *
- * @param dataSourceClassName data source class name
- * @param dataSourceProperties data source properties
- * @return data source instance
- * @throws ReflectiveOperationException reflective operation exception
- */
- public static DataSource getDataSource(final String dataSourceClassName, final Map<String, Object> dataSourceProperties) throws ReflectiveOperationException {
- DataSource result = (DataSource) Class.forName(dataSourceClassName).newInstance();
- for (Entry<String, Object> entry : dataSourceProperties.entrySet()) {
- callSetterMethod(result, getSetterMethodName(entry.getKey()), null == entry.getValue() ? null : entry.getValue().toString());
- }
- return result;
- }
-
- private static String getSetterMethodName(final String propertyName) {
- if (propertyName.contains("-")) {
- return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, SET_METHOD_PREFIX + "-" + propertyName);
- }
- return SET_METHOD_PREFIX + String.valueOf(propertyName.charAt(0)).toUpperCase() + propertyName.substring(1);
- }
-
- private static void callSetterMethod(final DataSource dataSource, final String methodName, final String setterValue) {
- for (Class<?> each : GENERAL_CLASS_TYPE) {
- try {
- Method method = dataSource.getClass().getMethod(methodName, each);
- if (boolean.class == each || Boolean.class == each) {
- method.invoke(dataSource, Boolean.valueOf(setterValue));
- } else if (int.class == each || Integer.class == each) {
- method.invoke(dataSource, Integer.parseInt(setterValue));
- } else if (long.class == each || Long.class == each) {
- method.invoke(dataSource, Long.parseLong(setterValue));
- } else if (Collection.class == each) {
- method.invoke(dataSource, Arrays.asList(setterValue.split(",")));
- } else {
- method.invoke(dataSource, setterValue);
- }
- return;
- } catch (final ReflectiveOperationException ignored) {
- }
- }
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
index 9164e6a..09c6080 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/main/java/org/apache/shardingsphere/spring/boot/util/PropertyUtil.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.spring.boot.util;
+import com.google.common.base.CaseFormat;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.SneakyThrows;
@@ -27,6 +28,7 @@ import org.springframework.core.env.PropertyResolver;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -110,4 +112,19 @@ public final class PropertyUtil {
Method resultGetMethod = bindResultObject.getClass().getDeclaredMethod("get");
return resultGetMethod.invoke(bindResultObject);
}
+
+ /**
+ * Convert keys of map to camel case.
+ *
+ * @param dataSourceProps map to be converted
+ * @return converted map
+ */
+ public static Map<String, Object> getCamelCaseKeys(final Map<String, Object> dataSourceProps) {
+ Map<String, Object> result = new LinkedHashMap<>(dataSourceProps.size(), 1);
+ for (Entry<String, Object> entry : dataSourceProps.entrySet()) {
+ String key = entry.getKey();
+ result.put(key.contains("-") ? CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, key) : key, entry.getValue());
+ }
+ return result;
+ }
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtilTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtilTest.java
deleted file mode 100644
index 7fa724b..0000000
--- a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/DataSourceUtilTest.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * 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.shardingsphere.spring.boot.util;
-
-import com.zaxxer.hikari.HikariDataSource;
-import org.apache.commons.dbcp2.BasicDataSource;
-import org.junit.Test;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.hamcrest.CoreMatchers.hasItem;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-public final class DataSourceUtilTest {
-
- @Test
- public void assertDataSourceForDBCPAndCamel() throws ReflectiveOperationException {
- BasicDataSource actual = (BasicDataSource) DataSourceUtil
- .getDataSource(BasicDataSource.class.getName(), getDataSourcePoolProperties("driverClassName", "url", "username"));
- assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
- assertThat(actual.getUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
- assertThat(actual.getUsername(), is("sa"));
- }
-
- @Test
- public void assertDataSourceForDBCPAndHyphen() throws ReflectiveOperationException {
- BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), getDataSourcePoolProperties("driver-class-name", "url", "username"));
- assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
- assertThat(actual.getUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
- assertThat(actual.getUsername(), is("sa"));
- }
-
- @Test
- public void assertDataSourceForHikariCPAndCamel() throws ReflectiveOperationException {
- HikariDataSource actual = (HikariDataSource) DataSourceUtil.getDataSource(HikariDataSource.class.getName(), getDataSourcePoolProperties("driverClassName", "jdbcUrl", "username"));
- assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
- assertThat(actual.getJdbcUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
- assertThat(actual.getUsername(), is("sa"));
- }
-
- @Test
- public void assertDataSourceForHikariCPAndHyphen() throws ReflectiveOperationException {
- HikariDataSource actual = (HikariDataSource) DataSourceUtil.getDataSource(HikariDataSource.class.getName(), getDataSourcePoolProperties("driver-class-name", "jdbc-url", "username"));
- assertThat(actual.getDriverClassName(), is("org.h2.Driver"));
- assertThat(actual.getJdbcUrl(), is("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL"));
- assertThat(actual.getUsername(), is("sa"));
- }
-
- private Map<String, Object> getDataSourcePoolProperties(final String driverClassName, final String url, final String username) {
- Map<String, Object> result = new HashMap<>(3, 1);
- result.put(driverClassName, "org.h2.Driver");
- result.put(url, "jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MySQL");
- result.put(username, "sa");
- return result;
- }
-
- @Test
- public void assertDataSourceForBooleanValue() throws ReflectiveOperationException {
- Map<String, Object> dataSourceProperties = new HashMap<>(7, 1);
- dataSourceProperties.put("defaultAutoCommit", true);
- dataSourceProperties.put("defaultReadOnly", false);
- dataSourceProperties.put("poolPreparedStatements", Boolean.TRUE);
- dataSourceProperties.put("testOnBorrow", Boolean.FALSE);
- dataSourceProperties.put("testOnReturn", true);
- dataSourceProperties.put("testWhileIdle", false);
- dataSourceProperties.put("accessToUnderlyingConnectionAllowed", Boolean.TRUE);
- BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), dataSourceProperties);
- assertTrue(actual.getDefaultAutoCommit());
- assertFalse(actual.getDefaultReadOnly());
- assertThat(actual.isPoolPreparedStatements(), is(Boolean.TRUE));
- assertThat(actual.getTestOnBorrow(), is(Boolean.FALSE));
- assertThat(actual.getTestOnReturn(), is(Boolean.TRUE));
- assertThat(actual.getTestWhileIdle(), is(Boolean.FALSE));
- assertTrue(actual.isAccessToUnderlyingConnectionAllowed());
- }
-
- @Test
- public void assertDataSourceForIntValue() throws ReflectiveOperationException {
- Map<String, Object> dataSourceProperties = new HashMap<>(7, 1);
- dataSourceProperties.put("defaultTransactionIsolation", -13);
- dataSourceProperties.put("maxTotal", 16);
- dataSourceProperties.put("maxIdle", 4);
- dataSourceProperties.put("minIdle", 16);
- dataSourceProperties.put("initialSize", 7);
- dataSourceProperties.put("maxOpenPreparedStatements", 128);
- dataSourceProperties.put("numTestsPerEvictionRun", 13);
- BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), dataSourceProperties);
- assertThat(actual.getDefaultTransactionIsolation(), is(-13));
- assertThat(actual.getMaxTotal(), is(16));
- assertThat(actual.getMaxIdle(), is(4));
- assertThat(actual.getMinIdle(), is(16));
- assertThat(actual.getInitialSize(), is(7));
- assertThat(actual.getMaxOpenPreparedStatements(), is(128));
- assertThat(actual.getNumTestsPerEvictionRun(), is(13));
- }
-
- @Test
- public void assertDataSourceForLongValue() throws ReflectiveOperationException {
- Map<String, Object> dataSourceProperties = new HashMap<>(3, 1);
- dataSourceProperties.put("timeBetweenEvictionRunsMillis", 16L);
- dataSourceProperties.put("minEvictableIdleTimeMillis", 4000L);
- BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), dataSourceProperties);
- assertThat(actual.getTimeBetweenEvictionRunsMillis(), is(16L));
- assertThat(actual.getMinEvictableIdleTimeMillis(), is(4000L));
- }
-
- @Test
- public void assertDataSourceForListValue() throws ReflectiveOperationException {
- Map<String, Object> dataSourceProperties = new HashMap<>(3, 1);
- dataSourceProperties.put("connectionInitSqls", "set names utf8mb4;,set names utf8;");
- BasicDataSource actual = (BasicDataSource) DataSourceUtil.getDataSource(BasicDataSource.class.getName(), dataSourceProperties);
- assertThat(actual.getConnectionInitSqls(), instanceOf(List.class));
- assertThat(actual.getConnectionInitSqls().size(), is(2));
- assertThat(actual.getConnectionInitSqls(), hasItem("set names utf8mb4;"));
- assertThat(actual.getConnectionInitSqls(), hasItem("set names utf8;"));
- }
-}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
new file mode 100644
index 0000000..a5bfda8
--- /dev/null
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-spring/shardingsphere-jdbc-spring-infra/shardingsphere-jdbc-spring-boot-starter-infra/src/test/java/org/apache/shardingsphere/spring/boot/util/PropertyUtilTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.shardingsphere.spring.boot.util;
+
+import org.junit.Test;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public final class PropertyUtilTest {
+
+ @Test
+ public void assertGetCamelCaseKeys() {
+ assertThat(PropertyUtil.getCamelCaseKeys(createToBeConvertedMap()), is(createConvertedMap()));
+ }
+
+ private Map<String, Object> createToBeConvertedMap() {
+ Map<String, Object> result = new LinkedHashMap<>(2, 1);
+ result.put("fooKey", "fooValue");
+ result.put("bar-key", "barValue");
+ return result;
+ }
+
+ private Map<String, Object> createConvertedMap() {
+ Map<String, Object> result = new LinkedHashMap<>(2, 1);
+ result.put("fooKey", "fooValue");
+ result.put("barKey", "barValue");
+ return result;
+ }
+}
diff --git a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/DataSourceUtils.java b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/DataSourceUtils.java
index ab13b3f..0370491 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/DataSourceUtils.java
+++ b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-core/src/test/java/org/apache/shardingsphere/transaction/xa/fixture/DataSourceUtils.java
@@ -38,15 +38,15 @@ public final class DataSourceUtils {
* @param dataSourceClass data source
* @param databaseType database type
* @param databaseName database name
- * @return data source
+ * @return built data source
*/
public static DataSource build(final Class<? extends DataSource> dataSourceClass, final DatabaseType databaseType, final String databaseName) {
if (HikariDataSource.class == dataSourceClass) {
return createHikariDataSource(databaseType, databaseName);
- } else if (AtomikosDataSourceBean.class == dataSourceClass) {
+ }
+ if (AtomikosDataSourceBean.class == dataSourceClass) {
return createAtomikosDataSourceBean(databaseType, createHikariDataSource(databaseType, databaseName), databaseName);
}
-
throw new UnsupportedOperationException(dataSourceClass.getName());
}
@@ -57,8 +57,8 @@ public final class DataSourceUtils {
result.setPassword("root");
result.setMaximumPoolSize(10);
result.setMinimumIdle(2);
- result.setConnectionTimeout(15 * 1000);
- result.setIdleTimeout(40 * 1000);
+ result.setConnectionTimeout(15 * 1000L);
+ result.setIdleTimeout(40 * 1000L);
return result;
}
diff --git a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
index 6a3699c..d3d7a5a 100644
--- a/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
+++ b/shardingsphere-mode/shardingsphere-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/ContextManagerTest.java
@@ -235,7 +235,7 @@ public final class ContextManagerTest {
}
@Test
- public void assertAlterProps() {
+ public void assertAlterProperties() {
Properties props = new Properties();
props.put("foo", "foo_value");
contextManager.alterProperties(props);