You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2023/04/24 09:14:07 UTC
[shardingsphere] branch master updated: Improve properties check of DataMatchDataConsistencyCalculateAlgorithm (#25300)
This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 e1202908f59 Improve properties check of DataMatchDataConsistencyCalculateAlgorithm (#25300)
e1202908f59 is described below
commit e1202908f597f479f620a51435444f983169a1f6
Author: ChenJiaHao <Pa...@163.com>
AuthorDate: Mon Apr 24 17:13:56 2023 +0800
Improve properties check of DataMatchDataConsistencyCalculateAlgorithm (#25300)
* Enhance init check for DataMatchDataConsistencyCalculateAlgorithm
* Fix code style, add warn log
* Modify log content
---
.../DataMatchDataConsistencyCalculateAlgorithm.java | 10 ++++++++--
...ataMatchDataConsistencyCalculateAlgorithmTest.java | 19 +++++++++++++++++++
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
index 94222b1de1c..a844eb5d0b7 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java
@@ -78,9 +78,15 @@ public final class DataMatchDataConsistencyCalculateAlgorithm extends AbstractSt
}
private int getChunkSize(final Properties props) {
- int result = Integer.parseInt(props.getProperty(CHUNK_SIZE_KEY, DEFAULT_CHUNK_SIZE + ""));
+ int result;
+ try {
+ result = Integer.parseInt(props.getProperty(CHUNK_SIZE_KEY, DEFAULT_CHUNK_SIZE + ""));
+ } catch (final NumberFormatException ignore) {
+ log.warn("'chunk-size' is not a valid number, use default value {}", DEFAULT_CHUNK_SIZE);
+ return DEFAULT_CHUNK_SIZE;
+ }
if (result <= 0) {
- log.warn("Invalid result={}, use default value", result);
+ log.warn("Invalid 'chunk-size': {}, use default value {}", result, DEFAULT_CHUNK_SIZE);
return DEFAULT_CHUNK_SIZE;
}
return result;
diff --git a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithmTest.java b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithmTest.java
index b0491d003da..ebb3f40e8ca 100644
--- a/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithmTest.java
+++ b/test/it/pipeline/src/test/java/org/apache/shardingsphere/test/it/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithmTest.java
@@ -24,6 +24,8 @@ import org.apache.shardingsphere.data.pipeline.api.datasource.PipelineDataSource
import org.apache.shardingsphere.data.pipeline.api.metadata.model.PipelineColumnMetaData;
import org.apache.shardingsphere.data.pipeline.core.check.consistency.algorithm.DataMatchDataConsistencyCalculateAlgorithm;
import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import org.apache.shardingsphere.test.util.PropertiesBuilder;
+import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@@ -120,6 +122,23 @@ class DataMatchDataConsistencyCalculateAlgorithmTest {
assertThat(sourceCalculateResult.get(), is(targetCalculateResult.get()));
}
+ @Test
+ void assertInitWithWrongProps() {
+ DataMatchDataConsistencyCalculateAlgorithm calculateAlgorithm = new DataMatchDataConsistencyCalculateAlgorithm();
+ calculateAlgorithm.init(PropertiesBuilder.build(new Property("chunk-size", "wrong")));
+ DataConsistencyCalculateParameter sourceParam = generateParameter(source, "t_order_copy", 0);
+ Optional<DataConsistencyCalculatedResult> sourceCalculateResult = calculateAlgorithm.calculateChunk(sourceParam);
+ DataConsistencyCalculateParameter targetParam = generateParameter(target, "t_order", 0);
+ Optional<DataConsistencyCalculatedResult> targetCalculateResult = calculateAlgorithm.calculateChunk(targetParam);
+ assertTrue(sourceCalculateResult.isPresent());
+ assertTrue(targetCalculateResult.isPresent());
+ assertTrue(sourceCalculateResult.get().getMaxUniqueKeyValue().isPresent());
+ assertTrue(targetCalculateResult.get().getMaxUniqueKeyValue().isPresent());
+ assertThat(sourceCalculateResult.get().getMaxUniqueKeyValue().get(), is(targetCalculateResult.get().getMaxUniqueKeyValue().get()));
+ assertThat(targetCalculateResult.get().getMaxUniqueKeyValue().get(), is(10L));
+ assertThat(sourceCalculateResult.get(), is(targetCalculateResult.get()));
+ }
+
private DataConsistencyCalculateParameter generateParameter(final PipelineDataSourceWrapper dataSource, final String logicTableName, final Object dataCheckPosition) {
PipelineColumnMetaData uniqueKey = new PipelineColumnMetaData(1, "order_id", Types.INTEGER, "integer", false, true, true);
return new DataConsistencyCalculateParameter(dataSource, null, logicTableName, Collections.emptyList(),