You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/08/30 12:05:44 UTC
[GitHub] [shardingsphere] sluk3r opened a new pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
sluk3r opened a new pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155
Fixes #7099.
Changes proposed in this pull request:
- assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] coveralls edited a comment on pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155#issuecomment-683424875
## Pull Request Test Coverage Report for [Build 14262](https://coveralls.io/builds/33098172)
* **0** of **0** changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.006%**) to **35.62%**
---
| Totals | [](https://coveralls.io/builds/33098172) |
| :-- | --: |
| Change from base [Build 14142](https://coveralls.io/builds/33009583): | 0.006% |
| Covered Lines: | 35828 |
| Relevant Lines: | 100585 |
---
##### 💛 - [Coveralls](https://coveralls.io)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] coveralls commented on pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155#issuecomment-683424875
## Pull Request Test Coverage Report for [Build 14261](https://coveralls.io/builds/33097679)
* **0** of **0** changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.003%**) to **35.617%**
---
| Totals | [](https://coveralls.io/builds/33097679) |
| :-- | --: |
| Change from base [Build 14142](https://coveralls.io/builds/33009583): | 0.003% |
| Covered Lines: | 35825 |
| Relevant Lines: | 100585 |
---
##### 💛 - [Coveralls](https://coveralls.io)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] coveralls edited a comment on pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155#issuecomment-683424875
## Pull Request Test Coverage Report for [Build 14265](https://coveralls.io/builds/33098791)
* **0** of **0** changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.01%**) to **35.626%**
---
| Totals | [](https://coveralls.io/builds/33098791) |
| :-- | --: |
| Change from base [Build 14142](https://coveralls.io/builds/33009583): | 0.01% |
| Covered Lines: | 35834 |
| Relevant Lines: | 100585 |
---
##### 💛 - [Coveralls](https://coveralls.io)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] coveralls edited a comment on pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155#issuecomment-683424875
## Pull Request Test Coverage Report for [Build 14263](https://coveralls.io/builds/33098414)
* **0** of **0** changed or added relevant lines in **0** files are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.01%**) to **35.626%**
---
| Totals | [](https://coveralls.io/builds/33098414) |
| :-- | --: |
| Change from base [Build 14142](https://coveralls.io/builds/33009583): | 0.01% |
| Covered Lines: | 35834 |
| Relevant Lines: | 100585 |
---
##### 💛 - [Coveralls](https://coveralls.io)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu commented on a change in pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155#discussion_r479783118
##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/api/OrchestrationShardingSphereDataSourceFactoryTest.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.driver.orchestration.api;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OrchestrationShardingSphereDataSourceFactoryTest {
+ private static final String TABLE_TYPE = "TABLE";
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmpty() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmptyWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSource() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSourceWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ private Map<String, DataSource> createDataSourceMap() {
+ Map<String, DataSource> dataSourceMap = new HashMap<>();
+ dataSourceMap.put("dataSourceMapKey", createDataSource());
+ return dataSourceMap;
Review comment:
The return value should name as `result`
##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/api/OrchestrationShardingSphereDataSourceFactoryTest.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.driver.orchestration.api;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OrchestrationShardingSphereDataSourceFactoryTest {
Review comment:
Please add final if the class is not design for extension
##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/api/OrchestrationShardingSphereDataSourceFactoryTest.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.driver.orchestration.api;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OrchestrationShardingSphereDataSourceFactoryTest {
+ private static final String TABLE_TYPE = "TABLE";
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmpty() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmptyWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSource() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSourceWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ private Map<String, DataSource> createDataSourceMap() {
+ Map<String, DataSource> dataSourceMap = new HashMap<>();
+ dataSourceMap.put("dataSourceMapKey", createDataSource());
+ return dataSourceMap;
+ }
+
+ @SneakyThrows
+ private DataSource createDataSource() {
+ DataSource baseDataSource = mock(DataSource.class);
+ Connection connection = mock(Connection.class);
+ DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(databaseMetaData);
+ when(databaseMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/mysql?serverTimezone=GMT%2B8");
+ ResultSet resultSet = mock(ResultSet.class);
+ when(databaseMetaData.getTables(null, null, null, new String[]{TABLE_TYPE})).thenReturn(resultSet);
+ when(resultSet.next()).thenReturn(false);
Review comment:
It is unnecessary to mock return false
##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/api/OrchestrationShardingSphereDataSourceFactoryTest.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.driver.orchestration.api;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OrchestrationShardingSphereDataSourceFactoryTest {
+ private static final String TABLE_TYPE = "TABLE";
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmpty() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmptyWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSource() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSourceWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ private Map<String, DataSource> createDataSourceMap() {
+ Map<String, DataSource> dataSourceMap = new HashMap<>();
+ dataSourceMap.put("dataSourceMapKey", createDataSource());
+ return dataSourceMap;
+ }
+
+ @SneakyThrows
+ private DataSource createDataSource() {
+ DataSource baseDataSource = mock(DataSource.class);
+ Connection connection = mock(Connection.class);
+ DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(databaseMetaData);
+ when(databaseMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/mysql?serverTimezone=GMT%2B8");
+ ResultSet resultSet = mock(ResultSet.class);
+ when(databaseMetaData.getTables(null, null, null, new String[]{TABLE_TYPE})).thenReturn(resultSet);
+ when(resultSet.next()).thenReturn(false);
+ when(baseDataSource.getConnection()).thenReturn(connection);
+ return baseDataSource;
Review comment:
The return value should name as `result`
##########
File path: shardingsphere-jdbc/shardingsphere-jdbc-orchestration/src/test/java/org/apache/shardingsphere/driver/orchestration/api/OrchestrationShardingSphereDataSourceFactoryTest.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.driver.orchestration.api;
+
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.cluster.configuration.config.ClusterConfiguration;
+import org.apache.shardingsphere.driver.orchestration.internal.datasource.OrchestrationShardingSphereDataSource;
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.metrics.configuration.config.MetricsConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationCenterConfiguration;
+import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+
+import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class OrchestrationShardingSphereDataSourceFactoryTest {
+ private static final String TABLE_TYPE = "TABLE";
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmpty() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWhenRuleConfigurationsNotEmptyWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSourceMap(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSource() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig(), mock(ClusterConfiguration.class), mock(MetricsConfiguration.class));
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ @SneakyThrows
+ @Test
+ public void assertCreateDataSourceWithGivenDataSourceWithClusterConfigurationAndMetricsConfigurationBothDefault() {
+ DataSource dataSource = OrchestrationShardingSphereDataSourceFactory.createDataSource(createDataSource(), Collections.singletonList(mock(RuleConfiguration.class)),
+ new Properties(), createOrchestrationConfig());
+ assertTrue(dataSource instanceof OrchestrationShardingSphereDataSource);
+ }
+
+ private Map<String, DataSource> createDataSourceMap() {
+ Map<String, DataSource> dataSourceMap = new HashMap<>();
+ dataSourceMap.put("dataSourceMapKey", createDataSource());
+ return dataSourceMap;
+ }
+
+ @SneakyThrows
+ private DataSource createDataSource() {
+ DataSource baseDataSource = mock(DataSource.class);
+ Connection connection = mock(Connection.class);
+ DatabaseMetaData databaseMetaData = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(databaseMetaData);
+ when(databaseMetaData.getURL()).thenReturn("jdbc:mysql://localhost:3306/mysql?serverTimezone=GMT%2B8");
+ ResultSet resultSet = mock(ResultSet.class);
+ when(databaseMetaData.getTables(null, null, null, new String[]{TABLE_TYPE})).thenReturn(resultSet);
+ when(resultSet.next()).thenReturn(false);
+ when(baseDataSource.getConnection()).thenReturn(connection);
+ return baseDataSource;
+ }
+
+ private OrchestrationConfiguration createOrchestrationConfig() {
+ OrchestrationConfiguration orchestrationConfig = mock(OrchestrationConfiguration.class);
+ OrchestrationCenterConfiguration orchestrationCenterConfiguration = mock(OrchestrationCenterConfiguration.class);
+ when(orchestrationConfig.getRegistryCenterConfiguration()).thenReturn(orchestrationCenterConfiguration);
+ when(orchestrationCenterConfiguration.getType()).thenReturn("REG_TEST");
+ return orchestrationConfig;
Review comment:
The return value should name as `result`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [shardingsphere] terrymanu merged pull request #7155: assertCreateDataSourceWhenRuleConfigurationsNotEmpty added
Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #7155:
URL: https://github.com/apache/shardingsphere/pull/7155
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org