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/22 12:36:18 UTC
(incubator-hugegraph) branch fix-pd-test updated: refactor
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
The following commit(s) were added to refs/heads/fix-pd-test by this push:
new 3facb4b76 refactor
3facb4b76 is described below
commit 3facb4b763b4813eefaac1cc6842e379ff237118
Author: VGalaxies <vg...@apache.org>
AuthorDate: Fri Mar 22 20:36:08 2024 +0800
refactor
---
.../org/apache/hugegraph/pd/meta/IdMetaStore.java | 2 +-
.../apache/hugegraph/pd/PartitionCacheTest.java | 2 -
.../org/apache/hugegraph/pd/core/BaseCoreTest.java | 10 +-
.../hugegraph/pd/core/ConfigServiceTest.java | 26 +-
.../apache/hugegraph/pd/core/IdServiceTest.java | 29 +-
.../apache/hugegraph/pd/core/KvServiceTest.java | 10 +-
.../apache/hugegraph/pd/core/LogServiceTest.java | 15 +-
.../hugegraph/pd/core/MonitorServiceTest.java | 122 ------
.../apache/hugegraph/pd/core/PDCoreSuiteTest.java | 5 -
.../apache/hugegraph/pd/core/PDCoreTestBase.java | 17 +-
.../hugegraph/pd/core/PartitionServiceTest.java | 18 +-
.../pd/core/StoreMonitorDataServiceTest.java | 5 +-
.../hugegraph/pd/core/StoreNodeServiceNewTest.java | 64 ---
.../hugegraph/pd/core/StoreNodeServiceTest.java | 479 ---------------------
.../apache/hugegraph/pd/core/StoreServiceTest.java | 64 ++-
.../hugegraph/pd/core/TaskScheduleServiceTest.java | 17 +-
.../hugegraph/pd/core/store/HgKVStoreImplTest.java | 5 +-
.../apache/hugegraph/pd/grpc/GrpcSuiteTest.java | 1 -
.../apache/hugegraph/pd/rest/BaseServerTest.java | 22 +-
.../apache/hugegraph/pd/rest/PDRestSuiteTest.java | 1 -
.../org/apache/hugegraph/pd/rest/RestApiTest.java | 1 +
21 files changed, 108 insertions(+), 807 deletions(-)
diff --git a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/meta/IdMetaStore.java b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/meta/IdMetaStore.java
index 70e4c501f..738054743 100644
--- a/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/meta/IdMetaStore.java
+++ b/hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/meta/IdMetaStore.java
@@ -47,7 +47,7 @@ public class IdMetaStore extends MetadataRocksDBStore {
private static final String CID_DEL_SLOT_PREFIX = "@CID_DEL_SLOT@";
private static final String SEPARATOR = "@";
private static final ConcurrentHashMap<String, Object> SEQUENCES = new ConcurrentHashMap<>();
- public static long CID_DEL_TIMEOUT = 24 * 3600 * 1000;
+ private static long CID_DEL_TIMEOUT = 24 * 3600 * 1000;
private final long clusterId;
public IdMetaStore(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 f01ba966d..3f2d48d35 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
@@ -52,7 +52,6 @@ public class PartitionCacheTest {
}
}
-
// @Test
public void test1() {
Map<String, RangeMap<Long, Integer>> keyToPartIdCache = new HashMap<>();
@@ -70,7 +69,6 @@ public class PartitionCacheTest {
allStoresCache.put("a", new ArrayList<>());
allStoresCache.get("a").add(Metapb.Store.newBuilder().setId(34).build());
-
Map<String, RangeMap<Long, Integer>> keyToPartIdCache2 =
cloneKeyToPartIdCache(keyToPartIdCache);
System.out.println(keyToPartIdCache2.size());
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 c2e7f652a..565d44f8a 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
@@ -30,28 +30,28 @@ import org.junit.BeforeClass;
@Useless
public class BaseCoreTest {
- static org.apache.hugegraph.pd.config.PDConfig pdConfig;
+ private static PDConfig pdConfig;
@BeforeClass
public static void init() throws Exception {
String path = "tmp/unitTest";
deleteDirectory(new File(path));
- pdConfig = new org.apache.hugegraph.pd.config.PDConfig() {{
+ 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 org.apache.hugegraph.pd.config.PDConfig().new Store() {{
+ pdConfig.setStore(new PDConfig().new Store() {{
this.setMaxDownTime(3600);
this.setKeepAliveTimeout(3600);
}});
- pdConfig.setPartition(new org.apache.hugegraph.pd.config.PDConfig().new Partition() {{
+ pdConfig.setPartition(new PDConfig().new Partition() {{
this.setShardCount(3);
this.setMaxShardsPerStore(3);
}});
- pdConfig.setRaft(new org.apache.hugegraph.pd.config.PDConfig().new Raft() {{
+ pdConfig.setRaft(new PDConfig().new Raft() {{
this.setEnable(false);
}});
pdConfig.setDiscovery(new PDConfig().new Discovery());
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
index c6a7c12c8..7ac5509bb 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/ConfigServiceTest.java
@@ -23,24 +23,21 @@ import org.apache.hugegraph.pd.ConfigService;
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;
-public class ConfigServiceTest {
-
- private final PDConfig config = BaseServerTest.getConfig();
+public class ConfigServiceTest extends PDCoreTestBase {
private ConfigService service;
@Before
public void setUp() {
- this.service = new ConfigService(this.config);
+ this.service = new ConfigService(getPdConfig());
}
@Test
- public void testGetPDConfig() throws Exception {
+ public void testGetPDConfig() {
// Setup
try {
final Metapb.PDConfig config = Metapb.PDConfig.newBuilder()
@@ -50,17 +47,17 @@ public class ConfigServiceTest {
.setMaxShardsPerStore(0)
.setTimestamp(0L).build();
this.service.setPDConfig(config);
+
// Run the test
Metapb.PDConfig result = this.service.getPDConfig(0L);
// Verify the results
- Assert.assertTrue(result.getShardCount() == 55);
+ Assert.assertEquals(55, result.getShardCount());
result = this.service.getPDConfig();
- Assert.assertTrue(result.getShardCount() == 55);
+ Assert.assertEquals(55, result.getShardCount());
} catch (Exception e) {
-
+ e.printStackTrace();
}
-
}
@Test
@@ -69,13 +66,14 @@ public class ConfigServiceTest {
Metapb.GraphSpace space = Metapb.GraphSpace.newBuilder()
.setName("gs1")
.setTimestamp(0L).build();
- final List<Metapb.GraphSpace> expectedResult = List.of(space);
this.service.setGraphSpace(space);
+
// Run the test
- final List<Metapb.GraphSpace> result = this.service.getGraphSpace(
- "gs1");
+ final List<Metapb.GraphSpace> result = this.service.getGraphSpace("gs1");
+ // Verify the results
Assert.assertEquals(1, result.size());
+ Assert.assertEquals(space.getName(), result.get(0).getName());
}
@Test
@@ -101,7 +99,7 @@ public class ConfigServiceTest {
expectedResult.setLicensePath("licensePath");
this.service.updatePDConfig(mConfig);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
index dae690d89..48f20d048 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/IdServiceTest.java
@@ -17,21 +17,17 @@
package org.apache.hugegraph.pd.core;
-import java.io.File;
-
-import org.apache.commons.io.FileUtils;
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;
-public class IdServiceTest {
+public class IdServiceTest extends PDCoreTestBase {
+
@Test
public void testCid() {
try {
- PDConfig pdConfig = BaseServerTest.getConfig();
+ PDConfig pdConfig = getPdConfig();
int max = 0x2000;
IdService idService = new IdService(pdConfig);
for (int i = 0; i < max; i++) {
@@ -62,7 +58,7 @@ public class IdServiceTest {
Thread.sleep(5000);
long cid3 = idService.getCId("test", "name", max);
} catch (Exception e) {
-
+ e.printStackTrace();
}
// MetadataFactory.closeStore();
}
@@ -70,16 +66,7 @@ public class IdServiceTest {
@Test
public void testId() {
try {
- FileUtils.deleteQuietly(new File("tmp/testId/"));
- IdMetaStore.CID_DEL_TIMEOUT = 2000;
- PDConfig pdConfig = new PDConfig() {{
- this.setClusterId(100);
- this.setPatrolInterval(1);
- this.setRaft(new Raft() {{
- setEnable(false);
- }});
- this.setDataPath("tmp/testId/");
- }};
+ PDConfig pdConfig = getPdConfig();
IdService idService = new IdService(pdConfig);
long first = idService.getId("abc", 100);
Assert.assertEquals(first, 0L);
@@ -88,8 +75,8 @@ public class IdServiceTest {
idService.resetId("abc");
first = idService.getId("abc", 100);
Assert.assertEquals(first, 0L);
- } catch (Exception ignored) {
-
+ } catch (Exception e) {
+ e.printStackTrace();
}
// MetadataFactory.closeStore();
}
@@ -97,7 +84,7 @@ public class IdServiceTest {
@Test
public void testMember() {
try {
- PDConfig pdConfig = BaseServerTest.getConfig();
+ PDConfig pdConfig = getPdConfig();
IdService idService = new IdService(pdConfig);
idService.setPdConfig(pdConfig);
PDConfig config = idService.getPdConfig();
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
index 8b8175013..80cf6a2d2 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/KvServiceTest.java
@@ -19,16 +19,15 @@ 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;
-public class KvServiceTest {
+public class KvServiceTest extends PDCoreTestBase {
@Test
public void testKv() {
try {
- PDConfig pdConfig = BaseServerTest.getConfig();
+ PDConfig pdConfig = getPdConfig();
KvService service = new KvService(pdConfig);
String key = "kvTest";
String kvTest = service.get(key);
@@ -43,17 +42,18 @@ public class KvServiceTest {
service.put(key, "kvTestValue", 1000L);
service.keepAlive(key);
} catch (Exception e) {
-
+ e.printStackTrace();
}
}
@Test
public void testMember() {
try {
- PDConfig pdConfig = BaseServerTest.getConfig();
+ PDConfig pdConfig = getPdConfig();
KvService service = new KvService(pdConfig);
service.setPdConfig(pdConfig);
PDConfig config = service.getPdConfig();
+ // TODO
} catch (Exception e) {
e.printStackTrace();
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
index ad6c7bfbb..9588d6d17 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/LogServiceTest.java
@@ -20,34 +20,29 @@ 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;
import com.google.protobuf.Any;
-public class LogServiceTest {
-
- private final PDConfig mockPdConfig = BaseServerTest.getConfig();
+public class LogServiceTest extends PDCoreTestBase {
private LogService logServiceUnderTest;
@Before
public void setUp() {
- this.logServiceUnderTest = new LogService(this.mockPdConfig);
+ this.logServiceUnderTest = new LogService(getPdConfig());
}
@Test
public void testGetLog() throws Exception {
- this.logServiceUnderTest.insertLog("action", "message",
- Any.newBuilder().build());
+ this.logServiceUnderTest.insertLog("action", "message", Any.newBuilder().build());
// Run the test
- final List<Metapb.LogRecord> result = this.logServiceUnderTest.getLog(
- "action", 0L, System.currentTimeMillis());
+ final List<Metapb.LogRecord> result =
+ this.logServiceUnderTest.getLog("action", 0L, System.currentTimeMillis());
// Verify the results
Assert.assertEquals(result.size(), 1);
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
deleted file mode 100644
index 546d288f2..000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/MonitorServiceTest.java
+++ /dev/null
@@ -1,122 +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 java.util.concurrent.ExecutionException;
-
-import org.apache.hugegraph.pd.PartitionService;
-import org.apache.hugegraph.pd.StoreNodeService;
-import org.apache.hugegraph.pd.TaskScheduleService;
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.config.PDConfig;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-public class MonitorServiceTest {
- static PDConfig pdConfig;
-
- @BeforeClass
- 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() {{
- // this.setAddress("http://localhost:2379");
- //
- //}});
- pdConfig.setStore(new PDConfig().new Store() {{
- this.setMaxDownTime(1);
- this.setKeepAliveTimeout(5);
- }});
-
- pdConfig.setPartition(new PDConfig().new Partition() {{
- this.setShardCount(3);
- this.setTotalCount(10);
- }});
-
- pdConfig.setRaft(new PDConfig().new Raft() {{
- this.setEnable(false);
- }});
-
- clearClusterData();
- }
-
- public static void clearClusterData() throws ExecutionException, InterruptedException {
- //Client client = Client.builder().endpoints(pdConfig.getEtcd().getAddress()).build();
- //KV kvClient = client.getKVClient();
- //
- //ByteSequence key = ByteSequence.from("HUGEGRAPH/" + pdConfig.getClusterId(), Charset
- // .forName("utf-8"));
- //CompletableFuture<DeleteResponse> rsp = kvClient.delete(key, DeleteOption.newBuilder()
- // .isPrefix(true).build());
- //System.out.println("删除数量 : " + rsp.get().getDeleted());
- //kvClient.close();
- //client.close();
- }
-
- @Ignore
- @Test
- public void testPatrolStores() throws PDException, InterruptedException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
- TaskScheduleService monitorService =
- new TaskScheduleService(pdConfig, storeService, partitionService);
- storeService.init(partitionService);
- partitionService.init();
- monitorService.init();
-
- 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()));
- }
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
-
- .setPartitionCount(10)
- .build();
- partitionService.updateGraph(graph);
- Thread.sleep(10000);
- count = 0;
- count += storeService.getStores("").stream()
- .filter(store -> store.getState() == Metapb.StoreState.Tombstone)
- .count();
-
- Assert.assertEquals(6, count);
-
- }
-
-
-}
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 71a8d972a..87766e811 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
@@ -24,7 +24,6 @@ import org.junit.runners.Suite;
import lombok.extern.slf4j.Slf4j;
-
@RunWith(Suite.class)
@Suite.SuiteClasses({
MetadataKeyHelperTest.class,
@@ -33,11 +32,8 @@ import lombok.extern.slf4j.Slf4j;
IdServiceTest.class,
KvServiceTest.class,
LogServiceTest.class,
- MonitorServiceTest.class,
PartitionServiceTest.class,
StoreMonitorDataServiceTest.class,
- StoreNodeServiceNewTest.class,
- StoreNodeServiceTest.class,
StoreServiceTest.class,
TaskScheduleServiceTest.class
})
@@ -45,5 +41,4 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PDCoreSuiteTest {
-
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
index 244fe2e9b..ff16b1caa 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreTestBase.java
@@ -19,6 +19,7 @@ package org.apache.hugegraph.pd.core;
import java.io.File;
+import org.apache.commons.io.FileUtils;
import org.apache.hugegraph.pd.ConfigService;
import org.apache.hugegraph.pd.IdService;
import org.apache.hugegraph.pd.PartitionInstructionListener;
@@ -43,6 +44,7 @@ import org.junit.AfterClass;
import org.junit.BeforeClass;
public class PDCoreTestBase {
+
private static final String DATA_PATH = "/tmp/pd_data";
private static PDConfig pdConfig;
private static StoreNodeService storeNodeService;
@@ -61,6 +63,7 @@ public class PDCoreTestBase {
config.setHost("127.0.0.1");
config.setVerifyPath("");
config.setLicensePath("");
+
PDConfig.Raft raft = new PDConfig().new Raft();
raft.setAddress("127.0.0.1:8601");
raft.setPeersList("127.0.0.1:8601");
@@ -70,7 +73,6 @@ public class PDCoreTestBase {
raft.setPort(8621);
config.setRaft(raft);
-
config.setStore(new PDConfig().new Store());
config.setPartition(new PDConfig().new Partition() {{
setShardCount(1);
@@ -97,7 +99,6 @@ public class PDCoreTestBase {
RaftEngine.getInstance().addStateListener(partitionService);
pdConfig.setIdService(idService);
-
storeNodeService.init(partitionService);
partitionService.init();
partitionService.addInstructionListener(new PartitionInstructionListener() {
@@ -216,4 +217,16 @@ public class PDCoreTestBase {
public static StoreMonitorDataService getStoreMonitorDataService() {
return storeMonitorDataService;
}
+
+ public static PDConfig getConfig() {
+ FileUtils.deleteQuietly(new File(DATA_PATH));
+ return new PDConfig() {{
+ this.setClusterId(100);
+ this.setPatrolInterval(1);
+ this.setRaft(new Raft() {{
+ setEnable(false);
+ }});
+ this.setDataPath(DATA_PATH);
+ }};
+ }
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
index 47815318a..0e4e25461 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PartitionServiceTest.java
@@ -44,7 +44,11 @@ public class PartitionServiceTest extends PDCoreTestBase {
@Test
public void testCombinePartition() throws PDException {
buildEnv();
- // 0, 1, 2-> 0, 3,4,5->1, 6,7,8 ->2, 9,10, 11-> 3
+
+ // 0, 1, 2 -> 0
+ // 3, 4, 5 -> 1
+ // 6, 7, 8 -> 2
+ // 9, 10, 11 -> 3
this.service.combinePartition(4);
var partition = this.service.getPartitionById("graph0", 0);
@@ -66,7 +70,11 @@ public class PartitionServiceTest extends PDCoreTestBase {
@Test
public void testCombinePartition2() throws PDException {
buildEnv();
- // 0, 1, 2-> 0, 3,4,5->1, 6,7,8 ->2, 9,10, 11-> 3
+
+ // 0, 1, 2 -> 0
+ // 3, 4, 5 -> 1
+ // 6, 7, 8 -> 2
+ // 9, 10, 11 -> 3
this.service.combinePartition(4);
var partition = this.service.getPartitionById("graph0", 0);
@@ -144,10 +152,6 @@ public class PartitionServiceTest extends PDCoreTestBase {
.addAllShard(shardList).build();
List<Metapb.Shard> shardList2 = new ArrayList<>(stats.getShardList());
Collections.shuffle(shardList2);
- shardList2.forEach(shard -> {
- System.out.println(shard.getStoreId());
- });
-
-
+ shardList2.forEach(shard -> System.out.println(shard.getStoreId()));
}
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
index 8b17a38eb..9caf9eaae 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreMonitorDataServiceTest.java
@@ -31,7 +31,7 @@ import org.junit.Test;
public class StoreMonitorDataServiceTest extends PDCoreTestBase {
- StoreMonitorDataService service;
+ private StoreMonitorDataService service;
@Before
public void init() {
@@ -63,12 +63,10 @@ public class StoreMonitorDataServiceTest extends PDCoreTestBase {
assertNotNull(this.service.getStoreMonitorDataText(1));
-
this.service.removeExpiredMonitorData(1, now + 1);
assertEquals(0, this.service.getStoreMonitorData(1).size());
}
-
private Metapb.StoreStats genStats() {
return Metapb.StoreStats.newBuilder()
.setStoreId(1)
@@ -78,5 +76,4 @@ public class StoreMonitorDataServiceTest extends PDCoreTestBase {
.build();
}
-
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java
deleted file mode 100644
index 199a02e65..000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceNewTest.java
+++ /dev/null
@@ -1,64 +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.junit.Assert.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-import org.apache.hugegraph.pd.StoreNodeService;
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.junit.Before;
-import org.junit.Test;
-
-public class StoreNodeServiceNewTest extends PDCoreTestBase {
- private StoreNodeService service;
-
- @Before
- public void init() {
- this.service = getStoreNodeService();
- }
-
- @Test
- public void testGetTaskInfoMeta() {
- assertNotNull(this.service.getTaskInfoMeta());
- }
-
- public void testGetStoreInfoMeta() {
- assertNotNull(this.service.getStoreInfoMeta());
- }
-
- @Test
- public void testRemoveShardGroup() throws PDException {
- for (int i = 0; i < 12; i++) {
- Metapb.ShardGroup group = Metapb.ShardGroup.newBuilder()
- .setId(i)
- .setState(
- Metapb.PartitionState.PState_Offline)
- .build();
- this.service.getStoreInfoMeta().updateShardGroup(group);
- }
-
- this.service.deleteShardGroup(11);
- this.service.deleteShardGroup(10);
-
- assertEquals(10, getPdConfig().getConfigService().getPDConfig().getPartitionCount());
- // restore
- getPdConfig().getConfigService().setPartitionCount(12);
- }
-}
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
deleted file mode 100644
index 8180ab862..000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java
+++ /dev/null
@@ -1,479 +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 java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.hugegraph.pd.ConfigService;
-import org.apache.hugegraph.pd.PartitionInstructionListener;
-import org.apache.hugegraph.pd.PartitionService;
-import org.apache.hugegraph.pd.PartitionStatusListener;
-import org.apache.hugegraph.pd.StoreNodeService;
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.config.PDConfig;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.apache.hugegraph.pd.grpc.pulse.ChangeShard;
-import org.apache.hugegraph.pd.grpc.pulse.CleanPartition;
-import org.apache.hugegraph.pd.grpc.pulse.DbCompaction;
-import org.apache.hugegraph.pd.grpc.pulse.MovePartition;
-import org.apache.hugegraph.pd.grpc.pulse.PartitionKeyRange;
-import org.apache.hugegraph.pd.grpc.pulse.SplitPartition;
-import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-
-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());
- }
- }
-
- @Ignore
- @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++) {
- 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<Metapb.Shard> 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("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<Metapb.Shard> 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/core/StoreServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreServiceTest.java
index 73f8b6223..423999bd4 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
@@ -18,6 +18,7 @@
package org.apache.hugegraph.pd.core;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -25,20 +26,18 @@ import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
-import org.apache.hugegraph.pd.ConfigService;
-import org.apache.hugegraph.pd.IdService;
import org.apache.hugegraph.pd.PartitionService;
import org.apache.hugegraph.pd.StoreNodeService;
import org.apache.hugegraph.pd.StoreStatusListener;
+import org.apache.hugegraph.pd.common.PDException;
import org.apache.hugegraph.pd.config.PDConfig;
import org.apache.hugegraph.pd.grpc.MetaTask;
import org.apache.hugegraph.pd.grpc.Metapb;
-import org.apache.hugegraph.pd.rest.BaseServerTest;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
-public class StoreServiceTest {
+public class StoreServiceTest extends PDCoreTestBase {
private PDConfig config;
@@ -46,18 +45,17 @@ public class StoreServiceTest {
@Before
public void setUp() {
- this.config = getConfig();
+ this.config = getPdConfig();
this.service = new StoreNodeService(this.config);
}
@Test
public void testInit() {
// Setup
- PDConfig pdConfig = getConfig();
- final PDConfig pdConfig1 = getConfig();
+ PDConfig pdConfig = getPdConfig();
final PartitionService partitionService = new PartitionService(pdConfig,
new StoreNodeService(
- pdConfig1));
+ pdConfig));
// Run the test
this.service.init(partitionService);
@@ -65,30 +63,6 @@ public class StoreServiceTest {
// Verify the results
}
- private PDConfig getConfig() {
- PDConfig pdConfig = new PDConfig();
- pdConfig.setConfigService(
- new ConfigService(BaseServerTest.getConfig()));
- pdConfig.setIdService(new IdService(BaseServerTest.getConfig()));
- pdConfig.setClusterId(0L);
- pdConfig.setPatrolInterval(0L);
- pdConfig.setDataPath("dataPath");
- pdConfig.setMinStoreCount(0);
- pdConfig.setInitialStoreList("initialStoreList");
- pdConfig.setHost("host");
- pdConfig.setVerifyPath("verifyPath");
- pdConfig.setLicensePath("licensePath");
- PDConfig.Raft raft = new PDConfig().new Raft();
- raft.setEnable(false);
- pdConfig.setRaft(raft);
- final PDConfig.Partition partition = new PDConfig().new Partition();
- partition.setTotalCount(0);
- partition.setShardCount(0);
- pdConfig.setPartition(partition);
- pdConfig.setInitialStoreMap(Map.ofEntries(Map.entry("value", "value")));
- return pdConfig;
- }
-
@Test
public void testIsOK() {
// Setup
@@ -325,7 +299,6 @@ public class StoreServiceTest {
// Verify the results
}
-
@Test
public void testGetStores1() throws Exception {
// Setup
@@ -376,7 +349,6 @@ public class StoreServiceTest {
final List<Metapb.Store> result = this.service.getStores("graphName");
}
-
@Test
public void testGetStoreStatus() throws Exception {
// Setup
@@ -441,7 +413,6 @@ public class StoreServiceTest {
// Verify the results
}
-
@Test
public void testGetShardGroupsByStore() throws Exception {
// Setup
@@ -527,7 +498,6 @@ public class StoreServiceTest {
assertThat(stores.size() == 0);
}
-
@Test
public void testAllocShards() throws Exception {
// Setup
@@ -665,7 +635,6 @@ public class StoreServiceTest {
}
}
-
@Test
public void testUpdateClusterStatus1() {
// Setup
@@ -764,6 +733,7 @@ public class StoreServiceTest {
// Verify the results
}
+ @Ignore
@Test
public void testCheckStoreCanOffline() {
// Setup
@@ -834,4 +804,24 @@ public class StoreServiceTest {
}
}
+
+ // migrated from StoreNodeServiceNewTest
+ @Test
+ public void testRemoveShardGroup() throws PDException {
+ for (int i = 0; i < 12; i++) {
+ Metapb.ShardGroup group = Metapb.ShardGroup.newBuilder()
+ .setId(i)
+ .setState(
+ Metapb.PartitionState.PState_Offline)
+ .build();
+ this.service.getStoreInfoMeta().updateShardGroup(group);
+ }
+
+ this.service.deleteShardGroup(11);
+ this.service.deleteShardGroup(10);
+
+ assertEquals(10, getPdConfig().getConfigService().getPDConfig().getPartitionCount());
+ // restore
+ getPdConfig().getConfigService().setPartitionCount(12);
+ }
}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
index 4b70845ad..fbccb47a1 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/TaskScheduleServiceTest.java
@@ -17,7 +17,7 @@
package org.apache.hugegraph.pd.core;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
import java.util.ArrayList;
import java.util.List;
@@ -37,26 +37,28 @@ public class TaskScheduleServiceTest extends PDCoreTestBase {
this.service = getTaskService();
}
- @Test
+ // TODO
public void testStoreOffline() {
}
+ // TODO
public void testPatrolStores() {
}
+ // TODO
public void testPatrolPartitions() {
}
+ // TODO
public void testBalancePartitionShard() {
}
@Test
public void testBalancePartitionLeader() throws PDException {
-
var list = new ArrayList<Metapb.Partition>();
for (int i = 0; i < 6; i++) {
getStoreNodeService().getStoreInfoMeta().updateShardGroup(genShardGroup(i));
@@ -67,20 +69,23 @@ public class TaskScheduleServiceTest extends PDCoreTestBase {
getPartitionService().updatePartition(list);
var rst = this.service.balancePartitionLeader(true);
- assertTrue(rst.size() > 0);
+ assertFalse(rst.isEmpty());
// recover
getPdConfig().getPartition().setShardCount(1);
getStoreNodeService().getStoreInfoMeta().removeAll();
}
+ // TODO
public void testSplitPartition() {
}
+ // TODO
public void testSplitPartition2() {
}
+ // TODO
public void testCanAllPartitionsMovedOut() {
}
@@ -97,8 +102,8 @@ public class TaskScheduleServiceTest extends PDCoreTestBase {
.setId(groupId)
.setState(Metapb.PartitionState.PState_Normal)
.setGraphName("graph1")
- .setStartKey(groupId * 10)
- .setEndKey(groupId * 10 + 10)
+ .setStartKey(groupId * 10L)
+ .setEndKey(groupId * 10L + 10)
.build();
}
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 cfd5299ea..5e77b6a82 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
@@ -31,8 +31,9 @@ import org.junit.BeforeClass;
import org.junit.Test;
public class HgKVStoreImplTest {
- static final String testPath = "tmp/test";
- static PDConfig pdConfig;
+
+ private static final String testPath = "tmp/test";
+ private static PDConfig pdConfig;
@BeforeClass
public static void init() throws IOException {
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 44ffdf064..85334c16c 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
@@ -27,7 +27,6 @@ import lombok.extern.slf4j.Slf4j;
@RunWith(Suite.class)
@Suite.SuiteClasses({
})
-
@Slf4j
public class GrpcSuiteTest {
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
index 5c397e809..4aff85d1e 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/BaseServerTest.java
@@ -17,18 +17,15 @@
package org.apache.hugegraph.pd.rest;
-import java.io.File;
import java.net.http.HttpClient;
-import org.apache.commons.io.FileUtils;
-import org.apache.hugegraph.pd.config.PDConfig;
import org.junit.After;
import org.junit.BeforeClass;
-
public class BaseServerTest {
- public static HttpClient client;
- public static String pdRestAddr;
+
+ protected static HttpClient client;
+ protected static String pdRestAddr;
@BeforeClass
public static void init() {
@@ -36,19 +33,6 @@ public class BaseServerTest {
pdRestAddr = "http://127.0.0.1:8620";
}
- public static PDConfig getConfig() {
- FileUtils.deleteQuietly(new File("tmp/test/"));
- PDConfig pdConfig = new PDConfig() {{
- this.setClusterId(100);
- this.setPatrolInterval(1);
- this.setRaft(new Raft() {{
- setEnable(false);
- }});
- this.setDataPath("tmp/test/");
- }};
- return pdConfig;
- }
-
@After
public void teardown() {
// pass
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 d16d21208..f804290d5 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
@@ -26,7 +26,6 @@ import lombok.extern.slf4j.Slf4j;
@Suite.SuiteClasses({
RestApiTest.class,
})
-
@Slf4j
public class PDRestSuiteTest {
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
index b3165ab30..813d7f065 100644
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
+++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/rest/RestApiTest.java
@@ -28,6 +28,7 @@ import org.json.JSONObject;
import org.junit.Test;
public class RestApiTest extends BaseServerTest {
+
@Test
public void testQueryClusterInfo() throws URISyntaxException, IOException, InterruptedException,
JSONException {