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 2022/04/15 10:39:56 UTC

[GitHub] [shardingsphere] tianhao960 commented on a diff in pull request #16832: for issue 14083, add test for RenameTableStatementSchemaRefresher

tianhao960 commented on code in PR #16832:
URL: https://github.com/apache/shardingsphere/pull/16832#discussion_r851205290


##########
shardingsphere-infra/shardingsphere-infra-context/src/test/java/org/apache/shardingsphere/infra/context/refresher/type/RenameTableStatementSchemaRefresherTest.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.infra.context.refresher.type;
+
+import com.google.common.eventbus.Subscribe;
+import lombok.RequiredArgsConstructor;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.type.dialect.SQL92DatabaseType;
+import org.apache.shardingsphere.infra.eventbus.ShardingSphereEventBus;
+import org.apache.shardingsphere.infra.federation.optimizer.context.planner.OptimizerPlannerContext;
+import org.apache.shardingsphere.infra.federation.optimizer.metadata.FederationDatabaseMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.infra.metadata.schema.event.SchemaAlteredEvent;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.RenameTableStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
+import javax.sql.DataSource;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class RenameTableStatementSchemaRefresherTest {
+
+    private final String oriTableNamePrefix = "TABLE";
+
+    private final String newTableNamePrefix = "NEW_TABLE";
+
+    private final String schemaMetaDataName = "SCHEMA_META_DATA_NAME";
+
+    private final String databaseName = "DATABASE_NAME";
+
+    private final String logicDataSourceName = "LOGIC_DATA_SOURCE_NAME";
+
+    @Mock
+    private ShardingSphereMetaData schemaMetaData;
+
+    @Mock
+    private FederationDatabaseMetaData database;
+
+    @Mock
+    private Map<String, OptimizerPlannerContext> optimizerPlanners;
+
+    private List<String> logicDataSourceNames;
+
+    @Mock
+    private RenameTableStatement sqlStatement;
+
+    @InjectMocks
+    private ConfigurationProperties props;
+
+    @Mock
+    private ShardingSphereResource shardingSphereResource;
+
+    @Mock
+    private ShardingSphereSchema shardingSphereSchema;
+
+    private RenameTableStatementSchemaRefresher renameTableStatementSchemaRefresher;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+        renameTableStatementSchemaRefresher = new RenameTableStatementSchemaRefresher();
+    }
+
+    @Test
+    public void assertRefreshNonRenameTableStatement() {
+        refreshRenameTableStatement(0);
+    }
+
+    @Test
+    public void assertRefreshOneRenameTableStatement() {
+        refreshRenameTableStatement(1);
+    }
+
+    @Test
+    public void assertRefreshMultipleRenameTableStatement() {
+        refreshRenameTableStatement(2);
+    }
+
+    @SneakyThrows
+    private void refreshRenameTableStatement(final int renameStatementCount) {
+        Collection<RenameTableDefinitionSegment> renameTables = new LinkedList<>();
+        for (Integer i = 0; i < renameStatementCount; i++) {

Review Comment:
   the following code uses the Integer.toString() method, so using the Integer, not int.  Thanks.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org