diff --git a/.github/workflows/pd-store.yml b/.github/workflows/pd-store.yml
index 2a84696663..b3abff59d0 100644
--- a/.github/workflows/pd-store.yml
+++ b/.github/workflows/pd-store.yml
@@ -45,29 +45,30 @@ jobs:
run: |
mvn clean package -U -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -ntp
- - name: Prepare env and service
+ - name: Run common test
run: |
- $TRAVIS_DIR/start-pd.sh
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test
- - name: Run client test
+ - name: Run core test
run: |
- mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-client-test -Dmaven.test.failure.ignore=true
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test
- - name: Run core test
+ # The above tests do not require starting a PD instance.
+ - name: Prepare env and service
run: |
- mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test -Dmaven.test.failure.ignore=true
+ $TRAVIS_DIR/start-pd.sh
- - name: Run cli-tools test
+ - name: Run client test
run: |
- mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-cli-tools-test -Dmaven.test.failure.ignore=true
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-client-test
- - name: Run common test
+ - name: Run cli-tools test
run: |
- mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test -Dmaven.test.failure.ignore=true
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-cli-tools-test
- - name: Run service test
+ - name: Run rest test
run: |
- mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-service-test -Dmaven.test.failure.ignore=true
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-rest-test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.0.0
diff --git a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/Discoverable.java b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/Discoverable.java
index abdcac414c..713657bd59 100644
--- a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/Discoverable.java
+++ b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/Discoverable.java
@@ -17,9 +17,11 @@
package org.apache.hugegraph.pd.client;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
import org.apache.hugegraph.pd.grpc.discovery.Query;
+@Useless
public interface Discoverable {
NodeInfos getNodeInfos(Query query);
diff --git a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClient.java b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClient.java
index 890e9e5864..fe1546ae61 100644
--- a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClient.java
+++ b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClient.java
@@ -28,6 +28,7 @@
import java.util.function.Function;
import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.DiscoveryServiceGrpc;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
@@ -38,6 +39,7 @@
import io.grpc.ManagedChannelBuilder;
import lombok.extern.slf4j.Slf4j;
+@Useless
@Slf4j
public abstract class DiscoveryClient implements Closeable, Discoverable {
diff --git a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImpl.java b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImpl.java
index 1208370d3f..b6b3e98204 100644
--- a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImpl.java
+++ b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImpl.java
@@ -20,9 +20,11 @@
import java.util.Map;
import java.util.function.Consumer;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
import org.apache.hugegraph.pd.grpc.discovery.RegisterType;
+@Useless
public class DiscoveryClientImpl extends DiscoveryClient {
private final String id;
diff --git a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/LicenseClient.java b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/LicenseClient.java
index a96185e5af..d9a2ef5fe2 100644
--- a/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/LicenseClient.java
+++ b/hugegraph-pd/hg-pd-client/src/main/java/org/apache/hugegraph/pd/client/LicenseClient.java
@@ -18,6 +18,7 @@
package org.apache.hugegraph.pd.client;
import org.apache.hugegraph.pd.common.KVPair;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.PDGrpc;
import org.apache.hugegraph.pd.grpc.Pdpb;
@@ -27,6 +28,7 @@
import io.grpc.stub.AbstractStub;
import lombok.extern.slf4j.Slf4j;
+@Useless
@Slf4j
public class LicenseClient extends AbstractClient {
diff --git a/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java
new file mode 100644
index 0000000000..ec000f7503
--- /dev/null
+++ b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java
@@ -0,0 +1,34 @@
+/*
+ * 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.hugegraph.pd.common;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * The "Useless" annotation indicates that the annotated object can be safely removed without
+ * affecting existing functionality, including objects that are only referenced in tests.
+ */
+@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
+@Retention(RetentionPolicy.SOURCE)
+public @interface Useless {
+
+ String value() default "Remove or handle it later";
+}
diff --git a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java
index 2557745c88..4a05b57ee9 100644
--- a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java
+++ b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java
@@ -18,6 +18,7 @@
package org.apache.hugegraph.pd;
import java.util.List;
+import java.util.Objects;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
@@ -128,7 +129,11 @@ public synchronized PDConfig setPartitionCount(int count) {
* @throws PDException when io error
*/
public int getPartitionCount() throws PDException {
- return getPDConfig().getPartitionCount();
+ Metapb.PDConfig config = getPDConfig();
+ if (Objects.nonNull(config)) {
+ return config.getPartitionCount();
+ }
+ return pdConfig.getInitialPartitionCount();
}
@Override
diff --git a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java
index f3089ed074..6882585a08 100644
--- a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java
+++ b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/raft/RaftEngine.java
@@ -159,6 +159,9 @@ public void shutDown() {
}
public boolean isLeader() {
+ if (Objects.isNull(this.raftNode)) {
+ return false;
+ }
return this.raftNode.isLeader(true);
}
diff --git a/hugegraph-pd/hg-pd-test/pom.xml b/hugegraph-pd/hg-pd-test/pom.xml
index 19e1855d8c..b41c5a2a2e 100644
--- a/hugegraph-pd/hg-pd-test/pom.xml
+++ b/hugegraph-pd/hg-pd-test/pom.xml
@@ -292,14 +292,14 @@
- pd-service-test
+ pd-rest-test
${basedir}/src/main/java/
${basedir}/target/classes/
- **/ServerSuiteTest.java
+ **/PDRestSuiteTest.java
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java
index 71efa70ecd..f01ba966d2 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java
@@ -24,12 +24,14 @@
import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.PartitionCache;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.grpc.Metapb;
import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;
+@Useless("can be merged to org.apache.hugegraph.pd.common.PartitionCacheTest")
public class PartitionCacheTest {
// @Test
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java
deleted file mode 100644
index 82fd4c9bdb..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.hugegraph.pd;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.junit.Test;
-
-public class PartitionServiceTest {
- @Test
- public void testPartitionHeartbeat() {
- List shardList = new ArrayList<>();
- shardList.add(Metapb.Shard.newBuilder().setStoreId(1).build());
- shardList.add(Metapb.Shard.newBuilder().setStoreId(2).build());
- shardList.add(Metapb.Shard.newBuilder().setStoreId(3).build());
- shardList = new ArrayList<>(shardList);
- Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
- .addAllShard(shardList).build();
- List shardList2 = new ArrayList<>(stats.getShardList());
- Collections.shuffle(shardList2);
- shardList2.forEach(shard -> {
- System.out.println(shard.getStoreId());
- });
-
-
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java
deleted file mode 100644
index c8f0ce39e5..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * 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.hugegraph.pd;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.config.PDConfig;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.apache.hugegraph.pd.grpc.pulse.ChangeShard;
-import org.apache.hugegraph.pd.grpc.pulse.CleanPartition;
-import org.apache.hugegraph.pd.grpc.pulse.DbCompaction;
-import org.apache.hugegraph.pd.grpc.pulse.MovePartition;
-import org.apache.hugegraph.pd.grpc.pulse.PartitionKeyRange;
-import org.apache.hugegraph.pd.grpc.pulse.SplitPartition;
-import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
-public class StoreNodeServiceTest {
- static PDConfig pdConfig;
-
- @BeforeClass
- public static void init() throws Exception {
- String path = "tmp/unitTest";
- deleteDirectory(new File(path));
- pdConfig = new PDConfig() {{
- this.setClusterId(100);
- this.setInitialStoreList(
- "127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502,127.0.0.1:8503,127.0.0.1:8504," +
- "127.0.0.1:8505");
- }};
-
- pdConfig.setStore(new PDConfig().new Store() {{
- this.setMaxDownTime(3600);
- this.setKeepAliveTimeout(3600);
- }});
-
- pdConfig.setPartition(new PDConfig().new Partition() {{
- this.setShardCount(3);
- this.setMaxShardsPerStore(3);
- }});
- pdConfig.setRaft(new PDConfig().new Raft() {{
- this.setEnable(false);
- }});
- pdConfig.setDiscovery(new PDConfig().new Discovery());
- pdConfig.setDataPath(path);
- ConfigService configService = new ConfigService(pdConfig);
- pdConfig = configService.loadConfig();
- }
-
- public static byte[] intToByteArray(int i) {
- byte[] result = new byte[4];
- result[0] = (byte) ((i >> 24) & 0xFF);
- result[1] = (byte) ((i >> 16) & 0xFF);
- result[2] = (byte) ((i >> 8) & 0xFF);
- result[3] = (byte) (i & 0xFF);
- return result;
- }
-
- public static void deleteDirectory(File dir) {
- try {
- FileUtils.deleteDirectory(dir);
- } catch (IOException e) {
- System.out.printf("Failed to start ....,%s%n", e.getMessage());
- }
- }
-
- // @Test
- public void testStoreNodeService() throws PDException {
- Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- (long) pdConfig.getInitialStoreMap().size() *
- pdConfig.getPartition().getMaxShardsPerStore()
- / pdConfig.getPartition().getShardCount());
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress("127.0.0.1:850" + i)
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + stores[i].getId());
- }
- Assert.assertEquals(count, storeService.getStores("").size());
-
- for (Metapb.Store store : stores) {
- Metapb.StoreStats stats = Metapb.StoreStats.newBuilder()
- .setStoreId(store.getId())
- .build();
- storeService.heartBeat(stats);
- }
-
- Assert.assertEquals(6, storeService.getActiveStores("").size());
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
- .setPartitionCount(10)
- .build();
- // 分配shard
- List shards = storeService.allocShards(graph, 1);
-
-
- Assert.assertEquals(3, shards.size());
-
- Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- storeService.getShardGroups().size()); // 设置leader
- Metapb.Shard leader = Metapb.Shard.newBuilder(shards.get(0))
- .setRole(Metapb.ShardRole.Leader).build();
- shards = new ArrayList<>(shards);
- shards.set(0, leader);
- // 增加shard
- pdConfig.getPartition().setShardCount(5);
-
- Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder()
- .setId(1)
- .addAllShards(shards).build();
- shards = storeService.reallocShards(shardGroup);
-
- Assert.assertEquals(5, shards.size());
- // 减少shard
- pdConfig.getPartition().setShardCount(3);
- shards = storeService.reallocShards(shardGroup);
- Assert.assertEquals(3, shards.size());
- // 包含leader,leader不能被删除
- Assert.assertTrue(shards.contains(leader));
-
- // 减少shard
- pdConfig.getPartition().setShardCount(1);
- graph = Metapb.Graph.newBuilder(graph).build();
- shards = storeService.reallocShards(shardGroup);
- Assert.assertEquals(1, shards.size());
- // 包含leader,leader不能被删除
- Assert.assertTrue(shards.contains(leader));
-
- for (Metapb.Store store : stores) {
- storeService.removeStore(store.getId());
- }
- Assert.assertEquals(0, storeService.getStores("").size());
-
-
- }
-
- // @Test
- public void testSplitPartition() throws PDException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- storeService.init(partitionService);
- partitionService.addInstructionListener(new PartitionInstructionListener() {
-
- @Override
- public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
- PDException {
-
- }
-
- @Override
- public void transferLeader(Metapb.Partition partition,
- TransferLeader transferLeader) throws PDException {
-
- }
-
- @Override
- public void splitPartition(Metapb.Partition partition,
- SplitPartition splitPartition) throws PDException {
- splitPartition.getNewPartitionList().forEach(p -> {
- System.out.println("SplitPartition " + p.getId() + " " + p.getStartKey() + "," +
- p.getEndKey());
- });
- }
-
- @Override
- public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
- PDException {
-
- }
-
- @Override
- public void movePartition(Metapb.Partition partition,
- MovePartition movePartition) throws PDException {
-
- }
-
- @Override
- public void cleanPartition(Metapb.Partition partition,
- CleanPartition cleanPartition) throws PDException {
-
- }
-
- @Override
- public void changePartitionKeyRange(Metapb.Partition partition,
- PartitionKeyRange partitionKeyRange) throws
- PDException {
-
- }
- });
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress("127.0.0.1:850" + i)
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
- }
- Assert.assertEquals(count, storeService.getStores().size());
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
- .build();
- Metapb.PartitionShard ptShard =
- partitionService.getPartitionByCode(graph.getGraphName(), 0);
- System.out.println(ptShard.getPartition().getId());
- {
- Metapb.Partition pt = ptShard.getPartition();
- System.out.println(pt.getId() + " " + pt.getStartKey() + "," + pt.getEndKey());
- }
-
- Assert.assertEquals(6, storeService.getShardGroups().size());
- // storeService.splitShardGroups(ptShard.getPartition().getId(), 4);
- Assert.assertEquals(9, storeService.getShardGroups().size());
- storeService.getShardGroups().forEach(shardGroup -> {
- System.out.println("shardGroup id = " + shardGroup.getId());
- });
- }
-
- // @Test
- public void testPartitionService() throws PDException, ExecutionException,
- InterruptedException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress(String.valueOf(i))
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
- }
- Assert.assertEquals(count, storeService.getStores("").size());
-
-
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
-
- .setPartitionCount(10)
- .build();
- // 申请分区
- Metapb.PartitionShard[] partitions = new Metapb.PartitionShard[10];
- for (int i = 0; i < partitions.length; i++) {
- partitions[i] =
- partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
- Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
- }
- System.out.println(
- "分区数量: " + partitionService.getPartitions(graph.getGraphName()).size());
-
- int[] caseNo = {0}; //1 测试增加shard, 2 //测试store下线
-
- Metapb.Shard leader = null;
- int[] finalCaseNo = caseNo;
-
- partitionService.addInstructionListener(new PartitionInstructionListener() {
-
- @Override
- public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
- PDException {
- switch (finalCaseNo[0]) {
- case 2:
- Assert.assertEquals(5, storeService.getShardGroup(partition.getId())
- .getShardsCount());
- break;
- case 3:
- storeService.getShardGroup(partition.getId()).getShardsList()
- .forEach(shard -> {
- Assert.assertNotEquals(shard.getStoreId(),
- stores[0].getId());
- });
- break;
- }
-
- }
-
- @Override
- public void transferLeader(Metapb.Partition partition, TransferLeader transferLeader) {
-
- }
-
- @Override
- public void splitPartition(Metapb.Partition partition, SplitPartition splitPartition) {
- }
-
- @Override
- public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
- PDException {
-
- }
-
- @Override
- public void movePartition(Metapb.Partition partition,
- MovePartition movePartition) throws PDException {
-
- }
-
- @Override
- public void cleanPartition(Metapb.Partition partition,
- CleanPartition cleanPartition) throws PDException {
-
- }
-
- @Override
- public void changePartitionKeyRange(Metapb.Partition partition,
- PartitionKeyRange partitionKeyRange)
- throws PDException {
-
- }
- });
- Metapb.Partition partition = partitions[0].getPartition();
- leader = Metapb.Shard.newBuilder(
- storeService.getShardGroup(partition.getId()).getShardsList().get(0)).build();
- Metapb.Shard finalLeader = leader;
- partitionService.addStatusListener(new PartitionStatusListener() {
- @Override
- public void onPartitionChanged(Metapb.Partition partition,
- Metapb.Partition newPartition) {
-
- }
-
- @Override
- public void onPartitionRemoved(Metapb.Partition partition) {
-
- }
- });
- // 测试修改图
- caseNo[0] = 1;
- partitionService.updateGraph(graph);
- for (int i = 0; i < partitions.length; i++) {
- partitions[i] =
- partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
- Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
- }
-
- graph = Metapb.Graph.newBuilder(graph)
- .setGraphName("defaultGH")
-
- .setPartitionCount(10)
- .build();
- caseNo[0] = 2;
- partitionService.updateGraph(graph);
-
- // 测试store离线
- caseNo[0] = 3;
- partitionService.storeOffline(stores[0]);
-
-
- Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
- .addGraphName(partition.getGraphName())
- .setId(partition.getId())
- .setLeader(
- Metapb.Shard.newBuilder(leader)
- .setRole(
- Metapb.ShardRole.Leader))
- .build();
- // 测试leader飘移
- caseNo[0] = 4;
- partitionService.partitionHeartbeat(stats);
- AtomicReference shard = new AtomicReference<>();
- Metapb.PartitionShard ss =
- partitionService.getPartitionShardById(partition.getGraphName(), partition.getId());
- storeService.getShardList(partition.getId()).forEach(s -> {
- if (s.getRole() == Metapb.ShardRole.Leader) {
- Assert.assertNull(shard.get());
- shard.set(s);
- }
- });
-
- Assert.assertEquals(leader.getStoreId(), shard.get().getStoreId());
-
- }
-
- // @Test
- public void testMergeGraphParams() throws PDException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- Metapb.Graph dfGraph = Metapb.Graph.newBuilder()
-
- .setPartitionCount(
- pdConfig.getPartition().getTotalCount())
-
- .build();
-
- Metapb.Graph graph1 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .setPartitionCount(20)
-
- .build();
-
- Metapb.Graph graph2 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .setPartitionCount(7).build();
- Metapb.Graph graph3 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .build();
- Metapb.Graph graph4 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .build();
-
- Metapb.Graph graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph2).build();
- Assert.assertEquals(graph2.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(graph2.getPartitionCount(), graph.getPartitionCount());
-
-
- graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph3).build();
- Assert.assertEquals(graph3.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
-
-
- graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph4).build();
- Assert.assertEquals(graph4.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
-
- }
-
- // @Test
- public void test() {
- int[] n = new int[3];
-
-
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java
index 35ada84167..e1ca5adaf9 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java
@@ -19,6 +19,9 @@
import java.io.File;
+import org.apache.hugegraph.pd.common.Useless;
+
+@Useless
public class UnitTestBase {
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java
index 5d068c02f8..470e3548f1 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java
@@ -25,6 +25,7 @@
import org.apache.hugegraph.pd.grpc.MetaTask;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.grpc.Pdpb;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -161,6 +162,7 @@ public void testGetPartitions() {
}
}
+ @Ignore
@Test
public void testUpdatePartitionLeader() {
System.out.println("updatePartitionLeader start");
@@ -398,6 +400,7 @@ public void testUpdatePartition() {
}
}
+ @Ignore
@Test
public void testDelPartition() {
try {
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/StoreRegisterTest.java
similarity index 95%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/StoreRegisterTest.java
index 48877273fc..5826b3858f 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/StoreRegisterTest.java
@@ -15,15 +15,11 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd;
+package org.apache.hugegraph.pd.client;
import java.nio.charset.StandardCharsets;
import java.util.List;
-import org.apache.hugegraph.pd.client.PDClient;
-import org.apache.hugegraph.pd.client.PDConfig;
-import org.apache.hugegraph.pd.client.PDPulse;
-import org.apache.hugegraph.pd.client.PDPulseImpl;
import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.grpc.Metapb;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java
index 526558ac95..8b2f5f8318 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java
@@ -20,8 +20,8 @@
import java.util.Arrays;
import java.util.List;
-import org.apache.hugegraph.pd.clitools.Main;
import org.apache.hugegraph.pd.common.PDException;
+import org.junit.Ignore;
import org.junit.Test;
import lombok.extern.slf4j.Slf4j;
@@ -48,6 +48,7 @@ public static boolean test2sup(List arrays, int tail, int res) {
}
}
+ @Ignore
@Test
public void getConfig() throws PDException {
Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad"});
@@ -63,6 +64,7 @@ public void setBatchFalse() throws PDException {
Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad=false"});
}
+ @Ignore
@Test
public void getConfig2() throws PDException {
Main.main(new String[]{"127.0.0.1:8686", "config", "shardCount"});
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java
index 6f676c6068..0395711caa 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java
@@ -17,8 +17,6 @@
package org.apache.hugegraph.pd.common;
-import org.apache.hugegraph.pd.service.IdServiceTest;
-import org.apache.hugegraph.pd.service.KvServiceTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -29,11 +27,8 @@
@Suite.SuiteClasses({
PartitionUtilsTest.class,
PartitionCacheTest.class,
- MetadataKeyHelperTest.class,
- KvServiceTest.class,
HgAssertTest.class,
KVPairTest.class,
- IdServiceTest.class
})
@Slf4j
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java
deleted file mode 100644
index ea239ed93c..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.hugegraph.pd.common;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.apache.hugegraph.pd.meta.MetadataKeyHelper;
-import org.junit.Test;
-
-public class MetadataKeyHelperTest {
-
- @Test
- public void testGetStoreInfoKey() {
- assertThat(MetadataKeyHelper.getStoreInfoKey(0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetActiveStoreKey() {
- assertThat(MetadataKeyHelper.getActiveStoreKey(0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetActiveStorePrefix() {
- assertThat(MetadataKeyHelper.getActiveStorePrefix()).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetStorePrefix() {
- assertThat(MetadataKeyHelper.getStorePrefix()).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetStoreStatusKey() {
- assertThat(MetadataKeyHelper.getStoreStatusKey(0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetShardGroupKey() {
- assertThat(MetadataKeyHelper.getShardGroupKey(0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetShardGroupPrefix() {
- assertThat(MetadataKeyHelper.getShardGroupPrefix()).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetPartitionKey() {
- assertThat(MetadataKeyHelper.getPartitionKey("graphName", 0)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetPartitionPrefix() {
- assertThat(MetadataKeyHelper.getPartitionPrefix("graphName")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetShardKey() {
- assertThat(MetadataKeyHelper.getShardKey(0L, 0)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetShardPrefix() {
- assertThat(MetadataKeyHelper.getShardPrefix(0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetGraphKey() {
- assertThat(MetadataKeyHelper.getGraphKey("graphName")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetGraphPrefix() {
- assertThat(MetadataKeyHelper.getGraphPrefix()).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetPartitionStatusKey() {
- assertThat(MetadataKeyHelper.getPartitionStatusKey("graphName",
- 0)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetPartitionStatusPrefixKey() {
- assertThat(MetadataKeyHelper.getPartitionStatusPrefixKey(
- "graphName")).contains(MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetGraphSpaceKey() {
- assertThat(MetadataKeyHelper.getGraphSpaceKey("graphSpace")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetPdConfigKey() {
- assertThat(MetadataKeyHelper.getPdConfigKey("configKey")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetQueueItemPrefix() {
- assertThat(MetadataKeyHelper.getQueueItemPrefix()).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetQueueItemKey() {
- assertThat(MetadataKeyHelper.getQueueItemKey("itemId")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetSpitTaskKey() {
- assertThat(MetadataKeyHelper.getSplitTaskKey("graphName", 0)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetSpitTaskPrefix() {
- assertThat(MetadataKeyHelper.getSplitTaskPrefix("graph0")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetLogKey() {
- // Setup
- final Metapb.LogRecord record = Metapb.LogRecord.newBuilder()
- .setAction("value")
- .setTimestamp(0L)
- .build();
-
- // Run the test
- final byte[] result = MetadataKeyHelper.getLogKey(record);
-
- // Verify the results
- assertThat(result).contains(MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetLogKeyPrefix() {
- assertThat(MetadataKeyHelper.getLogKeyPrefix("action", 0L)).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetKVPrefix() {
- assertThat(MetadataKeyHelper.getKVPrefix("prefix", "key")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetKVTTLPrefix() {
- assertThat(MetadataKeyHelper.getKVTTLPrefix("ttlPrefix", "prefix",
- "key")).contains(
- MetadataKeyHelper.getDelimiter());
- }
-
- @Test
- public void testGetKVWatchKeyPrefix1() {
- assertThat(
- MetadataKeyHelper.getKVWatchKeyPrefix("key", "watchDelimiter",
- 0L)).contains(
- String.valueOf(MetadataKeyHelper.getDelimiter()));
- }
-
- @Test
- public void testGetKVWatchKeyPrefix2() {
- assertThat(MetadataKeyHelper.getKVWatchKeyPrefix("key",
- "watchDelimiter")).contains(
- String.valueOf(MetadataKeyHelper.getDelimiter()));
- }
-
- @Test
- public void testGetDelimiter() {
- assertThat(MetadataKeyHelper.getDelimiter()).isEqualTo('/');
- }
-
- @Test
- public void testGetStringBuilderHelper() {
- try {
- MetadataKeyHelper.getStringBuilderHelper();
- } catch (Exception e) {
-
- }
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/BaseCoreTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/BaseCoreTest.java
index dddbffb088..c2e7f652a0 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/BaseCoreTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/BaseCoreTest.java
@@ -22,11 +22,12 @@
import org.apache.commons.io.FileUtils;
import org.apache.hugegraph.pd.ConfigService;
+import org.apache.hugegraph.pd.common.Useless;
import org.apache.hugegraph.pd.config.PDConfig;
import org.junit.After;
import org.junit.BeforeClass;
-
+@Useless
public class BaseCoreTest {
static org.apache.hugegraph.pd.config.PDConfig pdConfig;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ConfigServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
similarity index 97%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ConfigServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
index faeacd834e..c6a7c12c8d 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ConfigServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import java.util.List;
@@ -23,6 +23,7 @@
import org.apache.hugegraph.pd.IdService;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
+import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
similarity index 97%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
index dd0d3feb24..dae690d898 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import java.io.File;
@@ -23,6 +23,7 @@
import org.apache.hugegraph.pd.IdService;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.meta.IdMetaStore;
+import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Assert;
import org.junit.Test;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
similarity index 95%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
index 02870b219e..8b8175013c 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
@@ -15,10 +15,11 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import org.apache.hugegraph.pd.KvService;
import org.apache.hugegraph.pd.config.PDConfig;
+import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Assert;
import org.junit.Test;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
similarity index 95%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
index 266db76c56..ad6c7bfbbd 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
@@ -15,13 +15,14 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import java.util.List;
import org.apache.hugegraph.pd.LogService;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
+import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/MonitorServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java
similarity index 89%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/MonitorServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java
index 25272127fd..546d288f2e 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/MonitorServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java
@@ -15,17 +15,20 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd;
+package org.apache.hugegraph.pd.core;
import java.util.concurrent.ExecutionException;
+import org.apache.hugegraph.pd.PartitionService;
+import org.apache.hugegraph.pd.StoreNodeService;
+import org.apache.hugegraph.pd.TaskScheduleService;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.junit.Assert;
import org.junit.BeforeClass;
-
-// import org.junit.Test;
+import org.junit.Ignore;
+import org.junit.Test;
public class MonitorServiceTest {
static PDConfig pdConfig;
@@ -35,6 +38,8 @@ public static void init() throws ExecutionException, InterruptedException {
pdConfig = new PDConfig() {{
this.setClusterId(100);
this.setPatrolInterval(1);
+ this.setInitialStoreList("127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502," +
+ "127.0.0.1:8503,127.0.0.1:8504,127.0.0.1:8505");
}};
//pdConfig.setEtcd(new PDConfig().new Etcd() {{
@@ -51,6 +56,10 @@ public static void init() throws ExecutionException, InterruptedException {
this.setTotalCount(10);
}});
+ pdConfig.setRaft(new PDConfig().new Raft() {{
+ this.setEnable(false);
+ }});
+
clearClusterData();
}
@@ -67,7 +76,8 @@ public static void clearClusterData() throws ExecutionException, InterruptedExce
//client.close();
}
- // @Test
+ @Ignore
+ @Test
public void testPatrolStores() throws PDException, InterruptedException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java
index 3f616e2123..71a8d972a1 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java
@@ -18,6 +18,7 @@
package org.apache.hugegraph.pd.core;
import org.apache.hugegraph.pd.core.meta.MetadataKeyHelperTest;
+import org.apache.hugegraph.pd.core.store.HgKVStoreImplTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -26,8 +27,19 @@
@RunWith(Suite.class)
@Suite.SuiteClasses({
+ MetadataKeyHelperTest.class,
+ HgKVStoreImplTest.class,
+ ConfigServiceTest.class,
+ IdServiceTest.class,
+ KvServiceTest.class,
+ LogServiceTest.class,
+ MonitorServiceTest.class,
+ PartitionServiceTest.class,
+ StoreMonitorDataServiceTest.class,
+ StoreNodeServiceNewTest.class,
StoreNodeServiceTest.class,
- MetadataKeyHelperTest.class
+ StoreServiceTest.class,
+ TaskScheduleServiceTest.class
})
@Slf4j
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
similarity index 99%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
index 50eadb3a6d..244fe2e9b2 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import java.io.File;
@@ -42,7 +42,7 @@
import org.junit.AfterClass;
import org.junit.BeforeClass;
-public class PdTestBase {
+public class PDCoreTestBase {
private static final String DATA_PATH = "/tmp/pd_data";
private static PDConfig pdConfig;
private static StoreNodeService storeNodeService;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
similarity index 85%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PartitionServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
index 0a16402d33..47815318a6 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PartitionServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
@@ -15,10 +15,12 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.hugegraph.pd.PartitionService;
@@ -30,7 +32,7 @@
import org.junit.Before;
import org.junit.Test;
-public class PartitionServiceTest extends PdTestBase {
+public class PartitionServiceTest extends PDCoreTestBase {
private PartitionService service;
@@ -130,4 +132,22 @@ private void buildEnv() throws PDException {
}
}
+
+ @Test
+ public void testPartitionHeartbeat() {
+ List shardList = new ArrayList<>();
+ shardList.add(Metapb.Shard.newBuilder().setStoreId(1).build());
+ shardList.add(Metapb.Shard.newBuilder().setStoreId(2).build());
+ shardList.add(Metapb.Shard.newBuilder().setStoreId(3).build());
+ shardList = new ArrayList<>(shardList);
+ Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
+ .addAllShard(shardList).build();
+ List shardList2 = new ArrayList<>(stats.getShardList());
+ Collections.shuffle(shardList2);
+ shardList2.forEach(shard -> {
+ System.out.println(shard.getStoreId());
+ });
+
+
+ }
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
similarity index 96%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
index 21a2a37dde..8b17a38eb6 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -29,7 +29,7 @@
import org.junit.Before;
import org.junit.Test;
-public class StoreMonitorDataServiceTest extends PdTestBase {
+public class StoreMonitorDataServiceTest extends PDCoreTestBase {
StoreMonitorDataService service;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceNewTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java
similarity index 95%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceNewTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java
index 10d098d1f3..199a02e65f 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceNewTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -26,7 +26,7 @@
import org.junit.Before;
import org.junit.Test;
-public class StoreNodeServiceNewTest extends PdTestBase {
+public class StoreNodeServiceNewTest extends PDCoreTestBase {
private StoreNodeService service;
@Before
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java
index c8c7bcf157..8180ab8626 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java
@@ -17,30 +17,94 @@
package org.apache.hugegraph.pd.core;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.commons.io.FileUtils;
+import org.apache.hugegraph.pd.ConfigService;
+import org.apache.hugegraph.pd.PartitionInstructionListener;
import org.apache.hugegraph.pd.PartitionService;
+import org.apache.hugegraph.pd.PartitionStatusListener;
import org.apache.hugegraph.pd.StoreNodeService;
import org.apache.hugegraph.pd.common.PDException;
+import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.Metapb;
+import org.apache.hugegraph.pd.grpc.pulse.ChangeShard;
+import org.apache.hugegraph.pd.grpc.pulse.CleanPartition;
+import org.apache.hugegraph.pd.grpc.pulse.DbCompaction;
+import org.apache.hugegraph.pd.grpc.pulse.MovePartition;
+import org.apache.hugegraph.pd.grpc.pulse.PartitionKeyRange;
+import org.apache.hugegraph.pd.grpc.pulse.SplitPartition;
+import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
-import lombok.extern.slf4j.Slf4j;
+public class StoreNodeServiceTest {
+ static PDConfig pdConfig;
-@Slf4j
-public class StoreNodeServiceTest extends BaseCoreTest {
+ @BeforeClass
+ public static void init() throws Exception {
+ String path = "tmp/unitTest";
+ deleteDirectory(new File(path));
+ pdConfig = new PDConfig() {{
+ this.setClusterId(100);
+ this.setInitialStoreList(
+ "127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502,127.0.0.1:8503,127.0.0.1:8504," +
+ "127.0.0.1:8505");
+ }};
+ pdConfig.setStore(new PDConfig().new Store() {{
+ this.setMaxDownTime(3600);
+ this.setKeepAliveTimeout(3600);
+ }});
+ pdConfig.setPartition(new PDConfig().new Partition() {{
+ this.setShardCount(3);
+ this.setMaxShardsPerStore(3);
+ }});
+ pdConfig.setRaft(new PDConfig().new Raft() {{
+ this.setEnable(false);
+ }});
+ pdConfig.setDiscovery(new PDConfig().new Discovery());
+ pdConfig.setDataPath(path);
+ ConfigService configService = new ConfigService(pdConfig);
+ pdConfig = configService.loadConfig();
+ }
+
+ public static byte[] intToByteArray(int i) {
+ byte[] result = new byte[4];
+ result[0] = (byte) ((i >> 24) & 0xFF);
+ result[1] = (byte) ((i >> 16) & 0xFF);
+ result[2] = (byte) ((i >> 8) & 0xFF);
+ result[3] = (byte) (i & 0xFF);
+ return result;
+ }
+
+ public static void deleteDirectory(File dir) {
+ try {
+ FileUtils.deleteDirectory(dir);
+ } catch (IOException e) {
+ System.out.printf("Failed to start ....,%s%n", e.getMessage());
+ }
+ }
+
+ @Ignore
@Test
public void testStoreNodeService() throws PDException {
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- pdConfig.getInitialStoreMap().size() *
+ (long) pdConfig.getInitialStoreMap().size() *
pdConfig.getPartition().getMaxShardsPerStore()
/ pdConfig.getPartition().getShardCount());
StoreNodeService storeService = new StoreNodeService(pdConfig);
- storeService.init(new PartitionService(pdConfig, storeService));
+ PartitionService partitionService = new PartitionService(pdConfig, storeService);
+ storeService.init(partitionService);
+
int count = 6;
Metapb.Store[] stores = new Metapb.Store[count];
for (int i = 0; i < count; i++) {
@@ -76,9 +140,9 @@ public void testStoreNodeService() throws PDException {
Assert.assertEquals(3, shards.size());
- // 设置leader
+
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- storeService.getShardGroups().size());
+ storeService.getShardGroups().size()); // 设置leader
Metapb.Shard leader = Metapb.Shard.newBuilder(shards.get(0))
.setRole(Metapb.ShardRole.Leader).build();
shards = new ArrayList<>(shards);
@@ -115,5 +179,301 @@ public void testStoreNodeService() throws PDException {
}
+ // @Test
+ public void testSplitPartition() throws PDException {
+ StoreNodeService storeService = new StoreNodeService(pdConfig);
+ PartitionService partitionService = new PartitionService(pdConfig, storeService);
+ storeService.init(partitionService);
+ partitionService.addInstructionListener(new PartitionInstructionListener() {
+
+ @Override
+ public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
+ PDException {
+
+ }
+
+ @Override
+ public void transferLeader(Metapb.Partition partition,
+ TransferLeader transferLeader) throws PDException {
+
+ }
+
+ @Override
+ public void splitPartition(Metapb.Partition partition,
+ SplitPartition splitPartition) throws PDException {
+ splitPartition.getNewPartitionList().forEach(p -> {
+ System.out.println("SplitPartition " + p.getId() + " " + p.getStartKey() + "," +
+ p.getEndKey());
+ });
+ }
+
+ @Override
+ public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
+ PDException {
+
+ }
+
+ @Override
+ public void movePartition(Metapb.Partition partition,
+ MovePartition movePartition) throws PDException {
+
+ }
+
+ @Override
+ public void cleanPartition(Metapb.Partition partition,
+ CleanPartition cleanPartition) throws PDException {
+
+ }
+
+ @Override
+ public void changePartitionKeyRange(Metapb.Partition partition,
+ PartitionKeyRange partitionKeyRange) throws
+ PDException {
+
+ }
+ });
+ int count = 6;
+ Metapb.Store[] stores = new Metapb.Store[count];
+ for (int i = 0; i < count; i++) {
+ Metapb.Store store = Metapb.Store.newBuilder()
+ .setId(0)
+ .setAddress("127.0.0.1:850" + i)
+ .setDeployPath("/data")
+ .addLabels(Metapb.StoreLabel.newBuilder()
+ .setKey("namespace")
+ .setValue("default")
+ .build())
+ .build();
+ stores[i] = storeService.register(store);
+ System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
+ }
+ Assert.assertEquals(count, storeService.getStores().size());
+
+ Metapb.Graph graph = Metapb.Graph.newBuilder()
+ .setGraphName("defaultGH")
+ .build();
+ Metapb.PartitionShard ptShard =
+ partitionService.getPartitionByCode(graph.getGraphName(), 0);
+ System.out.println(ptShard.getPartition().getId());
+ {
+ Metapb.Partition pt = ptShard.getPartition();
+ System.out.println(pt.getId() + " " + pt.getStartKey() + "," + pt.getEndKey());
+ }
+
+ Assert.assertEquals(6, storeService.getShardGroups().size());
+ // storeService.splitShardGroups(ptShard.getPartition().getId(), 4);
+ Assert.assertEquals(9, storeService.getShardGroups().size());
+ storeService.getShardGroups().forEach(shardGroup -> {
+ System.out.println("shardGroup id = " + shardGroup.getId());
+ });
+ }
+ // @Test
+ public void testPartitionService() throws PDException, ExecutionException,
+ InterruptedException {
+ StoreNodeService storeService = new StoreNodeService(pdConfig);
+ int count = 6;
+ Metapb.Store[] stores = new Metapb.Store[count];
+ for (int i = 0; i < count; i++) {
+ Metapb.Store store = Metapb.Store.newBuilder()
+ .setId(0)
+ .setAddress("127.0.0.1:850" + i)
+ .setDeployPath("/data")
+ .addLabels(Metapb.StoreLabel.newBuilder()
+ .setKey("namespace")
+ .setValue("default")
+ .build())
+ .build();
+ stores[i] = storeService.register(store);
+ System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
+ }
+ Assert.assertEquals(count, storeService.getStores("").size());
+
+
+ PartitionService partitionService = new PartitionService(pdConfig, storeService);
+
+ Metapb.Graph graph = Metapb.Graph.newBuilder()
+ .setGraphName("defaultGH")
+
+ .setPartitionCount(10)
+ .build();
+ // 申请分区
+ Metapb.PartitionShard[] partitions = new Metapb.PartitionShard[10];
+ for (int i = 0; i < partitions.length; i++) {
+ partitions[i] =
+ partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
+ Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
+ }
+ System.out.println(
+ "分区数量: " + partitionService.getPartitions(graph.getGraphName()).size());
+
+ int[] caseNo = {0}; //1 测试增加shard, 2 //测试store下线
+
+ Metapb.Shard leader = null;
+ int[] finalCaseNo = caseNo;
+
+ partitionService.addInstructionListener(new PartitionInstructionListener() {
+
+ @Override
+ public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
+ PDException {
+ switch (finalCaseNo[0]) {
+ case 2:
+ Assert.assertEquals(5, storeService.getShardGroup(partition.getId())
+ .getShardsCount());
+ break;
+ case 3:
+ storeService.getShardGroup(partition.getId()).getShardsList()
+ .forEach(shard -> {
+ Assert.assertNotEquals(shard.getStoreId(),
+ stores[0].getId());
+ });
+ break;
+ }
+
+ }
+
+ @Override
+ public void transferLeader(Metapb.Partition partition, TransferLeader transferLeader) {
+
+ }
+
+ @Override
+ public void splitPartition(Metapb.Partition partition, SplitPartition splitPartition) {
+ }
+
+ @Override
+ public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
+ PDException {
+
+ }
+
+ @Override
+ public void movePartition(Metapb.Partition partition,
+ MovePartition movePartition) throws PDException {
+
+ }
+
+ @Override
+ public void cleanPartition(Metapb.Partition partition,
+ CleanPartition cleanPartition) throws PDException {
+
+ }
+
+ @Override
+ public void changePartitionKeyRange(Metapb.Partition partition,
+ PartitionKeyRange partitionKeyRange)
+ throws PDException {
+
+ }
+ });
+ Metapb.Partition partition = partitions[0].getPartition();
+ leader = Metapb.Shard.newBuilder(
+ storeService.getShardGroup(partition.getId()).getShardsList().get(0)).build();
+ Metapb.Shard finalLeader = leader;
+ partitionService.addStatusListener(new PartitionStatusListener() {
+ @Override
+ public void onPartitionChanged(Metapb.Partition partition,
+ Metapb.Partition newPartition) {
+
+ }
+
+ @Override
+ public void onPartitionRemoved(Metapb.Partition partition) {
+
+ }
+ });
+ // 测试修改图
+ caseNo[0] = 1;
+ partitionService.updateGraph(graph);
+ for (int i = 0; i < partitions.length; i++) {
+ partitions[i] =
+ partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
+ Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
+ }
+
+ graph = Metapb.Graph.newBuilder(graph)
+ .setGraphName("defaultGH")
+
+ .setPartitionCount(10)
+ .build();
+ caseNo[0] = 2;
+ partitionService.updateGraph(graph);
+
+ // 测试store离线
+ caseNo[0] = 3;
+ partitionService.storeOffline(stores[0]);
+
+
+ Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
+ .addGraphName(partition.getGraphName())
+ .setId(partition.getId())
+ .setLeader(
+ Metapb.Shard.newBuilder(leader)
+ .setRole(
+ Metapb.ShardRole.Leader))
+ .build();
+ // 测试leader飘移
+ caseNo[0] = 4;
+ partitionService.partitionHeartbeat(stats);
+ AtomicReference shard = new AtomicReference<>();
+ Metapb.PartitionShard ss =
+ partitionService.getPartitionShardById(partition.getGraphName(), partition.getId());
+ storeService.getShardList(partition.getId()).forEach(s -> {
+ if (s.getRole() == Metapb.ShardRole.Leader) {
+ Assert.assertNull(shard.get());
+ shard.set(s);
+ }
+ });
+
+ Assert.assertEquals(leader.getStoreId(), shard.get().getStoreId());
+
+ }
+
+ // @Test
+ public void testMergeGraphParams() throws PDException {
+ StoreNodeService storeService = new StoreNodeService(pdConfig);
+ PartitionService partitionService = new PartitionService(pdConfig, storeService);
+
+ Metapb.Graph dfGraph = Metapb.Graph.newBuilder()
+
+ .setPartitionCount(
+ pdConfig.getPartition().getTotalCount())
+
+ .build();
+
+ Metapb.Graph graph1 = Metapb.Graph.newBuilder()
+ .setGraphName("test")
+ .setPartitionCount(20)
+
+ .build();
+
+ Metapb.Graph graph2 = Metapb.Graph.newBuilder()
+ .setGraphName("test")
+ .setPartitionCount(7).build();
+ Metapb.Graph graph3 = Metapb.Graph.newBuilder()
+ .setGraphName("test")
+ .build();
+ Metapb.Graph graph4 = Metapb.Graph.newBuilder()
+ .setGraphName("test")
+ .build();
+
+ Metapb.Graph graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph2).build();
+ Assert.assertEquals(graph2.getGraphName(), graph.getGraphName());
+
+ Assert.assertEquals(graph2.getPartitionCount(), graph.getPartitionCount());
+
+
+ graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph3).build();
+ Assert.assertEquals(graph3.getGraphName(), graph.getGraphName());
+
+ Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
+
+
+ graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph4).build();
+ Assert.assertEquals(graph4.getGraphName(), graph.getGraphName());
+
+ Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
+
+ }
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java
similarity index 99%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java
index af17db1c72..73f8b62233 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -33,7 +33,9 @@
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.MetaTask;
import org.apache.hugegraph.pd.grpc.Metapb;
+import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
public class StoreServiceTest {
@@ -287,6 +289,7 @@ public void testUpdateStore() throws Exception {
final Metapb.Store result = this.service.updateStore(store);
}
+ @Ignore
@Test
public void testStoreTurnoff() throws Exception {
// Setup
@@ -491,6 +494,7 @@ public void testGetActiveStores1ThrowsPDException() {
}
}
+ @Ignore
@Test
public void testGetTombStores() throws Exception {
// Setup
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
similarity index 97%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
index d4686f0c5a..4b70845ad8 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.core;
import static org.junit.Assert.assertTrue;
@@ -28,7 +28,7 @@
import org.junit.Before;
import org.junit.Test;
-public class TaskScheduleServiceTest extends PdTestBase {
+public class TaskScheduleServiceTest extends PDCoreTestBase {
TaskScheduleService service;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java
index 7d38b9e132..03aa0e7856 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java
@@ -17,8 +17,10 @@
package org.apache.hugegraph.pd.core.meta;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;
+import org.apache.hugegraph.pd.grpc.Metapb;
import org.apache.hugegraph.pd.meta.MetadataKeyHelper;
import org.junit.Test;
@@ -31,4 +33,194 @@ public void testMoveTaskKey() {
var key2 = MetadataKeyHelper.getMoveTaskPrefix("foo");
assertArrayEquals(key2, "TASK_MOVE/foo".getBytes());
}
+
+ @Test
+ public void testGetStoreInfoKey() {
+ assertThat(MetadataKeyHelper.getStoreInfoKey(0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetActiveStoreKey() {
+ assertThat(MetadataKeyHelper.getActiveStoreKey(0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetActiveStorePrefix() {
+ assertThat(MetadataKeyHelper.getActiveStorePrefix()).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetStorePrefix() {
+ assertThat(MetadataKeyHelper.getStorePrefix()).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetStoreStatusKey() {
+ assertThat(MetadataKeyHelper.getStoreStatusKey(0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetShardGroupKey() {
+ assertThat(MetadataKeyHelper.getShardGroupKey(0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetShardGroupPrefix() {
+ assertThat(MetadataKeyHelper.getShardGroupPrefix()).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetPartitionKey() {
+ assertThat(MetadataKeyHelper.getPartitionKey("graphName", 0)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetPartitionPrefix() {
+ assertThat(MetadataKeyHelper.getPartitionPrefix("graphName")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetShardKey() {
+ assertThat(MetadataKeyHelper.getShardKey(0L, 0)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetShardPrefix() {
+ assertThat(MetadataKeyHelper.getShardPrefix(0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetGraphKey() {
+ assertThat(MetadataKeyHelper.getGraphKey("graphName")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetGraphPrefix() {
+ assertThat(MetadataKeyHelper.getGraphPrefix()).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetPartitionStatusKey() {
+ assertThat(MetadataKeyHelper.getPartitionStatusKey("graphName",
+ 0)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetPartitionStatusPrefixKey() {
+ assertThat(MetadataKeyHelper.getPartitionStatusPrefixKey(
+ "graphName")).contains(MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetGraphSpaceKey() {
+ assertThat(MetadataKeyHelper.getGraphSpaceKey("graphSpace")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetPdConfigKey() {
+ assertThat(MetadataKeyHelper.getPdConfigKey("configKey")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetQueueItemPrefix() {
+ assertThat(MetadataKeyHelper.getQueueItemPrefix()).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetQueueItemKey() {
+ assertThat(MetadataKeyHelper.getQueueItemKey("itemId")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetSpitTaskKey() {
+ assertThat(MetadataKeyHelper.getSplitTaskKey("graphName", 0)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetSpitTaskPrefix() {
+ assertThat(MetadataKeyHelper.getSplitTaskPrefix("graph0")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetLogKey() {
+ // Setup
+ final Metapb.LogRecord record = Metapb.LogRecord.newBuilder()
+ .setAction("value")
+ .setTimestamp(0L)
+ .build();
+
+ // Run the test
+ final byte[] result = MetadataKeyHelper.getLogKey(record);
+
+ // Verify the results
+ assertThat(result).contains(MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetLogKeyPrefix() {
+ assertThat(MetadataKeyHelper.getLogKeyPrefix("action", 0L)).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetKVPrefix() {
+ assertThat(MetadataKeyHelper.getKVPrefix("prefix", "key")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetKVTTLPrefix() {
+ assertThat(MetadataKeyHelper.getKVTTLPrefix("ttlPrefix", "prefix",
+ "key")).contains(
+ MetadataKeyHelper.getDelimiter());
+ }
+
+ @Test
+ public void testGetKVWatchKeyPrefix1() {
+ assertThat(
+ MetadataKeyHelper.getKVWatchKeyPrefix("key", "watchDelimiter",
+ 0L)).contains(
+ String.valueOf(MetadataKeyHelper.getDelimiter()));
+ }
+
+ @Test
+ public void testGetKVWatchKeyPrefix2() {
+ assertThat(MetadataKeyHelper.getKVWatchKeyPrefix("key",
+ "watchDelimiter")).contains(
+ String.valueOf(MetadataKeyHelper.getDelimiter()));
+ }
+
+ @Test
+ public void testGetDelimiter() {
+ assertThat(MetadataKeyHelper.getDelimiter()).isEqualTo('/');
+ }
+
+ @Test
+ public void testGetStringBuilderHelper() {
+ try {
+ MetadataKeyHelper.getStringBuilderHelper();
+ } catch (Exception e) {
+
+ }
+ }
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java
similarity index 93%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java
index 342ac9bc44..cfd5299ea0 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.store;
+package org.apache.hugegraph.pd.core.store;
import java.io.File;
import java.io.IOException;
@@ -24,8 +24,11 @@
import org.apache.commons.io.FileUtils;
import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
+import org.apache.hugegraph.pd.store.HgKVStore;
+import org.apache.hugegraph.pd.store.HgKVStoreImpl;
import org.junit.Assert;
import org.junit.BeforeClass;
+import org.junit.Test;
public class HgKVStoreImplTest {
static final String testPath = "tmp/test";
@@ -43,7 +46,7 @@ public static void init() throws IOException {
}};
}
- // @Test
+ @Test
public void Test() throws PDException {
HgKVStore kvStore = new HgKVStoreImpl();
kvStore.init(pdConfig);
@@ -63,9 +66,11 @@ public void Test() throws PDException {
kvStore.removeByPrefix("k".getBytes());
Assert.assertEquals(0, kvStore.scanPrefix("k".getBytes()).size());
+
+ kvStore.close();
}
- // @Test
+ @Test
public void TestSnapshot() throws PDException {
HgKVStore kvStore = new HgKVStoreImpl();
kvStore.init(pdConfig);
@@ -101,5 +106,7 @@ public void TestSnapshot() throws PDException {
kvStore.put(key, value);
}
Assert.assertEquals(200, kvStore.scanPrefix("k".getBytes()).size());
+
+ kvStore.close();
}
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java
index 0e768d6119..4ed8b39357 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java
@@ -17,10 +17,11 @@
package org.apache.hugegraph.pd.grpc;
+import org.apache.hugegraph.pd.common.Useless;
import org.junit.After;
import org.junit.BeforeClass;
-
+@Useless
public class BaseGrpcTest {
@BeforeClass
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java
index b994a1fd2e..44ffdf0649 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java
@@ -17,12 +17,13 @@
package org.apache.hugegraph.pd.grpc;
+import org.apache.hugegraph.pd.common.Useless;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import lombok.extern.slf4j.Slf4j;
-
+@Useless
@RunWith(Suite.class)
@Suite.SuiteClasses({
})
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/BaseServerTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
similarity index 97%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/BaseServerTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
index e9092a631c..5c397e8098 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/BaseServerTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.rest;
import java.io.File;
import java.net.http.HttpClient;
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java
similarity index 72%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java
index fe8c0ed044..d16d21208c 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java
@@ -15,28 +15,19 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.rest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import lombok.extern.slf4j.Slf4j;
-
@RunWith(Suite.class)
@Suite.SuiteClasses({
RestApiTest.class,
- ConfigServiceTest.class,
- IdServiceTest.class,
- KvServiceTest.class,
- LogServiceTest.class,
- StoreServiceTest.class,
- StoreNodeServiceNewTest.class,
- StoreMonitorDataServiceTest.class,
- TaskScheduleServiceTest.class,
- PartitionServiceTest.class
})
@Slf4j
-public class ServerSuiteTest {
+public class PDRestSuiteTest {
+
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
similarity index 99%
rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
index 7e5fec381e..b3165ab30b 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.hugegraph.pd.service;
+package org.apache.hugegraph.pd.rest;
import java.io.IOException;
import java.net.URI;
diff --git a/hugegraph-pd/pom.xml b/hugegraph-pd/pom.xml
index e7ccdce9b0..11b508024e 100644
--- a/hugegraph-pd/pom.xml
+++ b/hugegraph-pd/pom.xml
@@ -245,7 +245,7 @@
- pd-service-test
+ pd-rest-test
true
@@ -257,7 +257,7 @@
2.20
- pd-service-test
+ pd-rest-test
test