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 f5699ac182a Refactor AlterSQLFederationRuleExecutorTest Test Case 
(#31170)
f5699ac182a is described below

commit f5699ac182a6c4b382c21d3833f12dbf53efee96
Author: ilyas ahsan <[email protected]>
AuthorDate: Thu May 9 10:35:46 2024 +0700

    Refactor AlterSQLFederationRuleExecutorTest Test Case (#31170)
    
    * Refactor AlterSQLFederationRuleExecutorTest Test Case
    
    * Refactor AlterSQLFederationRuleExecutorTest Test Case
---
 .../update/AlterSQLFederationRuleExecutorTest.java | 47 +++++++++++++++-------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git 
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
 
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
index 7f355866727..0568c4491a7 100644
--- 
a/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
+++ 
b/kernel/sql-federation/distsql/handler/src/test/java/org/apache/shardingsphere/sqlfederation/distsql/handler/update/AlterSQLFederationRuleExecutorTest.java
@@ -17,36 +17,53 @@
 
 package org.apache.shardingsphere.sqlfederation.distsql.handler.update;
 
-import 
org.apache.shardingsphere.sqlfederation.api.config.SQLFederationRuleConfiguration;
+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.sqlfederation.distsql.segment.CacheOptionSegment;
 import 
org.apache.shardingsphere.sqlfederation.distsql.statement.updatable.AlterSQLFederationRuleStatement;
 import org.apache.shardingsphere.sqlfederation.rule.SQLFederationRule;
 import 
org.apache.shardingsphere.sqlfederation.rule.builder.DefaultSQLFederationRuleConfigurationBuilder;
 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.assertTrue;
+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 AlterSQLFederationRuleExecutorTest {
     
+    private DistSQLUpdateExecuteEngine engine;
+    
     @Test
     void assertExecute() {
-        AlterSQLFederationRuleExecutor executor = new 
AlterSQLFederationRuleExecutor();
         AlterSQLFederationRuleStatement sqlStatement = new 
AlterSQLFederationRuleStatement(true, true, new CacheOptionSegment(64, 512L));
-        SQLFederationRule rule = mock(SQLFederationRule.class);
-        
when(rule.getConfiguration()).thenReturn(getSQLFederationRuleConfiguration());
-        executor.setRule(rule);
-        SQLFederationRuleConfiguration actual = 
executor.buildToBeAlteredRuleConfiguration(sqlStatement);
-        assertTrue(actual.isSqlFederationEnabled());
-        assertTrue(actual.isAllQueryUseSQLFederation());
-        assertThat(actual.getExecutionPlanCache().getInitialCapacity(), 
is(64));
-        assertThat(actual.getExecutionPlanCache().getMaximumSize(), is(512L));
+        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+        assertDoesNotThrow(() -> engine.executeUpdate());
+    }
+    
+    @Test
+    void testExecuteWithNullStatement() {
+        AlterSQLFederationRuleStatement sqlStatement = new 
AlterSQLFederationRuleStatement(null, null, null);
+        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+        assertDoesNotThrow(() -> engine.executeUpdate());
     }
     
-    private SQLFederationRuleConfiguration getSQLFederationRuleConfiguration() 
{
-        return new DefaultSQLFederationRuleConfigurationBuilder().build();
+    @Test
+    void testExecuteWithNullCacheOptionSegment() {
+        AlterSQLFederationRuleStatement sqlStatement = new 
AlterSQLFederationRuleStatement(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);
+        SQLFederationRule rule = mock(SQLFederationRule.class);
+        GlobalRuleDefinitionExecutor executor = 
mock(GlobalRuleDefinitionExecutor.class);
+        when(executor.getRuleClass()).thenReturn(SQLFederationRule.class);
+        when(rule.getConfiguration()).thenReturn(new 
DefaultSQLFederationRuleConfigurationBuilder().build());
+        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule);
+        return result;
     }
 }

Reply via email to