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 121f1c0e2eb Complete test cases for ScalingRegistrySubscriber (#19338)
121f1c0e2eb is described below

commit 121f1c0e2eb2610f396a3058809d5edc332a9ad7
Author: skai <[email protected]>
AuthorDate: Tue Jul 19 16:27:10 2022 +0800

    Complete test cases for ScalingRegistrySubscriber (#19338)
---
 .../subscriber/ScalingRegistrySubscriberTest.java  | 35 +++++++++++++++++++---
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/cache/subscriber/ScalingRegistrySubscriberTest.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/cache/subscriber/ScalingRegistrySubscriberTest.java
index 61302352360..fd679fbb8ec 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/cache/subscriber/ScalingRegistrySubscriberTest.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/test/java/org/apache/shardingsphere/mode/manager/cluster/coordinator/registry/cache/subscriber/ScalingRegistrySubscriberTest.java
@@ -18,15 +18,24 @@
 package 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.cache.subscriber;
 
 import org.apache.shardingsphere.infra.eventbus.EventBusContext;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.cache.event.StartScalingEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.ScalingTaskFinishedEvent;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.version.MetadataVersionPreparedEvent;
 import 
org.apache.shardingsphere.mode.metadata.persist.service.MetaDataVersionPersistService;
 import 
org.apache.shardingsphere.mode.repository.cluster.ClusterPersistRepository;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.ArgumentMatchers;
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
 import java.lang.reflect.Field;
+import java.util.Optional;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.verify;
 
 @RunWith(MockitoJUnitRunner.class)
 public final class ScalingRegistrySubscriberTest {
@@ -36,17 +45,35 @@ public final class ScalingRegistrySubscriberTest {
     
     @Mock
     private MetaDataVersionPersistService metaDataVersionPersistService;
+
+    @Mock
+    private EventBusContext eventBusContext;
+
+    private ScalingRegistrySubscriber scalingRegistrySubscriber;
     
     @Before
     public void setUp() throws ReflectiveOperationException {
-        ScalingRegistrySubscriber scalingRegistrySubscriber = new 
ScalingRegistrySubscriber(repository, new EventBusContext());
+        scalingRegistrySubscriber = new ScalingRegistrySubscriber(repository, 
eventBusContext);
         Field persistServiceField = 
ScalingRegistrySubscriber.class.getDeclaredField("metaDataVersionPersistService");
         persistServiceField.setAccessible(true);
         persistServiceField.set(scalingRegistrySubscriber, 
metaDataVersionPersistService);
     }
-    
+
+    @Test
+    public void assertStartScaling() {
+        verify(eventBusContext).register(scalingRegistrySubscriber);
+        
when(metaDataVersionPersistService.getActiveVersion("ds_0")).thenReturn(Optional.of("1"));
+        when(repository.get(any())).thenReturn("");
+        scalingRegistrySubscriber.startScaling(new 
MetadataVersionPreparedEvent("2", "ds_0"));
+        StartScalingEvent startScalingEvent = new StartScalingEvent("ds_0", 
"", "", "", "", 1, 2);
+        
verify(eventBusContext).post(ArgumentMatchers.refEq(startScalingEvent));
+    }
+
     @Test
-    public void assertCacheRuleConfiguration() {
-        // TODO finish test case
+    public void assertScalingTaskFinished() {
+        
when(metaDataVersionPersistService.getActiveVersion("ds_0")).thenReturn(Optional.of("1"));
+        scalingRegistrySubscriber.scalingTaskFinished(new 
ScalingTaskFinishedEvent("ds_0", 1, 2));
+        verify(metaDataVersionPersistService).persistActiveVersion("ds_0", 
"2");
+        verify(metaDataVersionPersistService).deleteVersion("ds_0", "1");
     }
 }

Reply via email to