From 66122a6a0c92266173776693525af534face8ce8 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 12:16:02 +0800 Subject: [PATCH 01/18] fix NPE --- .../main/java/org/apache/hugegraph/pd/ConfigService.java | 7 ++++++- .../main/java/org/apache/hugegraph/pd/raft/RaftEngine.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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); } From ad5b5f233a462fa5ed54f38b490917e94007d972 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 12:16:17 +0800 Subject: [PATCH 02/18] adapt some tests --- .../hugegraph/pd/MonitorServiceTest.java | 2 -- .../hugegraph/pd/PartitionCacheTest.java | 5 +-- .../hugegraph/pd/StoreNodeServiceTest.java | 31 ++++++------------- .../org/apache/hugegraph/pd/UnitTestBase.java | 31 ------------------- 4 files changed, 13 insertions(+), 56 deletions(-) delete mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java 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/MonitorServiceTest.java index 25272127fd..39de8bda4e 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/MonitorServiceTest.java @@ -25,8 +25,6 @@ import org.junit.Assert; import org.junit.BeforeClass; -// import org.junit.Test; - public class MonitorServiceTest { static PDConfig pdConfig; 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..dc48f3f0ad 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 @@ -25,6 +25,7 @@ import org.apache.hugegraph.pd.common.KVPair; import org.apache.hugegraph.pd.common.PartitionCache; import org.apache.hugegraph.pd.grpc.Metapb; +import org.junit.Test; import com.google.common.collect.Range; import com.google.common.collect.RangeMap; @@ -32,7 +33,7 @@ public class PartitionCacheTest { - // @Test + @Test public void test() { PartitionCache cache = new PartitionCache(); for (int i = 0; i < 10; i++) { @@ -51,7 +52,7 @@ public void test() { } - // @Test + @Test public void test1() { Map> keyToPartIdCache = new HashMap<>(); // graphName + PartitionID组成key 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 index c8f0ce39e5..69826c11cc 100644 --- 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 @@ -37,6 +37,7 @@ import org.apache.hugegraph.pd.grpc.pulse.TransferLeader; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Test; public class StoreNodeServiceTest { static PDConfig pdConfig; @@ -87,13 +88,16 @@ public static void deleteDirectory(File dir) { } } - // @Test + @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); + 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++) { @@ -168,7 +172,7 @@ public void testStoreNodeService() throws PDException { } - // @Test + @Test public void testSplitPartition() throws PDException { StoreNodeService storeService = new StoreNodeService(pdConfig); PartitionService partitionService = new PartitionService(pdConfig, storeService); @@ -258,7 +262,7 @@ public void changePartitionKeyRange(Metapb.Partition partition, }); } - // @Test + @Test public void testPartitionService() throws PDException, ExecutionException, InterruptedException { StoreNodeService storeService = new StoreNodeService(pdConfig); @@ -267,7 +271,7 @@ public void testPartitionService() throws PDException, ExecutionException, for (int i = 0; i < count; i++) { Metapb.Store store = Metapb.Store.newBuilder() .setId(0) - .setAddress(String.valueOf(i)) + .setAddress("127.0.0.1:850" + i) .setDeployPath("/data") .addLabels(Metapb.StoreLabel.newBuilder() .setKey("namespace") @@ -281,6 +285,7 @@ public void testPartitionService() throws PDException, ExecutionException, PartitionService partitionService = new PartitionService(pdConfig, storeService); + storeService.init(partitionService); Metapb.Graph graph = Metapb.Graph.newBuilder() .setGraphName("defaultGH") @@ -420,7 +425,7 @@ public void onPartitionRemoved(Metapb.Partition partition) { } - // @Test + @Test public void testMergeGraphParams() throws PDException { StoreNodeService storeService = new StoreNodeService(pdConfig); PartitionService partitionService = new PartitionService(pdConfig, storeService); @@ -466,20 +471,4 @@ public void testMergeGraphParams() throws PDException { 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 deleted file mode 100644 index 35ada84167..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java +++ /dev/null @@ -1,31 +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; - -public class UnitTestBase { - public static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - for (File file : dir.listFiles()) { - deleteDir(file); - } - } - return dir.delete(); - } -} From d55f0809e9250000bb83589b2afa0601bcbe549d Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 16:57:35 +0800 Subject: [PATCH 03/18] intro useless annotation --- .../apache/hugegraph/pd/client/Discoverable.java | 2 ++ .../hugegraph/pd/client/DiscoveryClient.java | 2 ++ .../hugegraph/pd/client/DiscoveryClientImpl.java | 2 ++ .../apache/hugegraph/pd/client/LicenseClient.java | 2 ++ .../org/apache/hugegraph/pd/common/Useless.java | 14 ++++++++++++++ 5 files changed, 22 insertions(+) create mode 100644 hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java 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..f685821b46 --- /dev/null +++ b/hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java @@ -0,0 +1,14 @@ +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 {} From a689e3a490188ed7c53023df5393b5e1129194db Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 16:57:40 +0800 Subject: [PATCH 04/18] Revert "adapt some tests" This reverts commit ad5b5f233a462fa5ed54f38b490917e94007d972. --- .../hugegraph/pd/MonitorServiceTest.java | 2 ++ .../hugegraph/pd/PartitionCacheTest.java | 5 ++- .../hugegraph/pd/StoreNodeServiceTest.java | 31 +++++++++++++------ .../org/apache/hugegraph/pd/UnitTestBase.java | 31 +++++++++++++++++++ 4 files changed, 56 insertions(+), 13 deletions(-) create mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java 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/MonitorServiceTest.java index 39de8bda4e..25272127fd 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/MonitorServiceTest.java @@ -25,6 +25,8 @@ import org.junit.Assert; import org.junit.BeforeClass; +// import org.junit.Test; + public class MonitorServiceTest { static PDConfig pdConfig; 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 dc48f3f0ad..71efa70ecd 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 @@ -25,7 +25,6 @@ import org.apache.hugegraph.pd.common.KVPair; import org.apache.hugegraph.pd.common.PartitionCache; import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Test; import com.google.common.collect.Range; import com.google.common.collect.RangeMap; @@ -33,7 +32,7 @@ public class PartitionCacheTest { - @Test + // @Test public void test() { PartitionCache cache = new PartitionCache(); for (int i = 0; i < 10; i++) { @@ -52,7 +51,7 @@ public void test() { } - @Test + // @Test public void test1() { Map> keyToPartIdCache = new HashMap<>(); // graphName + PartitionID组成key 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 index 69826c11cc..c8f0ce39e5 100644 --- 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 @@ -37,7 +37,6 @@ import org.apache.hugegraph.pd.grpc.pulse.TransferLeader; import org.junit.Assert; import org.junit.BeforeClass; -import org.junit.Test; public class StoreNodeServiceTest { static PDConfig pdConfig; @@ -88,16 +87,13 @@ public static void deleteDirectory(File dir) { } } - @Test + // @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); - 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++) { @@ -172,7 +168,7 @@ public void testStoreNodeService() throws PDException { } - @Test + // @Test public void testSplitPartition() throws PDException { StoreNodeService storeService = new StoreNodeService(pdConfig); PartitionService partitionService = new PartitionService(pdConfig, storeService); @@ -262,7 +258,7 @@ public void changePartitionKeyRange(Metapb.Partition partition, }); } - @Test + // @Test public void testPartitionService() throws PDException, ExecutionException, InterruptedException { StoreNodeService storeService = new StoreNodeService(pdConfig); @@ -271,7 +267,7 @@ public void testPartitionService() throws PDException, ExecutionException, for (int i = 0; i < count; i++) { Metapb.Store store = Metapb.Store.newBuilder() .setId(0) - .setAddress("127.0.0.1:850" + i) + .setAddress(String.valueOf(i)) .setDeployPath("/data") .addLabels(Metapb.StoreLabel.newBuilder() .setKey("namespace") @@ -285,7 +281,6 @@ public void testPartitionService() throws PDException, ExecutionException, PartitionService partitionService = new PartitionService(pdConfig, storeService); - storeService.init(partitionService); Metapb.Graph graph = Metapb.Graph.newBuilder() .setGraphName("defaultGH") @@ -425,7 +420,7 @@ public void onPartitionRemoved(Metapb.Partition partition) { } - @Test + // @Test public void testMergeGraphParams() throws PDException { StoreNodeService storeService = new StoreNodeService(pdConfig); PartitionService partitionService = new PartitionService(pdConfig, storeService); @@ -471,4 +466,20 @@ public void testMergeGraphParams() throws PDException { 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 new file mode 100644 index 0000000000..35ada84167 --- /dev/null +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/UnitTestBase.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hugegraph.pd; + +import java.io.File; + +public class UnitTestBase { + public static boolean deleteDir(File dir) { + if (dir.isDirectory()) { + for (File file : dir.listFiles()) { + deleteDir(file); + } + } + return dir.delete(); + } +} From 48eeacad0c6578f55dcbda95b26c3f2e3bdeb607 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:02:39 +0800 Subject: [PATCH 05/18] mark some classes useless and rearrange package --- .../java/org/apache/hugegraph/pd/PartitionCacheTest.java | 2 ++ .../java/org/apache/hugegraph/pd/PartitionServiceTest.java | 2 ++ .../main/java/org/apache/hugegraph/pd/UnitTestBase.java | 3 +++ .../hugegraph/pd/{ => client}/StoreRegisterTest.java | 6 +----- .../hugegraph/pd/{ => service}/MonitorServiceTest.java | 5 ++++- .../hugegraph/pd/{ => service}/StoreNodeServiceTest.java | 7 ++++++- 6 files changed, 18 insertions(+), 7 deletions(-) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{ => client}/StoreRegisterTest.java (95%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{ => service}/MonitorServiceTest.java (95%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{ => service}/StoreNodeServiceTest.java (98%) 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..c2db028244 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 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 index 82fd4c9bdb..874518a0c0 100644 --- 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 @@ -21,9 +21,11 @@ import java.util.Collections; import java.util.List; +import org.apache.hugegraph.pd.common.Useless; import org.apache.hugegraph.pd.grpc.Metapb; import org.junit.Test; +@Useless public class PartitionServiceTest { @Test public void testPartitionHeartbeat() { 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/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/MonitorServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/MonitorServiceTest.java similarity index 95% 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/service/MonitorServiceTest.java index 25272127fd..c3184c352e 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/service/MonitorServiceTest.java @@ -15,10 +15,13 @@ * limitations under the License. */ -package org.apache.hugegraph.pd; +package org.apache.hugegraph.pd.service; 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; 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/service/StoreNodeServiceTest.java similarity index 98% rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceTest.java index c8f0ce39e5..8517a08262 100644 --- 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/service/StoreNodeServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.hugegraph.pd; +package org.apache.hugegraph.pd.service; import java.io.File; import java.io.IOException; @@ -25,6 +25,11 @@ 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; From b7bb946b58506a8c0f2b83367e19cf19beabed40 Mon Sep 17 00:00:00 2001 From: V_Galaxy Date: Sat, 16 Mar 2024 17:04:10 +0800 Subject: [PATCH 06/18] Update hugegraph-pd/hg-pd-common/src/main/java/org/apache/hugegraph/pd/common/Useless.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../org/apache/hugegraph/pd/common/Useless.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 index f685821b46..b4bd1d4af6 100644 --- 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 @@ -1,3 +1,20 @@ +/* + * 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; From b16d510d34478696a323f020273794c8b03f6a2a Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:07:45 +0800 Subject: [PATCH 07/18] rearrange test package --- .../java/org/apache/hugegraph/pd/common/CommonSuiteTest.java | 5 ----- .../hugegraph/pd/{common => core}/MetadataKeyHelperTest.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{common => core}/MetadataKeyHelperTest.java (99%) 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/core/MetadataKeyHelperTest.java similarity index 99% rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MetadataKeyHelperTest.java index ea239ed93c..9037a81851 100644 --- 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/core/MetadataKeyHelperTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.hugegraph.pd.common; +package org.apache.hugegraph.pd.core; import static org.assertj.core.api.Assertions.assertThat; From dc01e1337328ba4c81e04578edc4d36e39bc2544 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:10:20 +0800 Subject: [PATCH 08/18] rearrange test package --- .../hugegraph/pd/{ => core}/store/HgKVStoreImplTest.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{ => core}/store/HgKVStoreImplTest.java (96%) 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 96% 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..08da9aac24 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,6 +24,8 @@ 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; From 2ce14693e459d282d6cd128cf490c20de363a2e2 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:15:47 +0800 Subject: [PATCH 09/18] fix HgKVStoreImplTest --- .../org/apache/hugegraph/pd/core/PDCoreSuiteTest.java | 4 +++- .../hugegraph/pd/core/store/HgKVStoreImplTest.java | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) 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..3141a1b37a 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; @@ -27,7 +28,8 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ StoreNodeServiceTest.class, - MetadataKeyHelperTest.class + MetadataKeyHelperTest.class, + HgKVStoreImplTest.class }) @Slf4j diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java index 08da9aac24..cfd5299ea0 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/store/HgKVStoreImplTest.java @@ -28,6 +28,7 @@ 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"; @@ -45,7 +46,7 @@ public static void init() throws IOException { }}; } - // @Test + @Test public void Test() throws PDException { HgKVStore kvStore = new HgKVStoreImpl(); kvStore.init(pdConfig); @@ -65,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); @@ -103,5 +106,7 @@ public void TestSnapshot() throws PDException { kvStore.put(key, value); } Assert.assertEquals(200, kvStore.scanPrefix("k".getBytes()).size()); + + kvStore.close(); } } From 8a64eb4065c3a70a097c252d9b6663e3456510fb Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:16:56 +0800 Subject: [PATCH 10/18] mark tests in grpc package is useless --- .../main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java | 3 ++- .../main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) 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({ }) From 32e93ff560dc3296aa875c1f695db58e47d63521 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:18:25 +0800 Subject: [PATCH 11/18] add comment for PartitionCacheTest --- .../main/java/org/apache/hugegraph/pd/PartitionCacheTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c2db028244..1acfd2eaf2 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 @@ -31,7 +31,7 @@ import com.google.common.collect.RangeMap; import com.google.common.collect.TreeRangeMap; -@Useless +@Useless // can be merged to org.apache.hugegraph.pd.common.PartitionCacheTest public class PartitionCacheTest { // @Test From 4eb5d04a0dc46de5a0295ece2521ecb71e0361e6 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:19:25 +0800 Subject: [PATCH 12/18] add comment for PartitionServiceTest --- .../main/java/org/apache/hugegraph/pd/PartitionServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 874518a0c0..07a7be649b 100644 --- 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 @@ -25,7 +25,7 @@ import org.apache.hugegraph.pd.grpc.Metapb; import org.junit.Test; -@Useless +@Useless // can be merged to org.apache.hugegraph.pd.service.PartitionServiceTest public class PartitionServiceTest { @Test public void testPartitionHeartbeat() { From dd644feecb1032fbcb8a6ae1ef62abe1b8707031 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:40:27 +0800 Subject: [PATCH 13/18] refactor pd core tests --- .github/workflows/pd-store.yml | 4 +- hugegraph-pd/hg-pd-test/pom.xml | 4 +- .../hugegraph/pd/PartitionServiceTest.java | 47 -- .../hugegraph/pd/core/BaseCoreTest.java | 3 +- .../{service => core}/ConfigServiceTest.java | 3 +- .../pd/{service => core}/IdServiceTest.java | 3 +- .../pd/{service => core}/KvServiceTest.java | 3 +- .../pd/{service => core}/LogServiceTest.java | 3 +- .../pd/core/MetadataKeyHelperTest.java | 217 -------- .../{service => core}/MonitorServiceTest.java | 7 +- .../hugegraph/pd/core/PDCoreSuiteTest.java | 14 +- .../PDCoreTestBase.java} | 4 +- .../PartitionServiceTest.java | 24 +- .../StoreMonitorDataServiceTest.java | 4 +- .../StoreNodeServiceNewTest.java | 4 +- .../pd/core/StoreNodeServiceTest.java | 372 ++++++++++++- .../{service => core}/StoreServiceTest.java | 3 +- .../TaskScheduleServiceTest.java | 4 +- .../pd/core/meta/MetadataKeyHelperTest.java | 192 +++++++ .../pd/{service => rest}/BaseServerTest.java | 2 +- .../hugegraph/pd/rest/PDRestSuiteTest.java | 16 + .../pd/{service => rest}/RestApiTest.java | 2 +- .../hugegraph/pd/service/ServerSuiteTest.java | 42 -- .../pd/service/StoreNodeServiceTest.java | 490 ------------------ hugegraph-pd/pom.xml | 4 +- 25 files changed, 638 insertions(+), 833 deletions(-) delete mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/ConfigServiceTest.java (97%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/IdServiceTest.java (97%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/KvServiceTest.java (95%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/LogServiceTest.java (95%) delete mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MetadataKeyHelperTest.java rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/MonitorServiceTest.java (98%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service/PdTestBase.java => core/PDCoreTestBase.java} (99%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/PartitionServiceTest.java (85%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/StoreMonitorDataServiceTest.java (96%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/StoreNodeServiceNewTest.java (95%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/StoreServiceTest.java (99%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => core}/TaskScheduleServiceTest.java (97%) rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => rest}/BaseServerTest.java (97%) create mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java rename hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/{service => rest}/RestApiTest.java (99%) delete mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java delete mode 100644 hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceTest.java diff --git a/.github/workflows/pd-store.yml b/.github/workflows/pd-store.yml index 2a84696663..c3e2db10de 100644 --- a/.github/workflows/pd-store.yml +++ b/.github/workflows/pd-store.yml @@ -65,9 +65,9 @@ jobs: run: | mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test -Dmaven.test.failure.ignore=true - - 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 -Dmaven.test.failure.ignore=true - name: Upload coverage to Codecov uses: codecov/codecov-action@v3.0.0 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/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java deleted file mode 100644 index 07a7be649b..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java +++ /dev/null @@ -1,47 +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.common.Useless; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Test; - -@Useless // can be merged to org.apache.hugegraph.pd.service.PartitionServiceTest -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/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/core/MetadataKeyHelperTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MetadataKeyHelperTest.java deleted file mode 100644 index 9037a81851..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/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.core; - -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/service/MonitorServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java similarity index 98% rename from hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/MonitorServiceTest.java rename to hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java index c3184c352e..d9c6a63ce5 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/MonitorServiceTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package org.apache.hugegraph.pd.service; +package org.apache.hugegraph.pd.core; import java.util.concurrent.ExecutionException; @@ -27,8 +27,7 @@ import org.apache.hugegraph.pd.grpc.Metapb; import org.junit.Assert; import org.junit.BeforeClass; - -// import org.junit.Test; +import org.junit.Test; public class MonitorServiceTest { static PDConfig pdConfig; @@ -70,7 +69,7 @@ public static void clearClusterData() throws ExecutionException, InterruptedExce //client.close(); } - // @Test + @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 3141a1b37a..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 @@ -27,9 +27,19 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - StoreNodeServiceTest.class, MetadataKeyHelperTest.class, - HgKVStoreImplTest.class + HgKVStoreImplTest.class, + ConfigServiceTest.class, + IdServiceTest.class, + KvServiceTest.class, + LogServiceTest.class, + MonitorServiceTest.class, + PartitionServiceTest.class, + StoreMonitorDataServiceTest.class, + StoreNodeServiceNewTest.class, + StoreNodeServiceTest.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..4713d832e9 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,92 @@ 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.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()); + } + } @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 +138,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 +177,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..c7961a29e8 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,6 +33,7 @@ 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.Test; 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/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/rest/PDRestSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java new file mode 100644 index 0000000000..d05cc33846 --- /dev/null +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java @@ -0,0 +1,16 @@ +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, +}) + +@Slf4j +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/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/service/ServerSuiteTest.java deleted file mode 100644 index fe8c0ed044..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java +++ /dev/null @@ -1,42 +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.service; - -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 { -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceTest.java deleted file mode 100644 index 8517a08262..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceTest.java +++ /dev/null @@ -1,490 +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.service; - -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; - -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/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 From 87bff7c4544d62a7b1f230a4c7d94cec20cad303 Mon Sep 17 00:00:00 2001 From: V_Galaxy Date: Sat, 16 Mar 2024 17:42:23 +0800 Subject: [PATCH 14/18] Update hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- .../hugegraph/pd/rest/PDRestSuiteTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java index d05cc33846..d16d21208c 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/PDRestSuiteTest.java @@ -1,3 +1,20 @@ +/* + * 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.rest; import org.junit.runner.RunWith; From 9f79e9cb57b48c500855729a381cf9d5403e8e16 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:48:41 +0800 Subject: [PATCH 15/18] ignore some core tests --- .../org/apache/hugegraph/pd/core/MonitorServiceTest.java | 8 ++++++++ .../apache/hugegraph/pd/core/StoreNodeServiceTest.java | 2 ++ .../org/apache/hugegraph/pd/core/StoreServiceTest.java | 3 +++ 3 files changed, 13 insertions(+) diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java index d9c6a63ce5..546d288f2e 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java @@ -27,6 +27,7 @@ import org.apache.hugegraph.pd.grpc.Metapb; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class MonitorServiceTest { @@ -37,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() {{ @@ -53,6 +56,10 @@ public static void init() throws ExecutionException, InterruptedException { this.setTotalCount(10); }}); + pdConfig.setRaft(new PDConfig().new Raft() {{ + this.setEnable(false); + }}); + clearClusterData(); } @@ -69,6 +76,7 @@ public static void clearClusterData() throws ExecutionException, InterruptedExce //client.close(); } + @Ignore @Test public void testPatrolStores() throws PDException, InterruptedException { StoreNodeService storeService = new StoreNodeService(pdConfig); 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 4713d832e9..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 @@ -42,6 +42,7 @@ import org.apache.hugegraph.pd.grpc.pulse.TransferLeader; import org.junit.Assert; import org.junit.BeforeClass; +import org.junit.Ignore; import org.junit.Test; public class StoreNodeServiceTest { @@ -93,6 +94,7 @@ public static void deleteDirectory(File dir) { } } + @Ignore @Test public void testStoreNodeService() throws PDException { Assert.assertEquals(pdConfig.getPartition().getTotalCount(), diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java index c7961a29e8..73f8b62233 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java @@ -35,6 +35,7 @@ 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 { @@ -288,6 +289,7 @@ public void testUpdateStore() throws Exception { final Metapb.Store result = this.service.updateStore(store); } + @Ignore @Test public void testStoreTurnoff() throws Exception { // Setup @@ -492,6 +494,7 @@ public void testGetActiveStores1ThrowsPDException() { } } + @Ignore @Test public void testGetTombStores() throws Exception { // Setup From 5cd0d0242c46f94a03a79a78324e0e35bddcb1ef Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:50:52 +0800 Subject: [PATCH 16/18] ignore some tests --- .../java/org/apache/hugegraph/pd/client/PDClientTest.java | 3 +++ .../main/java/org/apache/hugegraph/pd/clitools/MainTest.java | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) 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/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"}); From afe99065e9da153f120a4273d61b4290b98af3e0 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 17:52:53 +0800 Subject: [PATCH 17/18] rearrange pd CI yml --- .github/workflows/pd-store.yml | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pd-store.yml b/.github/workflows/pd-store.yml index c3e2db10de..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 rest test run: | - mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-rest-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 From 04c8eff282ca05903b74585c5bfba390df72e063 Mon Sep 17 00:00:00 2001 From: VGalaxies Date: Sat, 16 Mar 2024 21:26:02 +0800 Subject: [PATCH 18/18] add value for Useless annotation --- .../main/java/org/apache/hugegraph/pd/common/Useless.java | 5 ++++- .../java/org/apache/hugegraph/pd/PartitionCacheTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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 index b4bd1d4af6..ec000f7503 100644 --- 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 @@ -28,4 +28,7 @@ */ @Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) @Retention(RetentionPolicy.SOURCE) -public @interface Useless {} +public @interface Useless { + + String value() default "Remove or handle it later"; +} 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 1acfd2eaf2..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 @@ -31,7 +31,7 @@ import com.google.common.collect.RangeMap; import com.google.common.collect.TreeRangeMap; -@Useless // can be merged to org.apache.hugegraph.pd.common.PartitionCacheTest +@Useless("can be merged to org.apache.hugegraph.pd.common.PartitionCacheTest") public class PartitionCacheTest { // @Test