This is an automated email from the ASF dual-hosted git repository.

totalo 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 764d52a7afb Add more assertions for AlterGlobalClockRuleExecutorTest 
(#33103)
764d52a7afb is described below

commit 764d52a7afbb4e8a9adad233ff4876b42a68e133
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Oct 3 15:28:06 2024 +0800

    Add more assertions for AlterGlobalClockRuleExecutorTest (#33103)
    
    * Refactor ShowGlobalClockRuleExecutorTest
    
    * Add more assertions for AlterGlobalClockRuleExecutorTest
    
    * Add more assertions for ShowGlobalClockRuleExecutorTest
---
 .../query/ShowGlobalClockRuleExecutorTest.java     | 40 ++++++++-----------
 .../update/AlterGlobalClockRuleExecutorTest.java   | 45 ++++++++++++----------
 2 files changed, 41 insertions(+), 44 deletions(-)

diff --git 
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
 
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
index 66e8611b51e..e9dfc77b8e3 100644
--- 
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
+++ 
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java
@@ -20,19 +20,19 @@ package 
org.apache.shardingsphere.globalclock.distsql.handler.query;
 import 
org.apache.shardingsphere.distsql.handler.engine.DistSQLConnectionContext;
 import 
org.apache.shardingsphere.distsql.handler.engine.query.DistSQLQueryExecuteEngine;
 import 
org.apache.shardingsphere.globalclock.config.GlobalClockRuleConfiguration;
-import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
 import 
org.apache.shardingsphere.globalclock.distsql.statement.queryable.ShowGlobalClockRuleStatement;
+import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
 import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
-import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
 import java.sql.SQLException;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Optional;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -42,31 +42,23 @@ import static org.mockito.Mockito.when;
 
 class ShowGlobalClockRuleExecutorTest {
     
-    private DistSQLQueryExecuteEngine engine;
-    
-    @BeforeEach
-    void setUp() {
-        engine = new DistSQLQueryExecuteEngine(new 
ShowGlobalClockRuleStatement(), null, mockContextManager(), 
mock(DistSQLConnectionContext.class));
+    @Test
+    void assertGlobalClockRule() throws SQLException {
+        DistSQLQueryExecuteEngine engine = new DistSQLQueryExecuteEngine(new 
ShowGlobalClockRuleStatement(), null, mockContextManager(), 
mock(DistSQLConnectionContext.class));
+        engine.executeQuery();
+        List<LocalDataQueryResultRow> actual = new 
ArrayList<>(engine.getRows());
+        assertThat(actual.size(), is(1));
+        assertThat(actual.get(0).getCell(1), is("TSO"));
+        assertThat(actual.get(0).getCell(2), is("local"));
+        assertThat(actual.get(0).getCell(3), is("false"));
+        assertThat(actual.get(0).getCell(4), is("{\"key\":\"value\"}"));
     }
     
     private ContextManager mockContextManager() {
         ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         GlobalClockRule rule = mock(GlobalClockRule.class);
         when(rule.getConfiguration()).thenReturn(new 
GlobalClockRuleConfiguration("TSO", "local", false, PropertiesBuilder.build(new 
Property("key", "value"))));
-        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().findSingleRule(GlobalClockRule.class)).thenReturn(Optional.of(rule));
+        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(rule)));
         return result;
     }
-    
-    @Test
-    void assertGlobalClockRule() throws SQLException {
-        engine.executeQuery();
-        Collection<LocalDataQueryResultRow> actual = engine.getRows();
-        assertThat(actual.size(), is(1));
-        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
-        LocalDataQueryResultRow row = iterator.next();
-        assertThat(row.getCell(1), is("TSO"));
-        assertThat(row.getCell(2), is("local"));
-        assertThat(row.getCell(3), is("false"));
-        assertThat(row.getCell(4), is("{\"key\":\"value\"}"));
-    }
 }
diff --git 
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
 
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
index 7b6c97946e4..bdbb30bc041 100644
--- 
a/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
+++ 
b/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/update/AlterGlobalClockRuleExecutorTest.java
@@ -18,44 +18,49 @@
 package org.apache.shardingsphere.globalclock.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.globalclock.config.GlobalClockRuleConfiguration;
 import 
org.apache.shardingsphere.globalclock.distsql.statement.updatable.AlterGlobalClockRuleStatement;
 import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
-import 
org.apache.shardingsphere.globalclock.rule.builder.DefaultGlobalClockRuleConfigurationBuilder;
+import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData;
 import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.junit.jupiter.api.BeforeEach;
+import 
org.apache.shardingsphere.mode.persist.service.MetaDataManagerPersistService;
 import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentMatchers;
 
+import java.sql.SQLException;
+import java.util.Collections;
 import java.util.Properties;
 
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 
 class AlterGlobalClockRuleExecutorTest {
     
-    private DistSQLUpdateExecuteEngine engine;
+    @Test
+    void assertExecute() throws SQLException {
+        ContextManager contextManager = mockContextManager();
+        new DistSQLUpdateExecuteEngine(new 
AlterGlobalClockRuleStatement("TSO", "redis", true, new Properties()), null, 
contextManager).executeUpdate();
+        MetaDataManagerPersistService metaDataManagerPersistService = 
contextManager.getPersistServiceFacade().getMetaDataManagerPersistService();
+        
verify(metaDataManagerPersistService).alterGlobalRuleConfiguration(ArgumentMatchers.argThat(this::assertRuleConfiguration));
+    }
     
-    @BeforeEach
-    void setUp() {
-        AlterGlobalClockRuleStatement sqlStatement = new 
AlterGlobalClockRuleStatement("TSO", "redis", Boolean.TRUE, new Properties());
-        engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, 
mockContextManager());
+    private boolean assertRuleConfiguration(final GlobalClockRuleConfiguration 
actual) {
+        assertThat(actual.getType(), is("TSO"));
+        assertThat(actual.getProvider(), is("redis"));
+        assertTrue(actual.isEnabled());
+        return true;
     }
     
-    @SuppressWarnings({"rawtypes", "unchecked"})
     private ContextManager mockContextManager() {
         ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
         GlobalClockRule rule = mock(GlobalClockRule.class);
-        GlobalRuleDefinitionExecutor executor = 
mock(GlobalRuleDefinitionExecutor.class);
-        when(executor.getRuleClass()).thenReturn(GlobalClockRule.class);
-        when(rule.getConfiguration()).thenReturn(new 
DefaultGlobalClockRuleConfigurationBuilder().build());
-        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule);
+        when(rule.getConfiguration()).thenReturn(new 
GlobalClockRuleConfiguration("TSO", "local", false, new Properties()));
+        
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
 RuleMetaData(Collections.singleton(rule)));
         return result;
     }
-    
-    @Test
-    void assertExecute() {
-        assertDoesNotThrow(() -> engine.executeUpdate());
-    }
 }

Reply via email to