You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by vg...@apache.org on 2024/03/16 04:16:31 UTC
(incubator-hugegraph) branch fix-pd-test created (now ad5b5f233)
This is an automated email from the ASF dual-hosted git repository.
vgalaxies pushed a change to branch fix-pd-test
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
at ad5b5f233 adapt some tests
This branch includes the following new commits:
new 66122a6a0 fix NPE
new ad5b5f233 adapt some tests
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(incubator-hugegraph) 02/02: adapt some tests
Posted by vg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vgalaxies pushed a commit to branch fix-pd-test
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit ad5b5f233a462fa5ed54f38b490917e94007d972
Author: VGalaxies <vg...@apache.org>
AuthorDate: Sat Mar 16 12:16:17 2024 +0800
adapt some tests
---
.../apache/hugegraph/pd/MonitorServiceTest.java | 2 --
.../apache/hugegraph/pd/PartitionCacheTest.java | 5 ++--
.../apache/hugegraph/pd/StoreNodeServiceTest.java | 31 +++++++---------------
.../java/org/apache/hugegraph/pd/UnitTestBase.java | 31 ----------------------
4 files changed, 13 insertions(+), 56 deletions(-)
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 25272127f..39de8bda4 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.apache.hugegraph.pd.grpc.Metapb;
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 71efa70ec..dc48f3f0a 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 java.util.Map;
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 @@ import com.google.common.collect.TreeRangeMap;
public class PartitionCacheTest {
- // @Test
+ @Test
public void test() {
PartitionCache cache = new PartitionCache();
for (int i = 0; i < 10; i++) {
@@ -51,7 +52,7 @@ public class PartitionCacheTest {
}
- // @Test
+ @Test
public void test1() {
Map<String, RangeMap<Long, Integer>> 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 c8f0ce39e..69826c11c 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.SplitPartition;
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 class StoreNodeServiceTest {
}
}
- // @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 class StoreNodeServiceTest {
}
- // @Test
+ @Test
public void testSplitPartition() throws PDException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
@@ -258,7 +262,7 @@ public class StoreNodeServiceTest {
});
}
- // @Test
+ @Test
public void testPartitionService() throws PDException, ExecutionException,
InterruptedException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
@@ -267,7 +271,7 @@ public class StoreNodeServiceTest {
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 class StoreNodeServiceTest {
PartitionService partitionService = new PartitionService(pdConfig, storeService);
+ storeService.init(partitionService);
Metapb.Graph graph = Metapb.Graph.newBuilder()
.setGraphName("defaultGH")
@@ -420,7 +425,7 @@ public class StoreNodeServiceTest {
}
- // @Test
+ @Test
public void testMergeGraphParams() throws PDException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
@@ -466,20 +471,4 @@ public class StoreNodeServiceTest {
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 35ada8416..000000000
--- 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();
- }
-}
(incubator-hugegraph) 01/02: fix NPE
Posted by vg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vgalaxies pushed a commit to branch fix-pd-test
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git
commit 66122a6a0c92266173776693525af534face8ce8
Author: VGalaxies <vg...@apache.org>
AuthorDate: Sat Mar 16 12:16:02 2024 +0800
fix NPE
---
.../src/main/java/org/apache/hugegraph/pd/ConfigService.java | 7 ++++++-
.../src/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 2557745c8..4a05b57ee 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 class ConfigService implements RaftStateListener {
* @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 f3089ed07..6882585a0 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 class RaftEngine {
}
public boolean isLeader() {
+ if (Objects.isNull(this.raftNode)) {
+ return false;
+ }
return this.raftNode.isLeader(true);
}