This is an automated email from the ASF dual-hosted git repository.
totalo 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 a77f294 Added unit tests for JobProgressYamlSwapper (#16107)
a77f294 is described below
commit a77f2946accf44f1a80bee13e660ad1245a7371c
Author: BashCache <[email protected]>
AuthorDate: Wed Mar 16 07:21:24 2022 +0530
Added unit tests for JobProgressYamlSwapper (#16107)
* Added unit tests for RecordUtil
* Made changes according to review
* Added changes according to review
* Changes as per review
* Removed * in imports
* Included space between English and Chinese words
* Included space between English and Chinese words
* Added test cases for JobProgreeYamlSwapper
* Added test cases for JobProgreeYamlSwapper
* Added test cases for JobProgreeYamlSwapper
* Removed blank space
---
.../progress/yaml/JobProgressYamlSwapperTest.java | 69 ++++++++++++++++++++++
.../test/resources/job-progress-no-inventory.yaml | 31 ++++++++++
2 files changed, 100 insertions(+)
diff --git
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/JobProgressYamlSwapperTest.java
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/JobProgressYamlSwapperTest.java
new file mode 100644
index 0000000..2119668
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/java/org/apache/shardingsphere/data/pipeline/core/job/progress/yaml/JobProgressYamlSwapperTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.data.pipeline.core.job.progress.yaml;
+
+import org.apache.shardingsphere.data.pipeline.api.job.progress.JobProgress;
+import org.apache.shardingsphere.data.pipeline.core.util.ConfigurationFileUtil;
+import org.apache.shardingsphere.infra.yaml.engine.YamlEngine;
+
+import org.junit.Test;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+
+public final class JobProgressYamlSwapperTest {
+
+ private static final JobProgressYamlSwapper JOB_PROGRESS_YAML_SWAPPER =
new JobProgressYamlSwapper();
+
+ private JobProgress getJobProgress(final String data) {
+ return
JOB_PROGRESS_YAML_SWAPPER.swapToObject(YamlEngine.unmarshal(data,
YamlJobProgress.class));
+ }
+
+ @Test
+ public void assertFullSwapToYaml() {
+ JobProgress jobProgress =
getJobProgress(ConfigurationFileUtil.readFile("job-progress.yaml"));
+ YamlJobProgress actual =
JOB_PROGRESS_YAML_SWAPPER.swapToYaml(jobProgress);
+ assertThat(actual.getStatus(), is("RUNNING"));
+ assertThat(actual.getSourceDatabaseType(), is("H2"));
+ assertThat(actual.getInventory().getFinished().length, is(2));
+ assertArrayEquals(actual.getInventory().getFinished(), new
String[]{"ds0.t_2", "ds0.t_1"});
+ assertThat(actual.getInventory().getUnfinished().size(), is(2));
+ assertThat(actual.getInventory().getUnfinished().get("ds1.t_2"),
is("1,2"));
+ assertThat(actual.getInventory().getUnfinished().get("ds1.t_1"),
is(""));
+ assertThat(actual.getIncremental().size(), is(1));
+ assertTrue(actual.getIncremental().containsKey("ds0"));
+ assertNull(actual.getIncremental().get("position"));
+ }
+
+ @Test
+ public void assertNullIncremental() {
+ JobProgress jobProgress =
getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-finished.yaml"));
+ YamlJobProgress actual =
JOB_PROGRESS_YAML_SWAPPER.swapToYaml(jobProgress);
+ assertTrue(actual.getIncremental().isEmpty());
+ }
+
+ @Test
+ public void assertNullInventory() {
+ JobProgress jobProgress =
getJobProgress(ConfigurationFileUtil.readFile("job-progress-no-inventory.yaml"));
+ YamlJobProgress actual =
JOB_PROGRESS_YAML_SWAPPER.swapToYaml(jobProgress);
+ assertThat(actual.getInventory().getFinished().length, is(0));
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-pipeline-test/src/test/resources/job-progress-no-inventory.yaml
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/resources/job-progress-no-inventory.yaml
new file mode 100644
index 0000000..c055b80
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-pipeline-test/src/test/resources/job-progress-no-inventory.yaml
@@ -0,0 +1,31 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+#
+ incremental:
+ ds0:
+ delay:
+ lastEventTimestamps: 0
+ latestActiveTimeMillis: 0
+ position: ''
+#inventory:
+# unfinished:
+# ds0.t_1: 1,2
+# ds0.t_2: ''
+# ds1.t_2: 1,2
+# ds1.t_1: ''
+ sourceDatabaseType: H2
+ status: RUNNING