You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/15 08:20:34 UTC

[shardingsphere] branch master updated: Improve MigrationJobAPIImplTest (#21582)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 59de429287c Improve MigrationJobAPIImplTest (#21582)
59de429287c is described below

commit 59de429287c2e5e7d39070dae7ebfac12faf50fb
Author: Hongsheng Zhong <zh...@apache.org>
AuthorDate: Sat Oct 15 16:20:23 2022 +0800

    Improve MigrationJobAPIImplTest (#21582)
    
    * Remove Experimental in migration doc (#21560)
    
    * Remove not needed filter in DataSourcePreparer
    
    * Remove unnecessary interface implements
    
    * Improve MigrationJobAPIImplTest to avoid possible failure
    
    * Revert "Remove not needed filter in DataSourcePreparer"
    
    This reverts commit 1ed04da5065405134d95444ceb0b4fa85b34278a.
---
 .../shardingsphere-proxy/migration/_index.cn.md    |  2 +-
 .../shardingsphere-proxy/migration/_index.en.md    |  2 +-
 .../pipeline/scenario/migration/MigrationJob.java  |  3 +-
 .../core/api/impl/MigrationJobAPIImplTest.java     | 33 +++++++++-------------
 4 files changed, 16 insertions(+), 24 deletions(-)

diff --git a/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.cn.md b/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.cn.md
index e6d59dca468..4bd443d6c5a 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.cn.md
@@ -7,4 +7,4 @@ weight = 4
 
 ShardingSphere 可以提供给用户通用的数据迁移解决方案。
 
-于 **4.1.0** 开始向用户提供,目前仍处于 **实验室** 版本。
+于 **4.1.0** 开始向用户提供。
diff --git a/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.en.md b/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.en.md
index 24ea0d3825f..973ff404c1d 100644
--- a/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.en.md
+++ b/docs/document/content/user-manual/shardingsphere-proxy/migration/_index.en.md
@@ -5,4 +5,4 @@ weight = 4
 
 ## Introduction
 
-ShardingSphere provides solution of migrating data since **4.1.0**, current state is **Experimental** version.
+ShardingSphere provides solution of migrating data since **4.1.0**.
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJob.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJob.java
index 365a5b28fe6..0792434e09f 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJob.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJob.java
@@ -22,7 +22,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.shardingsphere.data.pipeline.api.config.job.MigrationJobConfiguration;
 import org.apache.shardingsphere.data.pipeline.api.datasource.PipelineDataSourceManager;
 import org.apache.shardingsphere.data.pipeline.api.job.JobStatus;
-import org.apache.shardingsphere.data.pipeline.api.job.PipelineJob;
 import org.apache.shardingsphere.data.pipeline.api.job.progress.InventoryIncrementalJobItemProgress;
 import org.apache.shardingsphere.data.pipeline.api.task.PipelineTasksRunner;
 import org.apache.shardingsphere.data.pipeline.core.datasource.DefaultPipelineDataSourceManager;
@@ -43,7 +42,7 @@ import java.sql.SQLException;
  */
 @RequiredArgsConstructor
 @Slf4j
-public final class MigrationJob extends AbstractPipelineJob implements SimpleJob, PipelineJob {
+public final class MigrationJob extends AbstractPipelineJob implements SimpleJob {
     
     private final MigrationJobAPI jobAPI = MigrationJobAPIFactory.getInstance();
     
diff --git a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/api/impl/MigrationJobAPIImplTest.java b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/api/impl/MigrationJobAPIImplTest.java
index 452001a8b4a..2e60df2aa7d 100644
--- a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/api/impl/MigrationJobAPIImplTest.java
+++ b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/core/api/impl/MigrationJobAPIImplTest.java
@@ -28,8 +28,7 @@ import org.apache.shardingsphere.data.pipeline.api.job.JobStatus;
 import org.apache.shardingsphere.data.pipeline.api.job.JobType;
 import org.apache.shardingsphere.data.pipeline.api.job.progress.InventoryIncrementalJobItemProgress;
 import org.apache.shardingsphere.data.pipeline.api.pojo.CreateMigrationJobParameter;
-import org.apache.shardingsphere.data.pipeline.api.pojo.PipelineJobInfo;
-import org.apache.shardingsphere.data.pipeline.api.pojo.TableBasedPipelineJobInfo;
+import org.apache.shardingsphere.data.pipeline.core.api.PipelineAPIFactory;
 import org.apache.shardingsphere.data.pipeline.core.datasource.creator.PipelineDataSourceCreatorFactory;
 import org.apache.shardingsphere.data.pipeline.core.util.JobConfigurationBuilder;
 import org.apache.shardingsphere.data.pipeline.core.util.PipelineContextUtil;
@@ -37,6 +36,7 @@ import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobAP
 import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobAPIFactory;
 import org.apache.shardingsphere.data.pipeline.scenario.migration.MigrationJobItemContext;
 import org.apache.shardingsphere.data.pipeline.spi.check.consistency.DataConsistencyCalculateAlgorithm;
+import org.apache.shardingsphere.elasticjob.infra.pojo.JobConfigurationPOJO;
 import org.apache.shardingsphere.infra.datasource.pool.creator.DataSourcePoolCreator;
 import org.apache.shardingsphere.infra.datasource.props.DataSourceProperties;
 import org.junit.AfterClass;
@@ -55,13 +55,13 @@ import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Map.Entry;
-import java.util.Objects;
 import java.util.Optional;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -92,31 +92,24 @@ public final class MigrationJobAPIImplTest {
     public void assertStartAndList() {
         Optional<String> jobId = jobAPI.start(JobConfigurationBuilder.createJobConfiguration());
         assertTrue(jobId.isPresent());
-        PipelineJobInfo jobInfo = getNonNullJobInfo(jobId.get());
-        assertTrue(jobInfo.getJobMetaData().isActive());
-        assertThat(((TableBasedPipelineJobInfo) jobInfo).getTable(), is("t_order"));
-        assertThat(jobInfo.getJobMetaData().getShardingTotalCount(), is(1));
+        JobConfigurationPOJO jobConfigPOJO = getJobConfigurationPOJO(jobId.get());
+        assertFalse(jobConfigPOJO.isDisabled());
+        assertThat(jobConfigPOJO.getShardingTotalCount(), is(1));
     }
     
-    private Optional<? extends PipelineJobInfo> getJobInfo(final String jobId) {
-        return jobAPI.list().stream().filter(each -> Objects.equals(each.getJobMetaData().getJobId(), jobId)).reduce((a, b) -> a);
-    }
-    
-    private PipelineJobInfo getNonNullJobInfo(final String jobId) {
-        Optional<? extends PipelineJobInfo> result = getJobInfo(jobId);
-        assertTrue(result.isPresent());
-        return result.get();
+    private JobConfigurationPOJO getJobConfigurationPOJO(final String jobId) {
+        return PipelineAPIFactory.getJobConfigurationAPI().getJobConfiguration(jobId);
     }
     
     @Test
     public void assertStartOrStopById() {
         Optional<String> jobId = jobAPI.start(JobConfigurationBuilder.createJobConfiguration());
         assertTrue(jobId.isPresent());
-        assertTrue(getNonNullJobInfo(jobId.get()).getJobMetaData().isActive());
+        assertFalse(getJobConfigurationPOJO(jobId.get()).isDisabled());
         jobAPI.stop(jobId.get());
-        assertFalse(getNonNullJobInfo(jobId.get()).getJobMetaData().isActive());
+        assertTrue(getJobConfigurationPOJO(jobId.get()).isDisabled());
         jobAPI.startDisabledJob(jobId.get());
-        assertTrue(getNonNullJobInfo(jobId.get()).getJobMetaData().isActive());
+        assertFalse(getJobConfigurationPOJO(jobId.get()).isDisabled());
     }
     
     @Test
@@ -126,7 +119,7 @@ public final class MigrationJobAPIImplTest {
         MigrationJobConfiguration jobConfig = jobAPI.getJobConfiguration(jobId.get());
         initTableData(jobConfig);
         jobAPI.rollback(jobId.get());
-        assertFalse(getJobInfo(jobId.get()).isPresent());
+        assertNull(getJobConfigurationPOJO(jobId.get()));
     }
     
     @Test
@@ -136,7 +129,7 @@ public final class MigrationJobAPIImplTest {
         MigrationJobConfiguration jobConfig = jobAPI.getJobConfiguration(jobId.get());
         initTableData(jobConfig);
         jobAPI.commit(jobId.get());
-        assertFalse(getJobInfo(jobId.get()).isPresent());
+        assertNull(getJobConfigurationPOJO(jobId.get()));
     }
     
     @Test