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 2021/02/07 04:31:43 UTC

[shardingsphere] branch master updated: Optimize ScalingAPIImplTest (#9362)

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 3e97cb7  Optimize ScalingAPIImplTest (#9362)
3e97cb7 is described below

commit 3e97cb7a73c526b596417ce0d1e08331fba95f01
Author: 邱鹿 Lucas <lu...@163.com>
AuthorDate: Sun Feb 7 12:31:18 2021 +0800

    Optimize ScalingAPIImplTest (#9362)
    
    * Optimize ScalingAPIImplTest
    
    Co-authored-by: qiulu3 <Lucas209910>
---
 .../scaling/core/api/impl/ScalingAPIImplTest.java  | 27 +++++++++++++++-------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
index a9b49d0..5cc1e7b 100644
--- a/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
+++ b/shardingsphere-scaling/shardingsphere-scaling-core/src/test/java/org/apache/shardingsphere/scaling/core/api/impl/ScalingAPIImplTest.java
@@ -17,6 +17,7 @@
 
 package org.apache.shardingsphere.scaling.core.api.impl;
 
+import lombok.SneakyThrows;
 import org.apache.shardingsphere.governance.repository.api.config.GovernanceCenterConfiguration;
 import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
 import org.apache.shardingsphere.scaling.core.api.JobInfo;
@@ -28,6 +29,8 @@ import org.apache.shardingsphere.scaling.core.fixture.EmbedTestingServer;
 import org.apache.shardingsphere.scaling.core.job.JobStatus;
 import org.apache.shardingsphere.scaling.core.job.progress.JobProgress;
 import org.apache.shardingsphere.scaling.core.util.JobConfigurationUtil;
+import org.apache.shardingsphere.scaling.core.util.ReflectionUtil;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -42,18 +45,14 @@ import static org.junit.Assert.assertTrue;
 
 public final class ScalingAPIImplTest {
     
-    private final ScalingAPI scalingAPI = ScalingAPIFactory.getScalingAPI();
+    private static ScalingAPI scalingAPI;
     
     @BeforeClass
+    @SneakyThrows(ReflectiveOperationException.class)
     public static void init() {
         EmbedTestingServer.start();
-        ScalingContext.getInstance().init(mockServerConfig());
-    }
-    
-    private static ServerConfiguration mockServerConfig() {
-        ServerConfiguration result = new ServerConfiguration();
-        result.setGovernanceConfig(new GovernanceConfiguration("test", new GovernanceCenterConfiguration("Zookeeper", EmbedTestingServer.getConnectionString(), new Properties()), true));
-        return result;
+        ReflectionUtil.setFieldValue(ScalingContext.getInstance(), "serverConfig", mockServerConfig());
+        scalingAPI = ScalingAPIFactory.getScalingAPI();
     }
     
     @Test
@@ -106,4 +105,16 @@ public final class ScalingAPIImplTest {
         Map<Integer, JobProgress> jobProgressMap = scalingAPI.getProgress(jobId.get());
         assertThat(jobProgressMap.size(), is(2));
     }
+    
+    @AfterClass
+    @SneakyThrows(ReflectiveOperationException.class)
+    public static void afterClass() {
+        ReflectionUtil.setFieldValue(ScalingContext.getInstance(), "serverConfig", null);
+    }
+    
+    private static ServerConfiguration mockServerConfig() {
+        ServerConfiguration result = new ServerConfiguration();
+        result.setGovernanceConfig(new GovernanceConfiguration("test", new GovernanceCenterConfiguration("Zookeeper", EmbedTestingServer.getConnectionString(), new Properties()), true));
+        return result;
+    }
 }