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 f3229c0d370 Refactor AlterGlobalClockRuleExecutorTest Test Case
(#31109)
f3229c0d370 is described below
commit f3229c0d370627d2c9c7d83c4aed1a7ca5b21e49
Author: ilyas ahsan <[email protected]>
AuthorDate: Sun May 5 21:08:01 2024 +0700
Refactor AlterGlobalClockRuleExecutorTest Test Case (#31109)
* Refactor AlterGlobalClockRuleExecutorTest Test Case
* Fix Check Style issue
---
.../update/AlterGlobalClockRuleExecutorTest.java | 50 ++++++++++++----------
1 file changed, 28 insertions(+), 22 deletions(-)
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 e896acf6e5d..7b6c97946e4 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
@@ -17,39 +17,45 @@
package org.apache.shardingsphere.globalclock.distsql.handler.update;
-import
org.apache.shardingsphere.globalclock.api.config.GlobalClockRuleConfiguration;
+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.distsql.statement.updatable.AlterGlobalClockRuleStatement;
import org.apache.shardingsphere.globalclock.rule.GlobalClockRule;
import
org.apache.shardingsphere.globalclock.rule.builder.DefaultGlobalClockRuleConfigurationBuilder;
-import
org.apache.shardingsphere.globalclock.distsql.statement.updatable.AlterGlobalClockRuleStatement;
-import org.apache.shardingsphere.test.util.PropertiesBuilder;
-import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.junit.jupiter.api.BeforeEach;
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 java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
class AlterGlobalClockRuleExecutorTest {
- @Test
- void assertExecute() {
- AlterGlobalClockRuleExecutor executor = new
AlterGlobalClockRuleExecutor();
- AlterGlobalClockRuleStatement sqlStatement = new
AlterGlobalClockRuleStatement("TSO", "redis", Boolean.TRUE,
PropertiesBuilder.build(new Property("host", "127.0.0.1")));
+ private DistSQLUpdateExecuteEngine engine;
+
+ @BeforeEach
+ void setUp() {
+ AlterGlobalClockRuleStatement sqlStatement = new
AlterGlobalClockRuleStatement("TSO", "redis", Boolean.TRUE, new Properties());
+ engine = new DistSQLUpdateExecuteEngine(sqlStatement, null,
mockContextManager());
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private ContextManager mockContextManager() {
+ ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
GlobalClockRule rule = mock(GlobalClockRule.class);
-
when(rule.getConfiguration()).thenReturn(getSQLParserRuleConfiguration());
- executor.setRule(rule);
- GlobalClockRuleConfiguration actual =
executor.buildToBeAlteredRuleConfiguration(sqlStatement);
- assertThat(actual.getType(), is("TSO"));
- assertThat(actual.getProvider(), is("redis"));
- assertTrue(actual.isEnabled());
- assertThat(actual.getProps().size(), is(1));
- assertThat(executor.getRuleClass(), is(GlobalClockRule.class));
- assertThat(executor.getType(),
is(AlterGlobalClockRuleStatement.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);
+ return result;
}
- private GlobalClockRuleConfiguration getSQLParserRuleConfiguration() {
- return new DefaultGlobalClockRuleConfigurationBuilder().build();
+ @Test
+ void assertExecute() {
+ assertDoesNotThrow(() -> engine.executeUpdate());
}
}