strongduanmu commented on a change in pull request #12635:
URL: https://github.com/apache/shardingsphere/pull/12635#discussion_r714425731



##########
File path: 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.mode.manager.standalone;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNode;
+import org.apache.shardingsphere.mode.metadata.persist.node.SchemaMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class StandaloneContextManagerBuilderTextTest {
+
+    public static final String TEST_DATA_SOURCE_INNER_MAP = 
"TEST_DATA_SOURCE_INNER_MAP";
+
+    public static final String TEST_CONNECTION_URL = 
"jdbc:mysql://testhost:3306/testdatabase";
+
+    @Test
+    public void assertBuild() throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourceMap = 
getDataSourceMap();
+        Map<String, Collection<RuleConfiguration>> schemaRuleConfigs = 
getSchemaRuleConfigs();
+        Collection<RuleConfiguration> globalRuleConfigurationCollection = 
getGlobalRuleConfigurationCollection();
+        final Properties props = new Properties();

Review comment:
       @fwhdzh Please remove this useless final modifier.

##########
File path: 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.mode.manager.standalone;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNode;
+import org.apache.shardingsphere.mode.metadata.persist.node.SchemaMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class StandaloneContextManagerBuilderTextTest {
+
+    public static final String TEST_DATA_SOURCE_INNER_MAP = 
"TEST_DATA_SOURCE_INNER_MAP";
+
+    public static final String TEST_CONNECTION_URL = 
"jdbc:mysql://testhost:3306/testdatabase";
+
+    @Test
+    public void assertBuild() throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourceMap = 
getDataSourceMap();
+        Map<String, Collection<RuleConfiguration>> schemaRuleConfigs = 
getSchemaRuleConfigs();
+        Collection<RuleConfiguration> globalRuleConfigurationCollection = 
getGlobalRuleConfigurationCollection();
+        final Properties props = new Properties();
+        ModeConfiguration modeConfiguration = new 
ModeConfiguration("testType", null, false);
+        StandaloneContextManagerBuilder standaloneContextManagerBuilder = new 
StandaloneContextManagerBuilder();
+        ContextManager actual = 
standaloneContextManagerBuilder.build(modeConfiguration, dataSourceMap, 
schemaRuleConfigs, globalRuleConfigurationCollection, props, false, 1000);
+        MetaDataContexts metaDataContexts = actual.getMetaDataContexts();
+        
assertNotNull(metaDataContexts.getMetaDataMap().get(TEST_DATA_SOURCE_INNER_MAP));
+        assertNotNull(metaDataContexts.getExecutorEngine());
+        PersistRepository resultRepository = 
metaDataContexts.getMetaDataPersistService().get().getRepository();
+        assertNotNull(resultRepository.get(GlobalNode.getGlobalRuleNode()));
+        
assertNotNull(resultRepository.get(SchemaMetaDataNode.getMetaDataDataSourcePath(TEST_DATA_SOURCE_INNER_MAP)));
+        
assertNotNull(resultRepository.get(SchemaMetaDataNode.getRulePath(TEST_DATA_SOURCE_INNER_MAP)));
+        TransactionContexts transactionContexts = 
actual.getTransactionContexts();
+        assertNotNull(transactionContexts.getEngines());
+        
assertNotNull(transactionContexts.getEngines().get(TEST_DATA_SOURCE_INNER_MAP));
+    }
+
+    private Map<String, Map<String, DataSource>> getDataSourceMap() throws 
SQLException {
+        Connection connection = mock(Connection.class, RETURNS_DEEP_STUBS);
+        
when(connection.getMetaData().getURL()).thenReturn(TEST_CONNECTION_URL);
+        DataSource dataSource = mock(DataSource.class, RETURNS_DEEP_STUBS);
+        when(dataSource.getConnection()).thenReturn(connection);
+        Map<String, DataSource> dataSourceInnerMap = new HashMap<>();
+        dataSourceInnerMap.put("testDataSource", dataSource);
+        Map<String, Map<String, DataSource>> result = new HashMap<>();
+        result.put(TEST_DATA_SOURCE_INNER_MAP, dataSourceInnerMap);
+        return result;
+    }
+
+    private Map<String, Collection<RuleConfiguration>> getSchemaRuleConfigs() {
+        RuleConfiguration ruleConfiguration = mock(RuleConfiguration.class);
+        Collection<RuleConfiguration> ruleConfigurationCollection = new 
LinkedList<>();
+        ruleConfigurationCollection.add(ruleConfiguration);
+        Map<String, Collection<RuleConfiguration>> result = new HashMap<>();
+        result.put(TEST_DATA_SOURCE_INNER_MAP, ruleConfigurationCollection);
+        return result;
+    }
+
+    private Collection<RuleConfiguration> 
getGlobalRuleConfigurationCollection() {
+        RuleConfiguration globalRuleConfiguration = 
mock(RuleConfiguration.class);
+        Collection<RuleConfiguration> globalRuleConfigurationCollection = new 
HashSet<>();
+        globalRuleConfigurationCollection.add(globalRuleConfiguration);
+        return globalRuleConfigurationCollection;

Review comment:
       @fwhdzh Maybe `result` is better.

##########
File path: 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/fixture/StandalonePersistRepositoryFixture.java
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.mode.manager.standalone.fixture;
+
+import 
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRepository;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public final class StandalonePersistRepositoryFixture implements 
StandalonePersistRepository {
+
+    private Map<String, String> persistMap = new HashMap<>();
+
+    @Override
+    public String get(final String key) {
+        return persistMap.get(key);
+    }
+
+    @Override
+    public List<String> getChildrenKeys(final String key) {
+        List<String> result = new LinkedList<>();
+        for (String each: persistMap.keySet()) {
+            if (each.startsWith(key)) {
+                String child = each.substring(key.length() + 1, 
each.indexOf('/', key.length() + 1));
+                if (!result.contains(child)) {
+                    result.add(child);
+                }
+            }
+        }
+        return result;
+    }
+
+    @Override
+    public void persist(final String key, final String value) {
+        persistMap.put(key, value);
+    }
+
+    @Override
+    public void delete(final String key) {
+

Review comment:
       @fwhdzh Please remove useless blank line.

##########
File path: 
shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilderTextTest.java
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.mode.manager.standalone;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.mode.metadata.persist.node.GlobalNode;
+import org.apache.shardingsphere.mode.metadata.persist.node.SchemaMetaDataNode;
+import org.apache.shardingsphere.mode.persist.PersistRepository;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.junit.Test;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class StandaloneContextManagerBuilderTextTest {
+
+    public static final String TEST_DATA_SOURCE_INNER_MAP = 
"TEST_DATA_SOURCE_INNER_MAP";
+
+    public static final String TEST_CONNECTION_URL = 
"jdbc:mysql://testhost:3306/testdatabase";
+
+    @Test
+    public void assertBuild() throws SQLException {
+        Map<String, Map<String, DataSource>> dataSourceMap = 
getDataSourceMap();
+        Map<String, Collection<RuleConfiguration>> schemaRuleConfigs = 
getSchemaRuleConfigs();
+        Collection<RuleConfiguration> globalRuleConfigurationCollection = 
getGlobalRuleConfigurationCollection();
+        final Properties props = new Properties();

Review comment:
       @fwhdzh Please remove this useless final modifier.




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to