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 393588fdc05 Add more test cases on 
CreateIndexPushDownMetaDataRefresherTest, 
AlterIndexPushDownMetaDataRefresherTest and 
DropIndexPushDownMetaDataRefresherTest (#37200)
393588fdc05 is described below

commit 393588fdc05ac6bf439f9503014704a1ed379f56
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Nov 27 19:56:56 2025 +0800

    Add more test cases on CreateIndexPushDownMetaDataRefresherTest, 
AlterIndexPushDownMetaDataRefresherTest and 
DropIndexPushDownMetaDataRefresherTest (#37200)
---
 AGENTS.md                                          |   4 +-
 .../AlterIndexPushDownMetaDataRefresherTest.java   | 105 ++++++++++++++++++++
 .../CreateIndexPushDownMetaDataRefresherTest.java  | 100 +++++++++++++++++++
 .../DropIndexPushDownMetaDataRefresherTest.java    | 107 +++++++++++++++++++++
 4 files changed, 313 insertions(+), 3 deletions(-)

diff --git a/AGENTS.md b/AGENTS.md
index 69910ef099a..ab40e01927f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -242,10 +242,8 @@ Always state which topology, registry, and engine versions 
(e.g., MySQL 5.7 vs 8
 - When constructors hide collaborators, use `Plugins.getMemberAccessor()` to 
inject mocks and document why SPI creation is bypassed.
 - Cache SPI loader results (`OrderedSPILoader`, `TypedSPILoader`, 
`DatabaseTypedSPILoader`, etc.) per key at the test-class level to avoid 
redundant lookups.
 - If a test already uses `@ExtendWith(AutoMockExtension.class)`, always 
declare the needed static collaborators via `@StaticMockSettings` instead of 
hand-written `mockStatic` blocks; justify any exception explicitly in the plan 
before coding.
-- When a binder under test instantiates another binder (e.g., 
`SelectStatementBinder`, `TableSegmentBinder`), prefer `mockConstruction` and 
capture the injected context rather than reimplementing the constructor logic; 
only skip this approach if the plan explains why it cannot work.
-- Manage every static binder (`ColumnSegmentBinder`, 
`ExpressionSegmentBinder`, etc.) via `@StaticMockSettings` to avoid ad-hoc 
try-with-resources `mockStatic` blocks; if multiple static dependencies are 
needed, list each one in the plan.
-- For identifier formatting or dialect-dependent logic, default to mocking 
`DatabaseTypedSPILoader`/`TypedSPILoader` with scoped `MockedStatic` instead of 
loading real database types, to avoid ClassCast issues and 
environment-dependent casing.
 - Before adding coverage to a utility with multiple return paths, list every 
branch (no rule, non-Single config, wildcard blocks, missing data node, 
positive path, collection overload) and map each to a test; update the plan 
whenever this checklist changes.
+- Prefer imports over fully-qualified class names inside code and tests; if a 
class is used, add an import rather than using the full package path inline.
 
 ## 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/index/AlterIndexPushDownMetaDataRefresherTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/AlterIndexPushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..d19d8d6f640
--- /dev/null
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/AlterIndexPushDownMetaDataRefresherTest.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.mode.metadata.refresher.pushdown.type.index;
+
+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.ShardingSphereIndex;
+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.index.IndexNameSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.OwnerSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.index.AlterIndexStatement;
+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.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+@ExtendWith(MockitoExtension.class)
+class AlterIndexPushDownMetaDataRefresherTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
+    private final AlterIndexPushDownMetaDataRefresher refresher = 
(AlterIndexPushDownMetaDataRefresher) 
TypedSPILoader.getService(PushDownMetaDataRefresher.class, 
AlterIndexStatement.class);
+    
+    @Mock
+    private MetaDataManagerPersistService metaDataManagerPersistService;
+    
+    @Test
+    void assertRefreshReturnWhenRenameMissing() {
+        AlterIndexStatement sqlStatement = new 
AlterIndexStatement(databaseType);
+        sqlStatement.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 
0, new IdentifierValue("idx_old"))));
+        refresher.refresh(metaDataManagerPersistService, new 
ShardingSphereDatabase("foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()),
+                new RuleMetaData(Collections.emptyList()), 
Collections.emptyList()), "logic_ds", "foo_schema", databaseType, sqlStatement, 
new ConfigurationProperties(new Properties()));
+        verifyNoInteractions(metaDataManagerPersistService);
+    }
+    
+    @Test
+    void assertRefreshReturnWhenIndexMissing() {
+        AlterIndexStatement sqlStatement = new 
AlterIndexStatement(databaseType);
+        sqlStatement.setRenameIndex(new IndexSegment(0, 0, new 
IndexNameSegment(0, 0, new IdentifierValue("idx_new"))));
+        refresher.refresh(metaDataManagerPersistService, new 
ShardingSphereDatabase("foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()),
+                new RuleMetaData(Collections.emptyList()), 
Collections.emptyList()), "logic_ds", "foo_schema", databaseType, sqlStatement, 
new ConfigurationProperties(new Properties()));
+        verifyNoInteractions(metaDataManagerPersistService);
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    void assertRefreshRenameIndex() {
+        ShardingSphereTable table = new ShardingSphereTable(
+                "foo_tbl", Collections.emptyList(), Collections.singleton(new 
ShardingSphereIndex("idx_old", Collections.emptyList(), false)), 
Collections.emptyList());
+        ShardingSphereSchema schema = new ShardingSphereSchema("bar_schema", 
Collections.singleton(table), Collections.emptyList());
+        ShardingSphereDatabase database = new ShardingSphereDatabase(
+                "foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()), new 
RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+        AlterIndexStatement sqlStatement = createAlterStatement();
+        refresher.refresh(metaDataManagerPersistService, database, "logic_ds", 
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new 
Properties()));
+        ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor = 
ArgumentCaptor.forClass(Collection.class);
+        verify(metaDataManagerPersistService).alterTables(eq(database), 
eq("bar_schema"), alteredTablesCaptor.capture());
+        ShardingSphereTable actualTable = 
alteredTablesCaptor.getValue().iterator().next();
+        assertFalse(actualTable.containsIndex("idx_old"));
+        assertTrue(actualTable.containsIndex("idx_new"));
+    }
+    
+    private AlterIndexStatement createAlterStatement() {
+        AlterIndexStatement result = new AlterIndexStatement(databaseType);
+        IndexSegment index = new IndexSegment(0, 0, new IndexNameSegment(0, 0, 
new IdentifierValue("idx_old")));
+        index.setOwner(new OwnerSegment(0, 0, new 
IdentifierValue("BAR_SCHEMA")));
+        result.setIndex(index);
+        result.setRenameIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 
0, new IdentifierValue("idx_new"))));
+        return result;
+    }
+}
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/CreateIndexPushDownMetaDataRefresherTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/CreateIndexPushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..dbf29503a3d
--- /dev/null
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/CreateIndexPushDownMetaDataRefresherTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.index;
+
+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.ShardingSphereIndex;
+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.index.IndexNameSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.column.ColumnSegment;
+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.index.CreateIndexStatement;
+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.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+@ExtendWith(MockitoExtension.class)
+class CreateIndexPushDownMetaDataRefresherTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
+    private final CreateIndexPushDownMetaDataRefresher refresher = 
(CreateIndexPushDownMetaDataRefresher) 
TypedSPILoader.getService(PushDownMetaDataRefresher.class, 
CreateIndexStatement.class);
+    
+    @Mock
+    private MetaDataManagerPersistService metaDataManagerPersistService;
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    void assertRefreshCreateIndex() {
+        ShardingSphereSchema schema = new ShardingSphereSchema(
+                "foo_schema", Collections.singleton(new 
ShardingSphereTable("foo_tbl", Collections.emptyList(), 
Collections.emptyList(), Collections.emptyList())), Collections.emptyList());
+        ShardingSphereDatabase database = 
createDatabase(Collections.singleton(schema));
+        refresher.refresh(metaDataManagerPersistService, database, "logic_ds", 
"foo_schema", databaseType, createCreateIndexStatement(), new 
ConfigurationProperties(new Properties()));
+        ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor = 
ArgumentCaptor.forClass(Collection.class);
+        verify(metaDataManagerPersistService).alterTables(eq(database), 
eq("foo_schema"), alteredTablesCaptor.capture());
+        ShardingSphereTable actualTable = 
alteredTablesCaptor.getValue().iterator().next();
+        assertTrue(actualTable.containsIndex("idx_foo"));
+        ShardingSphereIndex actualIndex = 
actualTable.getAllIndexes().iterator().next();
+        assertThat(actualIndex.getColumns().iterator().next(), is("order_id"));
+    }
+    
+    private CreateIndexStatement createCreateIndexStatement() {
+        CreateIndexStatement result = new CreateIndexStatement(databaseType);
+        result.setTable(new SimpleTableSegment(new TableNameSegment(0, 0, new 
IdentifierValue("foo_tbl"))));
+        result.setIndex(new IndexSegment(0, 0, new IndexNameSegment(0, 0, new 
IdentifierValue("idx_foo"))));
+        result.getColumns().add(new ColumnSegment(0, 0, new 
IdentifierValue("order_id")));
+        return result;
+    }
+    
+    @Test
+    void assertRefreshThrowsWhenIndexCountInvalid() {
+        CreateIndexStatement sqlStatement = new 
CreateIndexStatement(databaseType);
+        assertThrows(IllegalArgumentException.class, () -> 
refresher.refresh(metaDataManagerPersistService,
+                createDatabase(Collections.emptyList()), "logic_ds", 
"foo_schema", databaseType, sqlStatement, new ConfigurationProperties(new 
Properties())));
+        verifyNoInteractions(metaDataManagerPersistService);
+    }
+    
+    private ShardingSphereDatabase createDatabase(final 
Collection<ShardingSphereSchema> schemas) {
+        return new ShardingSphereDatabase("foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()), new 
RuleMetaData(Collections.emptyList()), schemas);
+    }
+}
diff --git 
a/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/DropIndexPushDownMetaDataRefresherTest.java
 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/DropIndexPushDownMetaDataRefresherTest.java
new file mode 100644
index 00000000000..aeb3e47b9aa
--- /dev/null
+++ 
b/mode/core/src/test/java/org/apache/shardingsphere/mode/metadata/refresher/pushdown/type/index/DropIndexPushDownMetaDataRefresherTest.java
@@ -0,0 +1,107 @@
+/*
+ * 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.index;
+
+import org.apache.shardingsphere.database.connector.core.type.DatabaseType;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import 
org.apache.shardingsphere.infra.exception.kernel.metadata.TableNotFoundException;
+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.ShardingSphereIndex;
+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.index.IndexNameSegment;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.ddl.index.IndexSegment;
+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.index.DropIndexStatement;
+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.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoInteractions;
+
+@ExtendWith(MockitoExtension.class)
+class DropIndexPushDownMetaDataRefresherTest {
+    
+    private final DatabaseType databaseType = 
TypedSPILoader.getService(DatabaseType.class, "FIXTURE");
+    
+    private final DropIndexPushDownMetaDataRefresher refresher = 
(DropIndexPushDownMetaDataRefresher) 
TypedSPILoader.getService(PushDownMetaDataRefresher.class, 
DropIndexStatement.class);
+    
+    @Mock
+    private MetaDataManagerPersistService metaDataManagerPersistService;
+    
+    @Test
+    void assertRefreshSkipWhenLogicTableNotFound() {
+        ShardingSphereSchema schema = new ShardingSphereSchema("foo_db",
+                Collections.singleton(new ShardingSphereTable("foo_tbl", 
Collections.emptyList(), Collections.emptyList(), Collections.emptyList())), 
Collections.emptyList());
+        ShardingSphereDatabase database = new ShardingSphereDatabase(
+                "foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()), new 
RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+        DropIndexStatement sqlStatement = new DropIndexStatement(databaseType);
+        sqlStatement.getIndexes().add(new IndexSegment(0, 0, new 
IndexNameSegment(0, 0, new IdentifierValue("missing_idx"))));
+        refresher.refresh(metaDataManagerPersistService, database, "logic_ds", 
"foo_db", databaseType, sqlStatement, new ConfigurationProperties(new 
Properties()));
+        verifyNoInteractions(metaDataManagerPersistService);
+    }
+    
+    @Test
+    void assertRefreshThrowsTableNotFound() {
+        ShardingSphereSchema schema = new ShardingSphereSchema("foo_schema");
+        ShardingSphereDatabase database = new ShardingSphereDatabase(
+                "foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()), new 
RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+        DropIndexStatement sqlStatement = new DropIndexStatement(databaseType);
+        sqlStatement.setSimpleTable(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("foo_tbl"))));
+        sqlStatement.getIndexes().add(new IndexSegment(0, 0, new 
IndexNameSegment(0, 0, new IdentifierValue("idx_foo"))));
+        assertThrows(TableNotFoundException.class, () -> 
refresher.refresh(metaDataManagerPersistService,
+                database, "logic_ds", "foo_schema", databaseType, 
sqlStatement, new ConfigurationProperties(new Properties())));
+        verify(metaDataManagerPersistService, 
never()).alterTables(eq(database), eq("foo_schema"), any());
+    }
+    
+    @SuppressWarnings("unchecked")
+    @Test
+    void assertRefreshWithoutSimpleTableResolvesByMetaData() {
+        ShardingSphereTable table = new ShardingSphereTable(
+                "foo_tbl", Collections.emptyList(), Collections.singleton(new 
ShardingSphereIndex("idx_foo", Collections.emptyList(), false)), 
Collections.emptyList());
+        ShardingSphereSchema schema = new ShardingSphereSchema("foo_db", 
Collections.singleton(table), Collections.emptyList());
+        ShardingSphereDatabase database = new ShardingSphereDatabase(
+                "foo_db", databaseType, new 
ResourceMetaData(Collections.emptyMap()), new 
RuleMetaData(Collections.emptyList()), Collections.singleton(schema));
+        DropIndexStatement sqlStatement = new DropIndexStatement(databaseType);
+        sqlStatement.getIndexes().add(new IndexSegment(0, 0, new 
IndexNameSegment(0, 0, new IdentifierValue("idx_foo"))));
+        refresher.refresh(metaDataManagerPersistService, database, "logic_ds", 
"foo_db", databaseType, sqlStatement, new ConfigurationProperties(new 
Properties()));
+        ArgumentCaptor<Collection<ShardingSphereTable>> alteredTablesCaptor = 
ArgumentCaptor.forClass(Collection.class);
+        verify(metaDataManagerPersistService).alterTables(eq(database), 
eq("foo_db"), alteredTablesCaptor.capture());
+        ShardingSphereTable actualTable = 
alteredTablesCaptor.getValue().iterator().next();
+        assertFalse(actualTable.containsIndex("idx_foo"));
+    }
+}

Reply via email to