This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 fd722adb6b6 Add more test cases on TablePushDownMetaDataRefresherTest
(#37202)
fd722adb6b6 is described below
commit fd722adb6b601fe7fe4b1c703f7e77a55bfa171e
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 27 21:41:57 2025 +0800
Add more test cases on TablePushDownMetaDataRefresherTest (#37202)
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
* Add more test cases on TablePushDownMetaDataRefresherTest
---
AGENTS.md | 2 +
.../AlterTablePushDownMetaDataRefresherTest.java | 120 +++++++++++++++++++++
.../CreateTablePushDownMetaDataRefresherTest.java | 102 ++++++++++++++++++
.../DropTablePushDownMetaDataRefresherTest.java | 63 +++++++++++
.../RenameTablePushDownMetaDataRefresherTest.java | 79 ++++++++++++++
.../refresher/util/TableRefreshUtilsTest.java | 5 +-
6 files changed, 369 insertions(+), 2 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 36c65654479..c5a74c061b9 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -246,6 +246,8 @@ Always state which topology, registry, and engine versions
(e.g., MySQL 5.7 vs 8
- Before coding tests, prepare a concise branch-and-data checklist (all
branches, inputs, expected outputs) and keep the plan in sync when the
checklist changes.
- When a component is available via SPI (e.g., `TypedSPILoader`,
`DatabaseTypedSPILoader`, `PushDownMetaDataRefresher`), obtain the instance
through SPI by default; note any exceptions in the plan.
- Do not mix Mockito matchers with raw arguments; choose a single style per
invocation, and ensure the Mockito extension aligns with the mocking approach.
+- Never leave fully-qualified class names in production or test code; if a
class is referenced, add an import and verify via a quick scan (`rg "\\."
<path>`) before finishing.
+- When the user requires full branch/line coverage, treat 100% coverage as a
blocking condition: enumerate branches, map tests, and keep adding cases until
all branches are covered or explicitly waived; record the coverage requirement
in the plan and self-check before concluding.
## Brevity & Signal
- Prefer tables/bullets over prose walls; cite file paths (`kernel/src/...`)
directly.
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/AlterTablePushDownMetaDataRefresherTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/AlterTablePushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..52ec3ccd98b
--- /dev/null
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/AlterTablePushDownMetaDataRefresherTest.java
@@ -0,0 +1,120 @@
+/*
+ * 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.metadata.refresher.pushdown.type.table;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import
org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.mode.metadata.refresher.pushdown.PushDownMetaDataRefresher;
+import
org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils;
+import
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.AlterTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings({TableRefreshUtils.class, GenericSchemaBuilder.class})
+class AlterTablePushDownMetaDataRefresherTest {
+
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+
+ private final AlterTablePushDownMetaDataRefresher refresher =
(AlterTablePushDownMetaDataRefresher)
TypedSPILoader.getService(PushDownMetaDataRefresher.class,
AlterTableStatement.class);
+
+ @Mock
+ private MetaDataManagerPersistService metaDataManagerPersistService;
+
+ @Mock
+ private MutableDataNodeRuleAttribute mutableDataNodeRuleAttribute;
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertRefreshRenameTable() throws Exception {
+ ShardingSphereRule rule = mock(ShardingSphereRule.class);
+ when(rule.getAttributes()).thenReturn(new
RuleAttributes(mutableDataNodeRuleAttribute));
+ AlterTableStatement sqlStatement = new
AlterTableStatement(databaseType);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("foo_tbl"))));
+ sqlStatement.setRenameTable(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))));
+
when(TableRefreshUtils.getTableName(sqlStatement.getTable().getTableName().getIdentifier(),
databaseType)).thenReturn("foo_tbl");
+ when(TableRefreshUtils.isSingleTable(any(), any())).thenReturn(true);
+ ShardingSphereTable renamedTable = new ShardingSphereTable("bar_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ Map<String, ShardingSphereSchema> schemas =
Collections.singletonMap("foo_schema", new ShardingSphereSchema("foo_schema",
Collections.singleton(renamedTable), Collections.emptyList()));
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.singleton(rule)), Collections.emptyList());
+
when(GenericSchemaBuilder.build(eq(Collections.singletonList("bar_tbl")),
eq(database.getProtocolType()), any())).thenReturn(schemas);
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ ArgumentCaptor<Collection<String>> droppedTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ verify(mutableDataNodeRuleAttribute).put("logic_ds", "foo_schema",
"bar_tbl");
+ verify(metaDataManagerPersistService).alterTables(eq(database),
eq("foo_schema"), alteredTablesCaptor.capture());
+ verify(metaDataManagerPersistService).dropTables(eq(database),
eq("foo_schema"), droppedTablesCaptor.capture());
+ assertThat(alteredTablesCaptor.getValue().iterator().next().getName(),
is("bar_tbl"));
+ assertThat(droppedTablesCaptor.getValue().iterator().next(),
is("foo_tbl"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertRefreshAlterTableWithoutRename() throws Exception {
+ ShardingSphereRule rule = mock(ShardingSphereRule.class);
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.singleton(rule)), Collections.emptyList());
+ AlterTableStatement sqlStatement = new
AlterTableStatement(databaseType);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("foo_tbl"))));
+
when(TableRefreshUtils.getTableName(sqlStatement.getTable().getTableName().getIdentifier(),
databaseType)).thenReturn("foo_tbl");
+ when(TableRefreshUtils.isSingleTable("foo_tbl",
database)).thenReturn(false);
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ Map<String, ShardingSphereSchema> schemas =
Collections.singletonMap("foo_schema", new ShardingSphereSchema("foo_schema",
Collections.singleton(table), Collections.emptyList()));
+
when(GenericSchemaBuilder.build(eq(Collections.singletonList("foo_tbl")),
eq(database.getProtocolType()), any())).thenReturn(schemas);
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ ArgumentCaptor<Collection<String>> droppedTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ verify(metaDataManagerPersistService).alterTables(eq(database),
eq("foo_schema"), alteredTablesCaptor.capture());
+ verify(metaDataManagerPersistService).dropTables(eq(database),
eq("foo_schema"), droppedTablesCaptor.capture());
+ assertThat(alteredTablesCaptor.getValue().iterator().next().getName(),
is("foo_tbl"));
+ assertTrue(droppedTablesCaptor.getValue().isEmpty());
+ }
+}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/CreateTablePushDownMetaDataRefresherTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/CreateTablePushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..1c288fe39ed
--- /dev/null
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/CreateTablePushDownMetaDataRefresherTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.metadata.refresher.pushdown.type.table;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.schema.builder.GenericSchemaBuilder;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.infra.rule.attribute.RuleAttributes;
+import
org.apache.shardingsphere.infra.rule.attribute.datanode.MutableDataNodeRuleAttribute;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.mode.metadata.refresher.pushdown.PushDownMetaDataRefresher;
+import
org.apache.shardingsphere.mode.metadata.refresher.util.TableRefreshUtils;
+import
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.CreateTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.AutoMockExtension;
+import
org.apache.shardingsphere.test.infra.framework.extension.mock.StaticMockSettings;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(AutoMockExtension.class)
+@StaticMockSettings({TableRefreshUtils.class, GenericSchemaBuilder.class})
+class CreateTablePushDownMetaDataRefresherTest {
+
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+
+ private final CreateTablePushDownMetaDataRefresher refresher =
(CreateTablePushDownMetaDataRefresher)
TypedSPILoader.getService(PushDownMetaDataRefresher.class,
CreateTableStatement.class);
+
+ @Mock
+ private MetaDataManagerPersistService metaDataManagerPersistService;
+
+ @Mock
+ private MutableDataNodeRuleAttribute mutableDataNodeRuleAttribute;
+
+ @Test
+ void assertRefreshCreatesTableAndPutsSingleTableMapping() throws Exception
{
+ ShardingSphereRule rule = mock(ShardingSphereRule.class);
+ when(rule.getAttributes()).thenReturn(new
RuleAttributes(mutableDataNodeRuleAttribute));
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.singleton(rule)), Collections.emptyList());
+ CreateTableStatement sqlStatement = new
CreateTableStatement(databaseType);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("foo_tbl"))));
+
when(TableRefreshUtils.getTableName(sqlStatement.getTable().getTableName().getIdentifier(),
databaseType)).thenReturn("foo_tbl");
+ when(TableRefreshUtils.isSingleTable("foo_tbl",
database)).thenReturn(true);
+ ShardingSphereTable loadedTable = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ Map<String, ShardingSphereSchema> schemas =
Collections.singletonMap("foo_schema", new ShardingSphereSchema("foo_schema",
Collections.singleton(loadedTable), Collections.emptyList()));
+
when(GenericSchemaBuilder.build(eq(Collections.singletonList("foo_tbl")),
eq(database.getProtocolType()), any())).thenReturn(schemas);
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ verify(mutableDataNodeRuleAttribute).put("logic_ds", "foo_schema",
"foo_tbl");
+ verify(metaDataManagerPersistService).createTable(database,
"foo_schema", loadedTable);
+ }
+
+ @Test
+ void assertRefreshCreatesTableWithoutSingleTableMapping() throws Exception
{
+ ShardingSphereTable loadedTable = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ Map<String, ShardingSphereSchema> schemas =
Collections.singletonMap("foo_schema", new ShardingSphereSchema("foo_schema",
Collections.singleton(loadedTable), Collections.emptyList()));
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), Collections.emptyList());
+ CreateTableStatement sqlStatement = new
CreateTableStatement(databaseType);
+ sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0,
0, new IdentifierValue("foo_tbl"))));
+
when(TableRefreshUtils.getTableName(sqlStatement.getTable().getTableName().getIdentifier(),
databaseType)).thenReturn("foo_tbl");
+
when(GenericSchemaBuilder.build(eq(Collections.singletonList("foo_tbl")),
eq(database.getProtocolType()), any())).thenReturn(schemas);
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ verify(mutableDataNodeRuleAttribute, never()).put("logic_ds",
"foo_schema", "foo_tbl");
+ verify(metaDataManagerPersistService).createTable(database,
"foo_schema", loadedTable);
+ }
+}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/DropTablePushDownMetaDataRefresherTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/DropTablePushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..1bdde689764
--- /dev/null
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/DropTablePushDownMetaDataRefresherTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.metadata.refresher.pushdown.type.table;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.mode.metadata.refresher.pushdown.PushDownMetaDataRefresher;
+import
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.DropTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+class DropTablePushDownMetaDataRefresherTest {
+
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+
+ private final DropTablePushDownMetaDataRefresher refresher =
(DropTablePushDownMetaDataRefresher)
TypedSPILoader.getService(PushDownMetaDataRefresher.class,
DropTableStatement.class);
+
+ @Mock
+ private MetaDataManagerPersistService metaDataManagerPersistService;
+
+ @Test
+ void assertRefresh() {
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), Collections.emptyList());
+ DropTableStatement sqlStatement = new DropTableStatement(databaseType);
+ sqlStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
+ sqlStatement.getTables().add(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))));
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ verify(metaDataManagerPersistService).dropTables(database,
"foo_schema", Arrays.asList("foo_tbl", "bar_tbl"));
+ }
+}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/RenameTablePushDownMetaDataRefresherTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/RenameTablePushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..6cada5f0049
--- /dev/null
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/table/RenameTablePushDownMetaDataRefresherTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.metadata.refresher.pushdown.type.table;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import
org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereSchema;
+import
org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereTable;
+import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
+import
org.apache.shardingsphere.mode.metadata.refresher.pushdown.PushDownMetaDataRefresher;
+import
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.table.RenameTableDefinitionSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.TableNameSegment;
+import
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.table.RenameTableStatement;
+import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+
+@ExtendWith(MockitoExtension.class)
+class RenameTablePushDownMetaDataRefresherTest {
+
+ private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+
+ private final RenameTablePushDownMetaDataRefresher refresher =
(RenameTablePushDownMetaDataRefresher)
TypedSPILoader.getService(PushDownMetaDataRefresher.class,
RenameTableStatement.class);
+
+ @Mock
+ private MetaDataManagerPersistService metaDataManagerPersistService;
+
+ @SuppressWarnings("unchecked")
+ @Test
+ void assertRefreshRenamesTables() {
+ ShardingSphereTable table = new ShardingSphereTable("foo_tbl",
Collections.emptyList(), Collections.emptyList(), Collections.emptyList());
+ ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema",
Collections.singleton(table), Collections.emptyList());
+ ShardingSphereDatabase database = new ShardingSphereDatabase(
+ "foo_db", databaseType, new
ResourceMetaData(Collections.emptyMap()), new
RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+ RenameTableDefinitionSegment renameDef = new
RenameTableDefinitionSegment(0, 0);
+ renameDef.setTable(new SimpleTableSegment(new TableNameSegment(0, 0,
new IdentifierValue("foo_tbl"))));
+ renameDef.setRenameTable(new SimpleTableSegment(new
TableNameSegment(0, 0, new IdentifierValue("bar_tbl"))));
+ RenameTableStatement sqlStatement = new
RenameTableStatement(databaseType, Collections.singleton(renameDef));
+ refresher.refresh(metaDataManagerPersistService, database, "logic_ds",
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new
Properties()));
+ ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ ArgumentCaptor<Collection<String>> droppedTablesCaptor =
ArgumentCaptor.forClass(Collection.class);
+ verify(metaDataManagerPersistService).alterTables(eq(database),
eq("foo_schema"), alteredTablesCaptor.capture());
+ verify(metaDataManagerPersistService).dropTables(eq(database),
eq("foo_schema"), droppedTablesCaptor.capture());
+ assertThat(alteredTablesCaptor.getValue().iterator().next().getName(),
is("bar_tbl"));
+ assertThat(droppedTablesCaptor.getValue().iterator().next(),
is("foo_tbl"));
+ }
+}
diff --git
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
index 742da2fa239..0b2453f05d3 100644
---
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
+++
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/util/TableRefreshUtilsTest.java
@@ -48,6 +48,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
@ExtendWith(AutoMockExtension.class)
@@ -70,7 +71,7 @@ class TableRefreshUtilsTest {
DatabaseType upperCaseDatabaseType = mock(DatabaseType.class);
DialectDatabaseMetaData dialectDatabaseMetaData =
mock(DialectDatabaseMetaData.class);
when(dialectDatabaseMetaData.getIdentifierPatternType()).thenReturn(IdentifierPatternType.UPPER_CASE);
- try (MockedStatic<DatabaseTypedSPILoader> mockedStatic =
org.mockito.Mockito.mockStatic(DatabaseTypedSPILoader.class)) {
+ try (MockedStatic<DatabaseTypedSPILoader> mockedStatic =
mockStatic(DatabaseTypedSPILoader.class)) {
mockedStatic.when(() ->
DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class,
upperCaseDatabaseType)).thenReturn(dialectDatabaseMetaData);
assertThat(TableRefreshUtils.getTableName(new
IdentifierValue("foo_table"), upperCaseDatabaseType), is("FOO_TABLE"));
}
@@ -81,7 +82,7 @@ class TableRefreshUtilsTest {
DatabaseType lowerCaseDatabaseType = mock(DatabaseType.class);
DialectDatabaseMetaData dialectDatabaseMetaData =
mock(DialectDatabaseMetaData.class);
when(dialectDatabaseMetaData.getIdentifierPatternType()).thenReturn(IdentifierPatternType.LOWER_CASE);
- try (MockedStatic<DatabaseTypedSPILoader> mockedStatic =
org.mockito.Mockito.mockStatic(DatabaseTypedSPILoader.class)) {
+ try (MockedStatic<DatabaseTypedSPILoader> mockedStatic =
mockStatic(DatabaseTypedSPILoader.class)) {
mockedStatic.when(() ->
DatabaseTypedSPILoader.getService(DialectDatabaseMetaData.class,
lowerCaseDatabaseType)).thenReturn(dialectDatabaseMetaData);
assertThat(TableRefreshUtils.getTableName(new
IdentifierValue("Foo_Table"), lowerCaseDatabaseType), is("foo_table"));
}