diff --git a/.github/workflows/pd-store.yml b/.github/workflows/pd-store.yml
new file mode 100644
index 0000000000..65fb3ccc9c
--- /dev/null
+++ b/.github/workflows/pd-store.yml
@@ -0,0 +1,51 @@
+name: "pd-store"
+
+on:
+ push:
+ branches:
+ - master
+ - 'release-*'
+ - 'test-*'
+ pull_request:
+
+jobs:
+ pd:
+ runs-on: ubuntu-latest
+ env:
+ USE_STAGE: 'true' # Whether to include the stage repository.
+ TRAVIS_DIR: hugegraph-server/hugegraph-dist/src/assembly/travis
+ REPORT_DIR: target/site/jacoco
+
+ steps:
+ - name: Install JDK 11
+ uses: actions/setup-java@v3
+ with:
+ java-version: '11'
+ distribution: 'zulu'
+
+ - name: Cache Maven packages
+ uses: actions/cache@v3
+ with:
+ path: ~/.m2
+ key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
+ restore-keys: ${{ runner.os }}-m2
+
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ fetch-depth: 2
+
+ - name: use staged maven repo settings
+ if: ${{ env.USE_STAGE == 'true' }}
+ run: |
+ cp $HOME/.m2/settings.xml /tmp/settings.xml
+ mv -vf .github/configs/settings.xml $HOME/.m2/settings.xml
+
+ - name: Run common test
+ run: |
+ mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test
+
+ - name: Upload coverage to Codecov
+ uses: codecov/codecov-action@v3.0.0
+ with:
+ file: ${{ env.REPORT_DIR }}/*.xml
diff --git a/hugegraph-pd/hg-pd-test/pom.xml b/hugegraph-pd/hg-pd-test/pom.xml
index 19e1855d8c..31c0fd889d 100644
--- a/hugegraph-pd/hg-pd-test/pom.xml
+++ b/hugegraph-pd/hg-pd-test/pom.xml
@@ -96,7 +96,7 @@
org.apache.hugegraph
- hg-pd-client
+ hg-pd-common
${revision}
@@ -105,11 +105,6 @@
gson
2.8.9
-
- org.apache.hugegraph
- hg-pd-grpc
- ${revision}
-
commons-io
commons-io
@@ -131,28 +126,6 @@
2.13.0
-
-
-
org.springframework.boot
spring-boot-starter-test
@@ -164,46 +137,6 @@
-
- org.apache.hugegraph
- hg-pd-clitools
- ${revision}
-
-
- org.apache.hugegraph
- hg-pd-common
- ${revision}
-
-
-
- org.apache.hugegraph
- hg-pd-core
- ${revision}
-
-
- org.apache.hugegraph
- hg-pd-dist
- ${revision}
- compile
-
-
- org.apache.hugegraph
- hg-pd-service
- ${revision}
-
-
-
org.powermock
@@ -223,19 +156,24 @@
org.powermock
powermock-module-junit4
- 2.0.0-RC.3
+ ${powermock.version}
compile
org.powermock
powermock-api-mockito2
- 2.0.0-RC.3
+ ${powermock.version}
compile
+
+ org.apache.commons
+ commons-lang3
+ 3.14.0
+ compile
+
-
@@ -243,42 +181,6 @@
maven-surefire-plugin
2.20
-
- pd-client-test
-
- ${basedir}/src/main/java/
-
- ${basedir}/target/classes/
-
-
- **/PDClientSuiteTest.java
-
-
-
-
- pd-core-test
-
- ${basedir}/src/main/java/
-
- ${basedir}/target/classes/
-
-
- **/PDCoreSuiteTest.java
-
-
-
-
- pd-cli-tools-test
-
- ${basedir}/src/main/java/
-
- ${basedir}/target/classes/
-
-
- **/CliToolsSuiteTest.java
-
-
-
pd-common-test
@@ -292,14 +194,14 @@
- pd-service-test
+ pd-client-test
${basedir}/src/main/java/
${basedir}/target/classes/
- **/ServerSuiteTest.java
+ **/PDClientSuiteTest.java
@@ -343,7 +245,6 @@
org/apache/hugegraph/pd/grpc/**/*.class
org/apache/hugegraph/pd/raft/*.class
**/RaftKVStore.class
-
@@ -355,5 +256,4 @@
-
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
deleted file mode 100644
index 25272127fd..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/MonitorServiceTest.java
+++ /dev/null
@@ -1,112 +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.concurrent.ExecutionException;
-
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.config.PDConfig;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
-// import org.junit.Test;
-
-public class MonitorServiceTest {
- static PDConfig pdConfig;
-
- @BeforeClass
- public static void init() throws ExecutionException, InterruptedException {
- pdConfig = new PDConfig() {{
- this.setClusterId(100);
- this.setPatrolInterval(1);
- }};
-
- //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);
- }});
-
- 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 rsp = kvClient.delete(key, DeleteOption.newBuilder()
- // .isPrefix(true).build());
- //System.out.println("删除数量 : " + rsp.get().getDeleted());
- //kvClient.close();
- //client.close();
- }
-
- // @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/PartitionCacheTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java
deleted file mode 100644
index 71efa70ecd..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionCacheTest.java
+++ /dev/null
@@ -1,102 +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.HashMap;
-import java.util.List;
-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 com.google.common.collect.Range;
-import com.google.common.collect.RangeMap;
-import com.google.common.collect.TreeRangeMap;
-
-public class PartitionCacheTest {
-
- // @Test
- public void test() {
- PartitionCache cache = new PartitionCache();
- for (int i = 0; i < 10; i++) {
- KVPair partShards =
- new KVPair<>(Metapb.Partition.newBuilder()
- .setStartKey(i * 10)
- .setEndKey((i + 1) * 10)
- .build(), null);
- cache.updatePartition("aa", i, partShards.getKey());
- }
-
- for (int i = 0; i < 100; i++) {
- KVPair partShards = cache.getPartitionByCode("aa", i);
- System.out.println(" " + i + " " + partShards.getKey().getStartKey());
- }
- }
-
-
- // @Test
- public void test1() {
- Map> keyToPartIdCache = new HashMap<>();
- // graphName + PartitionID组成key
- Map> partitionCache = new HashMap<>();
-
- // 缓存全部Store,用于全库查询,需要优化
- Map> allStoresCache = new HashMap<>();
-
- keyToPartIdCache.put("a", TreeRangeMap.create());
-
- keyToPartIdCache.get("a")
- .put(Range.closedOpen(1L, 2L), 1);
-
- allStoresCache.put("a", new ArrayList<>());
- allStoresCache.get("a").add(Metapb.Store.newBuilder().setId(34).build());
-
-
- Map> keyToPartIdCache2 =
- cloneKeyToPartIdCache(keyToPartIdCache);
- System.out.println(keyToPartIdCache2.size());
- }
-
- public Map> cloneKeyToPartIdCache(
- Map> cache) {
- Map> cacheClone = new HashMap<>();
- cache.forEach((k1, v1) -> {
- cacheClone.put(k1, TreeRangeMap.create());
- v1.asMapOfRanges().forEach((k2, v2) -> {
- cacheClone.get(k1).put(k2, v2);
- });
- });
- return cacheClone;
- }
-
- public Map>
- clonePartitionCache(Map> cache) {
- Map> cacheClone = new HashMap<>();
- cacheClone.putAll(cache);
- return cacheClone;
- }
-
- public Map>
- cloneStoreCache(Map> cache) {
- Map> cacheClone = new HashMap<>();
- cacheClone.putAll(cache);
- return cacheClone;
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java
deleted file mode 100644
index 82fd4c9bdb..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/PartitionServiceTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hugegraph.pd;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.junit.Test;
-
-public class PartitionServiceTest {
- @Test
- public void testPartitionHeartbeat() {
- List shardList = new ArrayList<>();
- shardList.add(Metapb.Shard.newBuilder().setStoreId(1).build());
- shardList.add(Metapb.Shard.newBuilder().setStoreId(2).build());
- shardList.add(Metapb.Shard.newBuilder().setStoreId(3).build());
- shardList = new ArrayList<>(shardList);
- Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
- .addAllShard(shardList).build();
- List shardList2 = new ArrayList<>(stats.getShardList());
- Collections.shuffle(shardList2);
- shardList2.forEach(shard -> {
- System.out.println(shard.getStoreId());
- });
-
-
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java
deleted file mode 100644
index c8f0ce39e5..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreNodeServiceTest.java
+++ /dev/null
@@ -1,485 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.hugegraph.pd;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.hugegraph.pd.common.PDException;
-import org.apache.hugegraph.pd.config.PDConfig;
-import org.apache.hugegraph.pd.grpc.Metapb;
-import org.apache.hugegraph.pd.grpc.pulse.ChangeShard;
-import org.apache.hugegraph.pd.grpc.pulse.CleanPartition;
-import org.apache.hugegraph.pd.grpc.pulse.DbCompaction;
-import org.apache.hugegraph.pd.grpc.pulse.MovePartition;
-import org.apache.hugegraph.pd.grpc.pulse.PartitionKeyRange;
-import org.apache.hugegraph.pd.grpc.pulse.SplitPartition;
-import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
-public class StoreNodeServiceTest {
- static PDConfig pdConfig;
-
- @BeforeClass
- public static void init() throws Exception {
- String path = "tmp/unitTest";
- deleteDirectory(new File(path));
- pdConfig = new PDConfig() {{
- this.setClusterId(100);
- this.setInitialStoreList(
- "127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502,127.0.0.1:8503,127.0.0.1:8504," +
- "127.0.0.1:8505");
- }};
-
- pdConfig.setStore(new PDConfig().new Store() {{
- this.setMaxDownTime(3600);
- this.setKeepAliveTimeout(3600);
- }});
-
- pdConfig.setPartition(new PDConfig().new Partition() {{
- this.setShardCount(3);
- this.setMaxShardsPerStore(3);
- }});
- pdConfig.setRaft(new PDConfig().new Raft() {{
- this.setEnable(false);
- }});
- pdConfig.setDiscovery(new PDConfig().new Discovery());
- pdConfig.setDataPath(path);
- ConfigService configService = new ConfigService(pdConfig);
- pdConfig = configService.loadConfig();
- }
-
- public static byte[] intToByteArray(int i) {
- byte[] result = new byte[4];
- result[0] = (byte) ((i >> 24) & 0xFF);
- result[1] = (byte) ((i >> 16) & 0xFF);
- result[2] = (byte) ((i >> 8) & 0xFF);
- result[3] = (byte) (i & 0xFF);
- return result;
- }
-
- public static void deleteDirectory(File dir) {
- try {
- FileUtils.deleteDirectory(dir);
- } catch (IOException e) {
- System.out.printf("Failed to start ....,%s%n", e.getMessage());
- }
- }
-
- // @Test
- public void testStoreNodeService() throws PDException {
- Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- (long) pdConfig.getInitialStoreMap().size() *
- pdConfig.getPartition().getMaxShardsPerStore()
- / pdConfig.getPartition().getShardCount());
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress("127.0.0.1:850" + i)
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + stores[i].getId());
- }
- Assert.assertEquals(count, storeService.getStores("").size());
-
- for (Metapb.Store store : stores) {
- Metapb.StoreStats stats = Metapb.StoreStats.newBuilder()
- .setStoreId(store.getId())
- .build();
- storeService.heartBeat(stats);
- }
-
- Assert.assertEquals(6, storeService.getActiveStores("").size());
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
- .setPartitionCount(10)
- .build();
- // 分配shard
- List shards = storeService.allocShards(graph, 1);
-
-
- Assert.assertEquals(3, shards.size());
-
- Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
- storeService.getShardGroups().size()); // 设置leader
- Metapb.Shard leader = Metapb.Shard.newBuilder(shards.get(0))
- .setRole(Metapb.ShardRole.Leader).build();
- shards = new ArrayList<>(shards);
- shards.set(0, leader);
- // 增加shard
- pdConfig.getPartition().setShardCount(5);
-
- Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder()
- .setId(1)
- .addAllShards(shards).build();
- shards = storeService.reallocShards(shardGroup);
-
- Assert.assertEquals(5, shards.size());
- // 减少shard
- pdConfig.getPartition().setShardCount(3);
- shards = storeService.reallocShards(shardGroup);
- Assert.assertEquals(3, shards.size());
- // 包含leader,leader不能被删除
- Assert.assertTrue(shards.contains(leader));
-
- // 减少shard
- pdConfig.getPartition().setShardCount(1);
- graph = Metapb.Graph.newBuilder(graph).build();
- shards = storeService.reallocShards(shardGroup);
- Assert.assertEquals(1, shards.size());
- // 包含leader,leader不能被删除
- Assert.assertTrue(shards.contains(leader));
-
- for (Metapb.Store store : stores) {
- storeService.removeStore(store.getId());
- }
- Assert.assertEquals(0, storeService.getStores("").size());
-
-
- }
-
- // @Test
- public void testSplitPartition() throws PDException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- storeService.init(partitionService);
- partitionService.addInstructionListener(new PartitionInstructionListener() {
-
- @Override
- public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
- PDException {
-
- }
-
- @Override
- public void transferLeader(Metapb.Partition partition,
- TransferLeader transferLeader) throws PDException {
-
- }
-
- @Override
- public void splitPartition(Metapb.Partition partition,
- SplitPartition splitPartition) throws PDException {
- splitPartition.getNewPartitionList().forEach(p -> {
- System.out.println("SplitPartition " + p.getId() + " " + p.getStartKey() + "," +
- p.getEndKey());
- });
- }
-
- @Override
- public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
- PDException {
-
- }
-
- @Override
- public void movePartition(Metapb.Partition partition,
- MovePartition movePartition) throws PDException {
-
- }
-
- @Override
- public void cleanPartition(Metapb.Partition partition,
- CleanPartition cleanPartition) throws PDException {
-
- }
-
- @Override
- public void changePartitionKeyRange(Metapb.Partition partition,
- PartitionKeyRange partitionKeyRange) throws
- PDException {
-
- }
- });
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress("127.0.0.1:850" + i)
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
- }
- Assert.assertEquals(count, storeService.getStores().size());
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
- .build();
- Metapb.PartitionShard ptShard =
- partitionService.getPartitionByCode(graph.getGraphName(), 0);
- System.out.println(ptShard.getPartition().getId());
- {
- Metapb.Partition pt = ptShard.getPartition();
- System.out.println(pt.getId() + " " + pt.getStartKey() + "," + pt.getEndKey());
- }
-
- Assert.assertEquals(6, storeService.getShardGroups().size());
- // storeService.splitShardGroups(ptShard.getPartition().getId(), 4);
- Assert.assertEquals(9, storeService.getShardGroups().size());
- storeService.getShardGroups().forEach(shardGroup -> {
- System.out.println("shardGroup id = " + shardGroup.getId());
- });
- }
-
- // @Test
- public void testPartitionService() throws PDException, ExecutionException,
- InterruptedException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- int count = 6;
- Metapb.Store[] stores = new Metapb.Store[count];
- for (int i = 0; i < count; i++) {
- Metapb.Store store = Metapb.Store.newBuilder()
- .setId(0)
- .setAddress(String.valueOf(i))
- .setDeployPath("/data")
- .addLabels(Metapb.StoreLabel.newBuilder()
- .setKey("namespace")
- .setValue("default")
- .build())
- .build();
- stores[i] = storeService.register(store);
- System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
- }
- Assert.assertEquals(count, storeService.getStores("").size());
-
-
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- Metapb.Graph graph = Metapb.Graph.newBuilder()
- .setGraphName("defaultGH")
-
- .setPartitionCount(10)
- .build();
- // 申请分区
- Metapb.PartitionShard[] partitions = new Metapb.PartitionShard[10];
- for (int i = 0; i < partitions.length; i++) {
- partitions[i] =
- partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
- Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
- }
- System.out.println(
- "分区数量: " + partitionService.getPartitions(graph.getGraphName()).size());
-
- int[] caseNo = {0}; //1 测试增加shard, 2 //测试store下线
-
- Metapb.Shard leader = null;
- int[] finalCaseNo = caseNo;
-
- partitionService.addInstructionListener(new PartitionInstructionListener() {
-
- @Override
- public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
- PDException {
- switch (finalCaseNo[0]) {
- case 2:
- Assert.assertEquals(5, storeService.getShardGroup(partition.getId())
- .getShardsCount());
- break;
- case 3:
- storeService.getShardGroup(partition.getId()).getShardsList()
- .forEach(shard -> {
- Assert.assertNotEquals(shard.getStoreId(),
- stores[0].getId());
- });
- break;
- }
-
- }
-
- @Override
- public void transferLeader(Metapb.Partition partition, TransferLeader transferLeader) {
-
- }
-
- @Override
- public void splitPartition(Metapb.Partition partition, SplitPartition splitPartition) {
- }
-
- @Override
- public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
- PDException {
-
- }
-
- @Override
- public void movePartition(Metapb.Partition partition,
- MovePartition movePartition) throws PDException {
-
- }
-
- @Override
- public void cleanPartition(Metapb.Partition partition,
- CleanPartition cleanPartition) throws PDException {
-
- }
-
- @Override
- public void changePartitionKeyRange(Metapb.Partition partition,
- PartitionKeyRange partitionKeyRange)
- throws PDException {
-
- }
- });
- Metapb.Partition partition = partitions[0].getPartition();
- leader = Metapb.Shard.newBuilder(
- storeService.getShardGroup(partition.getId()).getShardsList().get(0)).build();
- Metapb.Shard finalLeader = leader;
- partitionService.addStatusListener(new PartitionStatusListener() {
- @Override
- public void onPartitionChanged(Metapb.Partition partition,
- Metapb.Partition newPartition) {
-
- }
-
- @Override
- public void onPartitionRemoved(Metapb.Partition partition) {
-
- }
- });
- // 测试修改图
- caseNo[0] = 1;
- partitionService.updateGraph(graph);
- for (int i = 0; i < partitions.length; i++) {
- partitions[i] =
- partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
- Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
- }
-
- graph = Metapb.Graph.newBuilder(graph)
- .setGraphName("defaultGH")
-
- .setPartitionCount(10)
- .build();
- caseNo[0] = 2;
- partitionService.updateGraph(graph);
-
- // 测试store离线
- caseNo[0] = 3;
- partitionService.storeOffline(stores[0]);
-
-
- Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
- .addGraphName(partition.getGraphName())
- .setId(partition.getId())
- .setLeader(
- Metapb.Shard.newBuilder(leader)
- .setRole(
- Metapb.ShardRole.Leader))
- .build();
- // 测试leader飘移
- caseNo[0] = 4;
- partitionService.partitionHeartbeat(stats);
- AtomicReference shard = new AtomicReference<>();
- Metapb.PartitionShard ss =
- partitionService.getPartitionShardById(partition.getGraphName(), partition.getId());
- storeService.getShardList(partition.getId()).forEach(s -> {
- if (s.getRole() == Metapb.ShardRole.Leader) {
- Assert.assertNull(shard.get());
- shard.set(s);
- }
- });
-
- Assert.assertEquals(leader.getStoreId(), shard.get().getStoreId());
-
- }
-
- // @Test
- public void testMergeGraphParams() throws PDException {
- StoreNodeService storeService = new StoreNodeService(pdConfig);
- PartitionService partitionService = new PartitionService(pdConfig, storeService);
-
- Metapb.Graph dfGraph = Metapb.Graph.newBuilder()
-
- .setPartitionCount(
- pdConfig.getPartition().getTotalCount())
-
- .build();
-
- Metapb.Graph graph1 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .setPartitionCount(20)
-
- .build();
-
- Metapb.Graph graph2 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .setPartitionCount(7).build();
- Metapb.Graph graph3 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .build();
- Metapb.Graph graph4 = Metapb.Graph.newBuilder()
- .setGraphName("test")
- .build();
-
- Metapb.Graph graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph2).build();
- Assert.assertEquals(graph2.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(graph2.getPartitionCount(), graph.getPartitionCount());
-
-
- graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph3).build();
- Assert.assertEquals(graph3.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
-
-
- graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph4).build();
- Assert.assertEquals(graph4.getGraphName(), graph.getGraphName());
-
- Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
-
- }
-
- // @Test
- public void test() {
- int[] n = new int[3];
-
-
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- if (++n[2] > 1) {
- System.out.println(n[2]);
- }
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java
deleted file mode 100644
index 48877273fc..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/StoreRegisterTest.java
+++ /dev/null
@@ -1,135 +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.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;
-import org.apache.hugegraph.pd.grpc.pulse.PartitionHeartbeatRequest;
-import org.apache.hugegraph.pd.grpc.pulse.PulseResponse;
-import org.apache.hugegraph.pd.pulse.PulseServerNotice;
-import org.junit.Assert;
-import org.junit.BeforeClass;
-
-public class StoreRegisterTest {
- private static PDClient pdClient;
- private final String storeAddr = "localhost";
- private final String graphName = "default/hugegraph/g";
- private long storeId = 0;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- PDConfig config = PDConfig.of("localhost:8686");
- config.setEnableCache(true);
- pdClient = PDClient.create(config);
- }
-
- // @Test
- public void testRegisterStore() throws PDException {
- Metapb.Store store = Metapb.Store.newBuilder().setAddress(storeAddr).build();
- try {
- storeId = pdClient.registerStore(store);
- } catch (Exception e) {
- e.printStackTrace();
- }
- Assert.assertTrue("RegisterStore store_id = " + storeId, storeId != 0);
- }
-
- // @Test
- public void testGetStore() throws PDException {
- testRegisterStore();
- Metapb.Store store = pdClient.getStore(storeId);
- Assert.assertEquals(storeAddr, store.getAddress());
- System.out.println(store);
- }
-
- // @Test
- public void testGetActiveStores() throws PDException {
- testRegisterStore();
- List stores = pdClient.getActiveStores(graphName);
- stores.forEach((e) -> {
- System.out.println("-------------------------------------");
- System.out.println(e);
- });
- }
-
-
- // @Test
- public void testStoreHeartbeat() throws PDException {
- testRegisterStore();
- Metapb.StoreStats stats = Metapb.StoreStats.newBuilder().setStoreId(storeId).build();
- pdClient.storeHeartbeat(stats);
- List stores = pdClient.getActiveStores(graphName);
- boolean exist = false;
- for (Metapb.Store store : stores) {
- if (store.getId() == storeId) {
- exist = true;
- break;
- }
- }
- Assert.assertTrue(exist);
- }
-
-
- // @Test
- public void testPartitionHeartbeat() throws InterruptedException, PDException {
- testRegisterStore();
- PDPulse pdPulse = new PDPulseImpl(pdClient.getLeaderIp());
-
- PDPulse.Notifier notifier = pdPulse.connectPartition(
- new PDPulse.Listener() {
-
- @Override
- public void onNext(PulseResponse response) {
-
- }
-
- @Override
- public void onNotice(PulseServerNotice notice) {
-
- }
-
- @Override
- public void onError(Throwable throwable) {
-
- }
-
- @Override
- public void onCompleted() {
-
- }
- });
- KVPair partShard =
- pdClient.getPartition("test", "1".getBytes(StandardCharsets.UTF_8));
- notifier.notifyServer(PartitionHeartbeatRequest.newBuilder().setStates(
- Metapb.PartitionStats.newBuilder().addGraphName("test")
- .setId(partShard.getKey().getId())
- .setLeader(Metapb.Shard.newBuilder().setStoreId(1).build())));
-
-
- Thread.sleep(10000);
- }
-
-}
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();
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/BaseClientTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/BaseClientTest.java
deleted file mode 100644
index 3fca39ade9..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/BaseClientTest.java
+++ /dev/null
@@ -1,44 +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.client;
-
-import org.junit.After;
-import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.mockito.runners.MockitoJUnitRunner;
-
-@RunWith(MockitoJUnitRunner.class)
-public class BaseClientTest {
- public static PDClient pdClient;
- public final String storeAddr = "localhost";
- public final String graphName = "default/hugegraph/g";
- public long storeId = 0;
-
- @BeforeClass
- public static void beforeClass() throws Exception {
- PDConfig config = PDConfig.of("localhost:8686");
-// PDConfig config = PDConfig.of("10.81.116.77:8986");
- config.setEnableCache(true);
- pdClient = PDClient.create(config);
- }
-
- @After
- public void teardown() throws Exception {
- // pass
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImplTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImplTest.java
deleted file mode 100644
index 6d42c5ea73..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientImplTest.java
+++ /dev/null
@@ -1,147 +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.client;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Vector;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.atomic.AtomicLong;
-
-import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
-import org.apache.hugegraph.pd.grpc.discovery.Query;
-import org.junit.Assert;
-
-public class DiscoveryClientImplTest {
-
- private static final AtomicLong label = new AtomicLong();
- String address = "localhost:80";
- int delay = 1000;
- int wait = delay * 3 + 500;
-
- // @Test
- public void registerStore() throws InterruptedException {
-
- HashMap labels = new HashMap<>();
-
- labels.put("metrics", "/actuator/prometheus");
- labels.put("target", "10.81.116.77:8520");
- labels.put("scheme", "http");
- labels.put("__relabeling", "http");
- labels.put("no_relabeling", "http");
- getClient("store", "address1", labels);
-
- labels.put("metrics", "/actuator/prometheus");
- labels.put("target", "10.81.116.78:8520");
- labels.put("scheme", "http");
- getClient("store", "address2", labels);
-
- labels.put("metrics", "/actuator/prometheus");
- labels.put("target", "10.81.116.79:8520");
- labels.put("scheme", "http");
- getClient("store", "address3", labels);
-
- labels.put("metrics", "/actuator/prometheus");
- labels.put("target", "10.81.116.78:8620");
- labels.put("scheme", "http");
- getClient("pd", "address1", labels);
-
- labels.put("metrics", "/graph/metrics");
- labels.put("target", "10.37.1.1:9200");
- labels.put("scheme", "https");
- getClient("hugegraph", "address1", labels);
- }
-
- // @Test
- public void testNodes() throws InterruptedException {
- String appName = "hugegraph";
- register(appName, address);
- }
-
- // @Test
- public void testMultiNode() throws InterruptedException {
- for (int i = 0; i < 2; i++) {
- register("app" + i, address + i);
- }
- }
-
- // @Test
- public void testParallelMultiNode() throws InterruptedException {
- CountDownLatch latch = new CountDownLatch(30);
- Vector exceptions = new Vector<>();
- for (int i = 0; i < 30; i++) {
- int finalI = i;
- new Thread(() -> {
- try {
- for (int j = 0; j < 3; j++) {
- register("app" + finalI, address + j);
- }
- } catch (Exception e) {
- exceptions.add(e);
- } finally {
- latch.countDown();
- }
- }).start();
- }
- latch.await();
- Assert.assertEquals(0, exceptions.size());
- }
-
- private void register(String appName, String address) throws InterruptedException {
-
- HashMap labels = new HashMap<>();
- String labelValue = String.valueOf(label.incrementAndGet());
- labels.put("address", labelValue);
- labels.put("address1", labelValue);
- Query query = Query.newBuilder().setAppName(
- appName).setVersion("0.13.0").putAllLabels(labels).build();
- DiscoveryClientImpl discoveryClient = getClient(appName, address, labels);
- Thread.sleep(10000);
- NodeInfos nodeInfos1 = discoveryClient.getNodeInfos(query);
- Assert.assertEquals(1, nodeInfos1.getInfoCount());
- DiscoveryClientImpl discoveryClient1 = getClient(appName, address + 0, labels);
- Thread.sleep(10000);
- Assert.assertEquals(2, discoveryClient.getNodeInfos(query).getInfoCount());
- Query query1 = Query.newBuilder().setAppName(
- appName).setVersion("0.12.0").putAllLabels(labels).build();
- Assert.assertEquals(0, discoveryClient.getNodeInfos(query1).getInfoCount());
- discoveryClient.cancelTask();
- discoveryClient1.cancelTask();
- Thread.sleep(wait);
- NodeInfos nodeInfos = discoveryClient.getNodeInfos(query);
- System.out.println(nodeInfos);
- Assert.assertEquals(0, nodeInfos.getInfoCount());
- discoveryClient.close();
- discoveryClient1.close();
- }
-
- private DiscoveryClientImpl getClient(String appName, String address, Map labels) {
- DiscoveryClientImpl discoveryClient = null;
- try {
- discoveryClient = DiscoveryClientImpl.newBuilder().setCenterAddress(
- "localhost:8687,localhost:8686,localhost:8688").setAddress(address).setAppName(
- appName).setDelay(delay).setVersion("0.13.0").setId(
- "0").setLabels(labels).build();
- discoveryClient.scheduleTask();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return discoveryClient;
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientTest.java
deleted file mode 100644
index 928f1dcba5..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/DiscoveryClientTest.java
+++ /dev/null
@@ -1,79 +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.client;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.function.Consumer;
-
-import org.apache.hugegraph.pd.client.DiscoveryClientImpl;
-import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
-import org.apache.hugegraph.pd.grpc.discovery.Query;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DiscoveryClientTest {
-
- private DiscoveryClientImpl client;
-
- @Before
- public void setUp() {
- this.client = getClient("appName", "localhost:8654", new HashMap());
- }
-
- @Test
- public void testGetRegisterNode() {
- // Setup
- try {
- Consumer result = this.client.getRegisterConsumer();
- final NodeInfo expectedResult = NodeInfo.newBuilder()
- .setAppName("appName")
- .build();
-
- Thread.sleep(3000);
- Query query = Query.newBuilder().setAppName("appName")
- .setVersion("0.13.0").build();
-
- // Run the test
- this.client.getNodeInfos(query);
- } catch (InterruptedException e) {
- e.printStackTrace();
- } finally {
- this.client.close();
- }
-
- }
-
- private DiscoveryClientImpl getClient(String appName, String address,
- Map labels) {
- DiscoveryClientImpl discoveryClient = null;
- try {
- discoveryClient = DiscoveryClientImpl.newBuilder().setCenterAddress(
- "localhost:8686").setAddress(address).setAppName(appName)
- .setDelay(2000)
- .setVersion("0.13.0")
- .setId("0").setLabels(labels)
- .build();
- discoveryClient.scheduleTask();
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- return discoveryClient;
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/KvClientTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/KvClientTest.java
deleted file mode 100644
index c61413b8cd..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/KvClientTest.java
+++ /dev/null
@@ -1,121 +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.client;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-import java.util.function.Consumer;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.hugegraph.pd.client.KvClient;
-import org.apache.hugegraph.pd.client.PDConfig;
-import org.apache.hugegraph.pd.grpc.kv.KResponse;
-import org.apache.hugegraph.pd.grpc.kv.ScanPrefixResponse;
-import org.apache.hugegraph.pd.grpc.kv.WatchEvent;
-import org.apache.hugegraph.pd.grpc.kv.WatchKv;
-import org.apache.hugegraph.pd.grpc.kv.WatchResponse;
-import org.apache.hugegraph.pd.grpc.kv.WatchState;
-import org.apache.hugegraph.pd.grpc.kv.WatchType;
-import org.junit.Before;
-import org.junit.Test;
-
-import io.grpc.stub.AbstractBlockingStub;
-import io.grpc.stub.AbstractStub;
-
-public class KvClientTest extends BaseClientTest {
-
- String key = "key";
- String value = "value";
- private KvClient client;
-
- @Before
- public void setUp() {
- this.client = new KvClient<>(PDConfig.of("localhost:8686"));
- }
-
- @Test
- public void testCreateStub() {
- // Setup
- // Run the test
- try {
- final AbstractStub result = this.client.createStub();
- } catch (Exception e) {
-
- }
-
-
- // Verify the results
- }
-
- @Test
- public void testCreateBlockingStub() {
- // Setup
- // Run the test
- try {
- final AbstractBlockingStub result = this.client.createBlockingStub();
- } catch (Exception e) {
-
- }
- }
-
- @Test
- public void testPutAndGet() throws Exception {
- // Run the test
- try {
- this.client.put(this.key, this.value);
- // Run the test
- KResponse result = this.client.get(this.key);
-
- // Verify the results
- assertThat(result.getValue()).isEqualTo(this.value);
- this.client.delete(this.key);
- result = this.client.get(this.key);
- assertThat(StringUtils.isEmpty(result.getValue()));
- this.client.deletePrefix(this.key);
- this.client.put(this.key + "1", this.value);
- this.client.put(this.key + "2", this.value);
- ScanPrefixResponse response = this.client.scanPrefix(this.key);
- assertThat(response.getKvsMap().size() == 2);
- this.client.putTTL(this.key + "3", this.value, 1000);
- this.client.keepTTLAlive(this.key + "3");
- final Consumer mockConsumer = mock(Consumer.class);
-
- // Run the test
- this.client.listen(this.key + "3", mockConsumer);
- this.client.listenPrefix(this.key + "4", mockConsumer);
- WatchResponse r = WatchResponse.newBuilder().addEvents(
- WatchEvent.newBuilder().setCurrent(
- WatchKv.newBuilder().setKey(this.key).setValue("value")
- .build()).setType(WatchType.Put).build())
- .setClientId(0L)
- .setState(WatchState.Starting)
- .build();
- this.client.getWatchList(r);
- this.client.getWatchMap(r);
- this.client.lock(this.key, 3000L);
- this.client.isLocked(this.key);
- this.client.unlock(this.key);
- this.client.lock(this.key, 3000L);
- this.client.keepAlive(this.key);
- this.client.close();
- } catch (Exception e) {
-
- }
- }
-}
diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/LicenseClientImplTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/LicenseClientImplTest.java
deleted file mode 100644
index 4ed11b9b21..0000000000
--- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/LicenseClientImplTest.java
+++ /dev/null
@@ -1,127 +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.client;
-
-import java.io.File;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import org.apache.commons.io.FileUtils;
-import org.apache.hugegraph.pd.grpc.Pdpb;
-import org.apache.hugegraph.pd.grpc.kv.KResponse;
-import org.apache.hugegraph.pd.grpc.kv.KvResponse;
-import org.yaml.snakeyaml.Yaml;
-
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-public class LicenseClientImplTest {
-
- // @Test
- public void putLicense() {
- PDConfig pdConfig = PDConfig.of("localhost:8686,localhost:8687,localhost:8688");
- //PDConfig pdConfig = PDConfig.of("localhost:8686");
- pdConfig.setEnableCache(true);
- try (LicenseClient c = new LicenseClient(pdConfig)) {
- File file = new File("../conf/hugegraph.license");
- byte[] bytes = FileUtils.readFileToByteArray(file);
- Pdpb.PutLicenseResponse putLicenseResponse = c.putLicense(bytes);
- Pdpb.Error error = putLicenseResponse.getHeader().getError();
- log.info(error.getMessage());
- assert error.getType().equals(Pdpb.ErrorType.OK);
- } catch (Exception e) {
- log.error("put license with error: ", e);
- }
- }
-
- // @Test
- public void getKv() {
- PDConfig pdConfig = PDConfig.of("10.157.12.36:8686");
- pdConfig.setEnableCache(true);
- try (KvClient c = new KvClient(pdConfig)) {
- KResponse kResponse = c.get("S:FS");
- Pdpb.Error error = kResponse.getHeader().getError();
- log.info(error.getMessage());
- assert error.getType().equals(Pdpb.ErrorType.OK);
- Properties ymlConfig = getYmlConfig(kResponse.getValue());
- Object property = ymlConfig.get("rocksdb.write_buffer_size");
- assert property.toString().equals("32000000");
- } catch (Exception e) {
- log.error("put license with error: ", e);
- }
- }
-
- // @Test
- public void putKv() {
- PDConfig pdConfig = PDConfig.of("127.0.0.1.70:8688");
- pdConfig.setEnableCache(true);
- try (KvClient c = new KvClient(pdConfig)) {
- long l = System.currentTimeMillis();
- KvResponse kvResponse = c.put("S:Timestamp", String.valueOf(l));
- Pdpb.Error error = kvResponse.getHeader().getError();
- log.info(error.getMessage());
- assert error.getType().equals(Pdpb.ErrorType.OK);
- } catch (Exception e) {
- log.error("put license with error: ", e);
- }
- }
-
- // @Test
- public void putKvLocal() {
- PDConfig pdConfig = PDConfig.of("localhost:8686");
- pdConfig.setEnableCache(true);
- try (KvClient c = new KvClient(pdConfig)) {
- long l = System.currentTimeMillis();
- KvResponse kvResponse = c.put("S:Timestamp", String.valueOf(l));
- Pdpb.Error error = kvResponse.getHeader().getError();
- log.info(error.getMessage());
- assert error.getType().equals(Pdpb.ErrorType.OK);
- } catch (Exception e) {
- log.error("put license with error: ", e);
- }
- }
-
- private Properties getYmlConfig(String yml) {
- Yaml yaml = new Yaml();
- Iterable