You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/05/11 15:13:02 UTC
(shardingsphere) branch master updated: Refactor AlterSQLTranslatorRuleExecutorTest Test Case (#31202)
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 ed211e7d43b Refactor AlterSQLTranslatorRuleExecutorTest Test Case (#31202)
ed211e7d43b is described below
commit ed211e7d43b36f6554348a2320abe895a8cd7502
Author: ilyas ahsan <me...@gmail.com>
AuthorDate: Sat May 11 22:12:56 2024 +0700
Refactor AlterSQLTranslatorRuleExecutorTest Test Case (#31202)
---
.../update/AlterSQLTranslatorRuleExecutorTest.java | 37 +++++++++++++++-------
1 file changed, 26 insertions(+), 11 deletions(-)
diff --git a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
index 3adef17ca7d..91a947cdc36 100644
--- a/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
+++ b/kernel/sql-translator/distsql/handler/src/test/java/org/apache/shardingsphere/sqltranslator/distsql/handler/update/AlterSQLTranslatorRuleExecutorTest.java
@@ -17,7 +17,10 @@
package org.apache.shardingsphere.sqltranslator.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.distsql.segment.AlgorithmSegment;
+import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.sqltranslator.api.config.SQLTranslatorRuleConfiguration;
import org.apache.shardingsphere.sqltranslator.distsql.statement.updateable.AlterSQLTranslatorRuleStatement;
import org.apache.shardingsphere.sqltranslator.rule.SQLTranslatorRule;
@@ -27,26 +30,38 @@ import org.junit.jupiter.api.Test;
import java.util.Properties;
-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 AlterSQLTranslatorRuleExecutorTest {
+ private DistSQLUpdateExecuteEngine engine;
+
@Test
void assertExecute() {
- AlterSQLTranslatorRuleExecutor executor = new AlterSQLTranslatorRuleExecutor();
+ AlterSQLTranslatorRuleStatement sqlStatement = new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), Boolean.TRUE);
+ engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager());
+ assertDoesNotThrow(() -> engine.executeUpdate());
+ }
+
+ @Test
+ void assertExecuteWithNullOriginalSQLWhenTranslatingFailed() {
+ AlterSQLTranslatorRuleStatement sqlStatement = new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), null);
+ engine = new DistSQLUpdateExecuteEngine(sqlStatement, null, mockContextManager());
+ assertDoesNotThrow(() -> engine.executeUpdate());
+ }
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ private ContextManager mockContextManager() {
+ ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
SQLTranslatorRule rule = mock(SQLTranslatorRule.class);
+ GlobalRuleDefinitionExecutor executor = mock(GlobalRuleDefinitionExecutor.class);
+ when(executor.getRuleClass()).thenReturn(SQLTranslatorRule.class);
when(rule.getConfiguration()).thenReturn(createSQLTranslatorRuleConfiguration());
- executor.setRule(rule);
- SQLTranslatorRuleConfiguration actual = executor.buildToBeAlteredRuleConfiguration(
- new AlterSQLTranslatorRuleStatement(new AlgorithmSegment("Native", PropertiesBuilder.build(new Property("foo", "bar"))), null));
- assertThat(actual.getType(), is("Native"));
- assertThat(actual.getProps().size(), is(1));
- assertThat(actual.getProps().getProperty("foo"), is("bar"));
- assertTrue(actual.isUseOriginalSQLWhenTranslatingFailed());
+ when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule);
+ return result;
}
private SQLTranslatorRuleConfiguration createSQLTranslatorRuleConfiguration() {