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 8b19d81195b Refactor AlterSQLParserRuleExecutorTest Test Case (#31199)
8b19d81195b is described below

commit 8b19d81195b211557844707dfcecb1332b154edd
Author: ilyas ahsan <[email protected]>
AuthorDate: Fri May 10 22:56:22 2024 +0700

    Refactor AlterSQLParserRuleExecutorTest Test Case (#31199)
---
 .../update/AlterSQLParserRuleExecutorTest.java     | 41 +++++++++++++++++-----
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git 
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
 
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
index 0e0ac8abcdd..209e5d179a8 100644
--- 
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
+++ 
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
@@ -17,6 +17,9 @@
 
 package org.apache.shardingsphere.parser.distsql.handler.update;
 
+import 
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine;
+import 
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global.GlobalRuleDefinitionExecutor;
+import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
 import org.apache.shardingsphere.parser.distsql.segment.CacheOptionSegment;
 import 
org.apache.shardingsphere.parser.distsql.statement.updatable.AlterSQLParserRuleStatement;
@@ -24,25 +27,45 @@ import org.apache.shardingsphere.parser.rule.SQLParserRule;
 import 
org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
 import org.junit.jupiter.api.Test;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 class AlterSQLParserRuleExecutorTest {
     
+    private DistSQLUpdateExecuteEngine engine;
+    
     @Test
     void assertExecute() {
-        AlterSQLParserRuleExecutor executor = new AlterSQLParserRuleExecutor();
         AlterSQLParserRuleStatement sqlStatement = new 
AlterSQLParserRuleStatement(new CacheOptionSegment(64, 512L), new 
CacheOptionSegment(1000, 1000L));
+        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+        assertDoesNotThrow(() -> engine.executeUpdate());
+    }
+    
+    @Test
+    void assertExecuteWithNullStatement() {
+        AlterSQLParserRuleStatement sqlStatement = new 
AlterSQLParserRuleStatement(null, null);
+        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+        assertDoesNotThrow(() -> engine.executeUpdate());
+    }
+    
+    @Test
+    void assertExecuteWithNullCacheOptionSegment() {
+        AlterSQLParserRuleStatement sqlStatement = new 
AlterSQLParserRuleStatement(new CacheOptionSegment(null, null), new 
CacheOptionSegment(null, null));
+        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+        assertDoesNotThrow(() -> engine.executeUpdate());
+    }
+    
+    @SuppressWarnings({"rawtypes", "unchecked"})
+    private ContextManager mockContextManager() {
+        ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         SQLParserRule rule = mock(SQLParserRule.class);
+        GlobalRuleDefinitionExecutor executor = 
mock(GlobalRuleDefinitionExecutor.class);
+        when(executor.getRuleClass()).thenReturn(SQLParserRule.class);
         
when(rule.getConfiguration()).thenReturn(getSQLParserRuleConfiguration());
-        executor.setRule(rule);
-        SQLParserRuleConfiguration actual = 
executor.buildToBeAlteredRuleConfiguration(sqlStatement);
-        assertThat(actual.getSqlStatementCache().getInitialCapacity(), 
is(1000));
-        assertThat(actual.getSqlStatementCache().getMaximumSize(), is(1000L));
-        assertThat(actual.getParseTreeCache().getInitialCapacity(), is(64));
-        assertThat(actual.getParseTreeCache().getMaximumSize(), is(512L));
+        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule);
+        return result;
     }
     
     private SQLParserRuleConfiguration getSQLParserRuleConfiguration() {

Reply via email to