This is an automated email from the ASF dual-hosted git repository.
sunnianjun 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 00f5553fa3b Refactor JobDataNodeEntry (#21572)
00f5553fa3b is described below
commit 00f5553fa3b5ba2b772e9fecb58fe72f6ee4119e
Author: Liang Zhang <[email protected]>
AuthorDate: Sat Oct 15 00:53:47 2022 +0800
Refactor JobDataNodeEntry (#21572)
* Refactor JobDataNodeEntry
* For code format
---
.../inline/InlineShardingAlgorithmTest.java | 8 +++---
.../pipeline/api/datanode/JobDataNodeEntry.java | 31 +++-------------------
.../scenario/migration/MigrationJobAPIImpl.java | 2 +-
.../api/datanode/JobDataNodeEntryTest.java | 18 ++++---------
4 files changed, 13 insertions(+), 46 deletions(-)
diff --git
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
index e1e950abf18..7444822c9c7 100644
---
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
+++
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/algorithm/sharding/inline/InlineShardingAlgorithmTest.java
@@ -109,13 +109,13 @@ public final class InlineShardingAlgorithmTest {
@Test
public void assertDoShardingWithLargeValues() {
List<String> availableTargetNames = Lists.newArrayList("t_order_0",
"t_order_1", "t_order_2", "t_order_3");
- assertThat(inlineShardingAlgorithm.doSharding(availableTargetNames,
+ assertThat(inlineShardingAlgorithm.doSharding(availableTargetNames,
new PreciseShardingValue<>("t_order", "order_id",
DATA_NODE_INFO, 787694822390497280L)), is("t_order_0"));
- assertThat(inlineShardingAlgorithm.doSharding(availableTargetNames,
+ assertThat(inlineShardingAlgorithm.doSharding(availableTargetNames,
new PreciseShardingValue<>("t_order", "order_id",
DATA_NODE_INFO, new BigInteger("787694822390497280787694822390497280"))),
is("t_order_0"));
-
assertThat(inlineShardingAlgorithmWithSimplified.doSharding(availableTargetNames,
+
assertThat(inlineShardingAlgorithmWithSimplified.doSharding(availableTargetNames,
new PreciseShardingValue<>("t_order", "order_id",
DATA_NODE_INFO, 787694822390497280L)), is("t_order_0"));
-
assertThat(inlineShardingAlgorithmWithSimplified.doSharding(availableTargetNames,
+
assertThat(inlineShardingAlgorithmWithSimplified.doSharding(availableTargetNames,
new PreciseShardingValue<>("t_order", "order_id",
DATA_NODE_INFO, new BigInteger("787694822390497280787694822390497280"))),
is("t_order_0"));
}
}
diff --git
a/kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntry.java
b/kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntry.java
index 3d78b074981..d0d831078e8 100644
---
a/kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntry.java
+++
b/kernel/data-pipeline/api/src/main/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntry.java
@@ -17,45 +17,20 @@
package org.apache.shardingsphere.data.pipeline.api.datanode;
-import com.google.common.base.Splitter;
-import lombok.Getter;
-import lombok.NonNull;
import lombok.RequiredArgsConstructor;
-import lombok.ToString;
import org.apache.shardingsphere.infra.datanode.DataNode;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.Collection;
/**
* Job data node entry.
*/
-@Getter
@RequiredArgsConstructor
-@ToString
public final class JobDataNodeEntry {
- @NonNull
private final String logicTableName;
- @NonNull
- private final List<DataNode> dataNodes;
-
- /**
- * Unmarshal from text.
- *
- * @param text marshalled entry
- * @return entry
- */
- public static JobDataNodeEntry unmarshal(final String text) {
- List<String> segments = Splitter.on(":").splitToList(text);
- String logicTableName = segments.get(0);
- List<DataNode> dataNodes = new LinkedList<>();
- for (String each :
Splitter.on(",").omitEmptyStrings().splitToList(segments.get(1))) {
- dataNodes.add(new DataNode(each));
- }
- return new JobDataNodeEntry(logicTableName, dataNodes);
- }
+ private final Collection<DataNode> dataNodes;
/**
* Marshal to text.
@@ -78,7 +53,7 @@ public final class JobDataNodeEntry {
/**
* Get marshalled text estimated length.
*
- * @return length
+ * @return marshalled text estimated length
*/
public int getMarshalledTextEstimatedLength() {
return logicTableName.length() + 1 +
dataNodes.stream().mapToInt(DataNode::getFormattedTextLength).sum() +
dataNodes.size();
diff --git
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
index c78bd95f05b..25b4d8a602e 100644
---
a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
+++
b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/scenario/migration/MigrationJobAPIImpl.java
@@ -147,7 +147,7 @@ public final class MigrationJobAPIImpl extends
AbstractInventoryIncrementalJobAP
config.setTargetDatabaseType(targetDataSourceConfig.getDatabaseType().getType());
}
// target table name is logic table name, source table name is actual
table name.
- JobDataNodeEntry nodeEntry = new
JobDataNodeEntry(config.getTargetTableName(), Collections.singletonList(new
DataNode(config.getSourceResourceName(), config.getSourceTableName())));
+ JobDataNodeEntry nodeEntry = new
JobDataNodeEntry(config.getTargetTableName(), Collections.singleton(new
DataNode(config.getSourceResourceName(), config.getSourceTableName())));
String dataNodeLine = new
JobDataNodeLine(Collections.singleton(nodeEntry)).marshal();
config.setTablesFirstDataNodes(dataNodeLine);
config.setJobShardingDataNodes(Collections.singletonList(dataNodeLine));
diff --git
a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntryTest.java
b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntryTest.java
index ab88e87a7f9..2be0612bbc5 100644
---
a/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntryTest.java
+++
b/test/pipeline/src/test/java/org/apache/shardingsphere/data/pipeline/api/datanode/JobDataNodeEntryTest.java
@@ -20,25 +20,17 @@ package
org.apache.shardingsphere.data.pipeline.api.datanode;
import org.apache.shardingsphere.infra.datanode.DataNode;
import org.junit.Test;
-import java.util.List;
+import java.util.Arrays;
import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
public final class JobDataNodeEntryTest {
@Test
- public void assertSerialization() {
- String text = "t_order:ds_0.t_order_0,ds_0.t_order_1";
- JobDataNodeEntry actual = JobDataNodeEntry.unmarshal(text);
- assertNotNull(actual);
- assertThat(actual.marshal(), is(text));
- assertThat(actual.getLogicTableName(), is("t_order"));
- List<DataNode> dataNodes = actual.getDataNodes();
- assertNotNull(dataNodes);
- assertThat(dataNodes.size(), is(2));
- assertThat(dataNodes.get(0).format(), is("ds_0.t_order_0"));
- assertThat(dataNodes.get(1).format(), is("ds_0.t_order_1"));
+ public void assertMarshal() {
+ String actual = new JobDataNodeEntry("t_order", Arrays.asList(new
DataNode("ds_0.t_order_0"), new DataNode("ds_0.t_order_1"))).marshal();
+ String expected = "t_order:ds_0.t_order_0,ds_0.t_order_1";
+ assertThat(actual, is(expected));
}
}