You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "ilyasahsan123 (via GitHub)" <gi...@apache.org> on 2024/05/01 04:20:22 UTC

[PR] Enhance AlterGlobalClockRuleExecutorTest test case [shardingsphere]

ilyasahsan123 opened a new pull request, #31087:
URL: https://github.com/apache/shardingsphere/pull/31087

   Ref #30083.
   
   Changes proposed in this pull request:
     - Enhance AlterGlobalClockRuleExecutorTest test case
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enhance AlterGlobalClockRuleExecutorTest test case [shardingsphere]

Posted by "terrymanu (via GitHub)" <gi...@apache.org>.
terrymanu merged PR #31087:
URL: https://github.com/apache/shardingsphere/pull/31087


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enhance AlterGlobalClockRuleExecutorTest test case [shardingsphere]

Posted by "ilyasahsan123 (via GitHub)" <gi...@apache.org>.
ilyasahsan123 commented on PR #31087:
URL: https://github.com/apache/shardingsphere/pull/31087#issuecomment-2088028383

   Are these changes correct, @terrymanu? Also, do we need to create an engine similar to the one shown in this example: https://github.com/apache/shardingsphere/blob/master/kernel/global-clock/distsql/handler/src/test/java/org/apache/shardingsphere/globalclock/distsql/handler/query/ShowGlobalClockRuleExecutorTest.java#L62


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Enhance AlterGlobalClockRuleExecutorTest test case [shardingsphere]

Posted by "ilyasahsan123 (via GitHub)" <gi...@apache.org>.
ilyasahsan123 commented on PR #31087:
URL: https://github.com/apache/shardingsphere/pull/31087#issuecomment-2093997454

   hi @terrymanu @strongduanmu,
   
   I realize these changes are **incorrect** because they implement a simple assertion. After taking a closer look, it turns out that we need to implement `DistSQLUpdateExecuteEngine` to cover all lines. I've tried to implement it, but I still don't know how to proceed. Below is the code snippet that still produces the error "can't convert class from `GlobalClockRule` to `ShardingSphereRule`." Could you please give me a clue on how to fix it? Thanks.
   
   
   ```java
   package org.apache.shardingsphere.globalclock.distsql.handler.update;
   
   import org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine;
   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.rule.ShardingSphereRule;
   import org.apache.shardingsphere.mode.manager.ContextManager;
   import org.apache.shardingsphere.test.util.PropertiesBuilder;
   import org.junit.jupiter.api.BeforeEach;
   import org.junit.jupiter.api.Test;
   
   import java.sql.SQLException;
   
   import static org.mockito.Mockito.mock;
   import static org.mockito.Mockito.when;
   import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
   
   class AlterGlobalClockRuleExecutorTest {
       
       public DistSQLUpdateExecuteEngine engine;
       
       @BeforeEach
       void setUp() {
           AlterGlobalClockRuleStatement sqlStatement = new AlterGlobalClockRuleStatement("TSO", "redis", Boolean.TRUE, PropertiesBuilder.build(new PropertiesBuilder.Property("host", "127.0.0.1")));
           engine = new DistSQLUpdateExecuteEngine(sqlStatement, "foo_db", mockContextManager());
       }
       
       private ContextManager mockContextManager() {
           ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
           GlobalClockRule rule = mock(GlobalClockRule.class);
           when(rule.getConfiguration()).thenReturn(new DefaultGlobalClockRuleConfigurationBuilder().build());
           when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(ShardingSphereRule.class)).thenReturn(rule);
           return result;
       }
       
       @Test
       void assertExecute() throws SQLException {
           engine.executeUpdate();
       }
   }
   ```  
   
   **Stacktrace**
   ```
   java.lang.ClassCastException: class org.apache.shardingsphere.infra.rule.ShardingSphereRule$MockitoMock$zajmxfuL cannot be cast to class org.apache.shardingsphere.globalclock.rule.GlobalClockRule (org.apache.shardingsphere.infra.rule.ShardingSphereRule$MockitoMock$zajmxfuL and org.apache.shardingsphere.globalclock.rule.GlobalClockRule are in unnamed module of loader 'app')
   
   	at org.apache.shardingsphere.globalclock.distsql.handler.update.AlterGlobalClockRuleExecutor.setRule(AlterGlobalClockRuleExecutor.java:28)
   	at org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.engine.global.GlobalRuleDefinitionExecuteEngine.executeUpdate(GlobalRuleDefinitionExecuteEngine.java:48)
   	at org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine.executeRuleDefinitionUpdate(DistSQLUpdateExecuteEngine.java:76)
   	at org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine.executeUpdate(DistSQLUpdateExecuteEngine.java:62)
   	at org.apache.shardingsphere.globalclock.distsql.handler.update.AlterGlobalClockRuleExecutorTest.assertExecute(AlterGlobalClockRuleExecutorTest.java:56)
   	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org