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 2826262c2da Fix pipeline unit test (#20308)
2826262c2da is described below

commit 2826262c2da0c0b143ead4302aee2856b84c1891
Author: Hongsheng Zhong <[email protected]>
AuthorDate: Fri Aug 19 21:33:38 2022 +0800

    Fix pipeline unit test (#20308)
---
 .../data/pipeline/scenario/migration/MigrationJobAPIImpl.java |  9 ++++++++-
 .../pipeline/scenario/migration/MigrationJobItemContext.java  |  1 +
 .../pipeline/scenario/migration/MigrationProcessContext.java  |  2 +-
 .../data/pipeline/core/job/FinishedCheckJobTest.java          |  6 ++++++
 .../pipeline/core/util/PipelineDistributedBarrierTest.java    | 11 +++++------
 5 files changed, 21 insertions(+), 8 deletions(-)

diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
index cce56aa9a0a..0508bcf0d17 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
@@ -58,9 +58,12 @@ import 
org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import org.apache.shardingsphere.elasticjob.lite.lifecycle.domain.JobBriefInfo;
 import org.apache.shardingsphere.infra.config.mode.ModeConfiguration;
 import 
org.apache.shardingsphere.infra.config.rule.data.pipeline.PipelineProcessConfiguration;
+import 
org.apache.shardingsphere.infra.config.rule.data.pipeline.PipelineReadConfiguration;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
 import org.apache.shardingsphere.infra.lock.LockContext;
 import org.apache.shardingsphere.infra.lock.LockDefinition;
+import 
org.apache.shardingsphere.infra.yaml.config.pojo.data.pipeline.YamlPipelineReadConfiguration;
+import 
org.apache.shardingsphere.infra.yaml.config.swapper.rule.data.pipeline.YamlPipelineReadConfigurationSwapper;
 import org.apache.shardingsphere.mode.lock.ExclusiveLockDefinition;
 import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.config.event.rule.ScalingTaskFinishedEvent;
 
@@ -147,7 +150,11 @@ public final class MigrationJobAPIImpl extends 
AbstractPipelineJobAPIImpl implem
     public MigrationProcessContext buildPipelineProcessContext(final 
PipelineJobConfiguration pipelineJobConfig) {
         // TODO add jobType
         // TODO read process config from registry center
-        PipelineProcessConfiguration processConfig = new 
PipelineProcessConfiguration(null, null, null);
+        YamlPipelineReadConfiguration yamlReadConfig = 
YamlPipelineReadConfiguration.buildWithDefaultValue();
+        yamlReadConfig.fillInNullFieldsWithDefaultValue();
+        yamlReadConfig.setShardingSize(10);
+        PipelineReadConfiguration readConfig = new 
YamlPipelineReadConfigurationSwapper().swapToObject(yamlReadConfig);
+        PipelineProcessConfiguration processConfig = new 
PipelineProcessConfiguration(readConfig, null, null);
         return new MigrationProcessContext(pipelineJobConfig.getJobId(), 
processConfig);
     }
     
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobItemContext.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobItemContext.java
index f559d4e8feb..2f954f91f04 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobItemContext.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobItemContext.java
@@ -85,6 +85,7 @@ public final class MigrationJobItemContext implements 
InventoryIncrementalJobIte
     
     public MigrationJobItemContext(final MigrationJobConfiguration jobConfig, 
final int jobShardingItem, final InventoryIncrementalJobItemProgress 
initProgress,
                                    final PipelineDataSourceManager 
dataSourceManager) {
+        // TODO refactor, transfer in parameter
         MigrationJobAPI jobAPI = MigrationJobAPIFactory.getInstance();
         jobProcessContext = jobAPI.buildPipelineProcessContext(jobConfig);
         this.jobConfig = jobConfig;
diff --git 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationProcessContext.java
 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationProcessContext.java
index b3c430629e1..70936c0fc4b 100644
--- 
a/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationProcessContext.java
+++ 
b/shardingsphere-kernel/shardingsphere-data-pipeline/shardingsphere-data-pipeline-core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationProcessContext.java
@@ -46,7 +46,7 @@ public final class MigrationProcessContext extends 
AbstractPipelineProcessContex
     public MigrationProcessContext(final String jobId, final 
PipelineProcessConfiguration originalProcessConfig) {
         super(jobId, originalProcessConfig);
         completionDetectAlgorithm = null;
-        dataConsistencyCalculateAlgorithm = null;
+        dataConsistencyCalculateAlgorithm = 
DataConsistencyCalculateAlgorithmFactory.newInstance("DATA_MATCH", null);
     }
     
     @SuppressWarnings("unchecked")
diff --git 
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/FinishedCheckJobTest.java
 
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/FinishedCheckJobTest.java
index 93c2b8262fa..913ff7f65d7 100644
--- 
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/FinishedCheckJobTest.java
+++ 
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/FinishedCheckJobTest.java
@@ -24,6 +24,7 @@ import 
org.apache.shardingsphere.data.pipeline.core.util.PipelineContextUtil;
 import org.apache.shardingsphere.data.pipeline.core.util.ReflectionUtil;
 import 
org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobAPI;
 import 
org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobAPIFactory;
+import 
org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationProcessContext;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -35,6 +36,7 @@ import java.util.List;
 import java.util.Optional;
 
 import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.when;
 
 @RunWith(MockitoJUnitRunner.class)
@@ -45,6 +47,9 @@ public final class FinishedCheckJobTest {
     @Mock
     private MigrationJobAPI jobAPI;
     
+    @Mock
+    private MigrationProcessContext processContext;
+    
     @BeforeClass
     public static void beforeClass() {
         PipelineContextUtil.mockModeConfigAndContextManager();
@@ -54,6 +59,7 @@ public final class FinishedCheckJobTest {
     @Before
     @SneakyThrows(ReflectiveOperationException.class)
     public void setUp() {
+        
when(jobAPI.buildPipelineProcessContext(any())).thenReturn(processContext);
         ReflectionUtil.setFieldValue(finishedCheckJob, "jobAPI", jobAPI);
     }
     
diff --git 
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrierTest.java
 
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrierTest.java
index 94641521d09..61f199207ea 100644
--- 
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrierTest.java
+++ 
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/util/PipelineDistributedBarrierTest.java
@@ -25,10 +25,8 @@ import org.junit.Test;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
-import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 @SuppressWarnings("rawtypes")
@@ -42,12 +40,13 @@ public final class PipelineDistributedBarrierTest {
     @Test
     public void assertRegisterAndRemove() throws NoSuchFieldException, 
IllegalAccessException {
         PipelineDistributedBarrier instance = 
PipelineDistributedBarrier.getInstance();
-        instance.register("/test", 1);
+        String parentPath = "/test";
+        instance.register(parentPath, 1);
         Map countDownLatchMap = ReflectionUtil.getFieldValue(instance, 
"countDownLatchMap", Map.class);
         assertNotNull(countDownLatchMap);
-        assertThat(countDownLatchMap.size(), is(1));
-        instance.removeParentNode("/test");
-        assertThat(countDownLatchMap.size(), is(0));
+        assertTrue(countDownLatchMap.containsKey(parentPath));
+        instance.removeParentNode(parentPath);
+        assertFalse(countDownLatchMap.containsKey(parentPath));
     }
     
     @Test

Reply via email to