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 e80ec94309f Refactor MySQLShowCreateDatabaseExecutorTest (#36861)
e80ec94309f is described below
commit e80ec94309f19098d466d0b236d3af2a8ca47b65
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 12 23:17:24 2025 +0800
Refactor MySQLShowCreateDatabaseExecutorTest (#36861)
---
.../show/MySQLShowCreateDatabaseExecutorTest.java | 28 +++++++---------------
1 file changed, 9 insertions(+), 19 deletions(-)
diff --git
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowCreateDatabaseExecutorTest.java
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowCreateDatabaseExecutorTest.java
index c5faad059a1..53b9887638d 100644
---
a/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowCreateDatabaseExecutorTest.java
+++
b/proxy/backend/dialect/mysql/src/test/java/org/apache/shardingsphere/proxy/backend/mysql/handler/admin/executor/show/MySQLShowCreateDatabaseExecutorTest.java
@@ -21,44 +21,34 @@ import
org.apache.shardingsphere.database.connector.core.type.DatabaseType;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
import
org.apache.shardingsphere.sql.parser.statement.mysql.dal.show.database.MySQLShowCreateDatabaseStatement;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import java.sql.SQLException;
-import java.util.Collection;
import java.util.Collections;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
import static org.hamcrest.CoreMatchers.is;
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;
@ExtendWith(MockitoExtension.class)
class MySQLShowCreateDatabaseExecutorTest {
- private static final String DATABASE_PATTERN = "db_%s";
-
private final DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, "MySQL");
@Test
void assertExecute() throws SQLException {
- MySQLShowCreateDatabaseStatement statement = new
MySQLShowCreateDatabaseStatement(databaseType, "db_0");
- MySQLShowCreateDatabaseExecutor executor = new
MySQLShowCreateDatabaseExecutor(statement);
- executor.execute(mock(ConnectionSession.class), new
ShardingSphereMetaData(createDatabases(), mock(), mock(), mock()));
+ MySQLShowCreateDatabaseStatement sqlStatement = new
MySQLShowCreateDatabaseStatement(databaseType, "foo_db");
+ MySQLShowCreateDatabaseExecutor executor = new
MySQLShowCreateDatabaseExecutor(sqlStatement);
+ executor.execute(mock(),
+ new ShardingSphereMetaData(Collections.singleton(new
ShardingSphereDatabase("foo_db", databaseType, mock(), mock(),
Collections.emptyList())), mock(), mock(), mock()));
assertThat(executor.getQueryResultMetaData().getColumnCount(), is(2));
- int count = 0;
- while (executor.getMergedResult().next()) {
- assertThat(executor.getMergedResult().getValue(1, Object.class),
is(String.format(DATABASE_PATTERN, count)));
- count++;
- }
- }
-
- private Collection<ShardingSphereDatabase> createDatabases() {
- return IntStream.range(0, 10)
- .mapToObj(each -> new
ShardingSphereDatabase(String.format(DATABASE_PATTERN, each), databaseType,
mock(), mock(), Collections.emptyList())).collect(Collectors.toList());
+ assertTrue(executor.getMergedResult().next());
+ assertThat(executor.getMergedResult().getValue(1, Object.class),
is("foo_db"));
+ assertFalse(executor.getMergedResult().next());
}
}