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 load = yaml.loadAll(yml); - Iterator iterator = load.iterator(); - Properties properties = new Properties(); - while (iterator.hasNext()) { - Map next = (Map) iterator.next(); - map2Properties(next, "", properties); - } - return properties; - } - - private void map2Properties(Map map, String prefix, Properties properties) { - - for (Map.Entry entry : map.entrySet()) { - String key = entry.getKey(); - String newPrefix = prefix == null || prefix.length() == 0 ? key : prefix + "." + key; - Object value = entry.getValue(); - if (!(value instanceof Map)) { - properties.put(newPrefix, value); - } else { - map2Properties((Map) value, newPrefix, properties); - } - - } - } - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientSuiteTest.java deleted file mode 100644 index a9d3ae1406..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientSuiteTest.java +++ /dev/null @@ -1,36 +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.runner.RunWith; -import org.junit.runners.Suite; - -import lombok.extern.slf4j.Slf4j; - - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - PDClientTest.class, - KvClientTest.class, - DiscoveryClientTest.class -}) - -@Slf4j -public class PDClientSuiteTest { - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java deleted file mode 100644 index 5d068c02f8..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDClientTest.java +++ /dev/null @@ -1,418 +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.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.List; - -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.grpc.MetaTask; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.apache.hugegraph.pd.grpc.Pdpb; -import org.junit.Test; -import org.mockito.Mockito; - -public class PDClientTest extends BaseClientTest { - @Test - public void testDbCompaction() { - System.out.println("testDbCompaction start"); - - try { - pdClient.dbCompaction(""); - pdClient.dbCompaction(); - } catch (PDException e) { - e.printStackTrace(); - } - - System.out.println("pdclienttest testDbCompaction end"); - } - - @Test - public void testRegisterStore() { - Metapb.Store store = Metapb.Store.newBuilder().build(); - try { - pdClient.registerStore(store); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testSetGraph() { - Metapb.Graph graph = Metapb.Graph.newBuilder().setGraphName("test").build(); - try { - pdClient.setGraph(graph); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetGraph() { - try { - pdClient.getGraph("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetStore() { - try { - pdClient.getStore(0L); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testUpdateStore() { - Metapb.Store store = Metapb.Store.newBuilder().build(); - try { - pdClient.updateStore(store); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetActiveStores() { - try { - pdClient.getActiveStores("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetAllStores() { - try { - pdClient.getAllStores("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - -// @Test -// public void testStoreHeartbeat(){ -// Metapb.StoreStats stats = Metapb.StoreStats.newBuilder().build(); -// try { -// pdClient.storeHeartbeat(stats); -// } catch (PDException e) { -// e.printStackTrace(); -// } -// } - - @Test - public void testKeyToCode() { - pdClient.keyToCode("test", "test".getBytes(StandardCharsets.UTF_8)); - } - - @Test - public void testScanPartitions() { - try { - pdClient.scanPartitions("test", "1".getBytes(StandardCharsets.UTF_8), - "9".getBytes(StandardCharsets.UTF_8)); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetPartitionsByStore() { - try { - pdClient.getPartitionsByStore(0L); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testQueryPartitions() { - try { - pdClient.queryPartitions(0L, 0); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetPartitions() { - try { - pdClient.getPartitions(0L, "test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testUpdatePartitionLeader() { - System.out.println("updatePartitionLeader start"); - - pdClient.updatePartitionLeader("aaa", 0, 0L); - } - - @Test - public void testInvalidPartitionCache() { - pdClient.invalidPartitionCache(); - } - - @Test - public void testInvalidStoreCache() { - pdClient.invalidStoreCache(0L); - } - - @Test - public void testUpdatePartitionCache() { - Metapb.Partition partition = Metapb.Partition.newBuilder().build(); - Metapb.Shard leader = Metapb.Shard.newBuilder().build(); - pdClient.updatePartitionCache(partition, leader); - } - - @Test - public void testGetIdByKey() { - try { - pdClient.getIdByKey("test", 1); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testResetIdByKey() { - try { - pdClient.resetIdByKey("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetGetLeader() { - try { - pdClient.getLeader(); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetMembers() { - try { - pdClient.getMembers(); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetClusterStats() { - try { - pdClient.getClusterStats(); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testAddEventListener() { - PDClient.PDEventListener listener = Mockito.mock(PDClient.PDEventListener.class); - pdClient.addEventListener(listener); - } - - @Test - public void testGetWatchClient() { - pdClient.getWatchClient(); - } - - @Test - public void testGetPulseClient() { - // pdClient.getPulseClient(); - } - - @Test - public void testGetStoreStatus() { - try { - pdClient.getStoreStatus(true); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetPartition() { - try { - pdClient.getPartition("test", "test".getBytes(StandardCharsets.UTF_8)); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testSetGraphSpace() { - try { - pdClient.setGraphSpace("test", 1L); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetGraphSpace() { - try { - pdClient.getGraphSpace("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testSetPDConfig() { - try { - pdClient.setPDConfig(0, "", 0, 0L); - } catch (PDException e) { - e.printStackTrace(); - } - Metapb.PDConfig pdConfig = Metapb.PDConfig.newBuilder().build(); - - try { - pdClient.setPDConfig(pdConfig); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testGetPDConfig() { - try { - pdClient.getPDConfig(0L); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testChangePeerList() { - try { - pdClient.changePeerList(""); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testSplitData() { - try { - Metapb.PDConfig config = pdClient.getPDConfig(); - pdClient.setPDConfig(config.toBuilder().setMaxShardsPerStore(12).build()); - System.out.println(pdClient.getPDConfig()); - - // 开始分区分裂 - pdClient.splitData(); - } catch (Exception e) { - e.printStackTrace(); - } - } - - @Test - public void testBalancePartition() { - try { - pdClient.balancePartition(); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testMovePartition() { - Pdpb.OperationMode mode = Pdpb.OperationMode.Auto; - List params = new ArrayList<>(1); - try { - pdClient.movePartition(mode, params); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testReportTask() { - MetaTask.Task task = MetaTask.Task.newBuilder().build(); - try { - pdClient.reportTask(task); - } catch (PDException e) { - e.printStackTrace(); - } - } - - - @Test - public void testBalanceLeaders() { - try { - pdClient.balanceLeaders(); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testDelStore() { - try { - pdClient.delStore(0L); - } catch (PDException e) { - e.printStackTrace(); - } - } - -// @Test -// public void testgetQuota() { -// try { -// pdClient.getQuota(); -// } catch (PDException e) { -// e.printStackTrace(); -// } -// } - - @Test - public void testUpdatePartition() { - List partitions = new ArrayList<>(1); - try { - pdClient.updatePartition(partitions); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testDelPartition() { - try { - pdClient.delPartition("test", 0); - } catch (PDException e) { - e.printStackTrace(); - } - } - - @Test - public void testdelGraph() { - try { - pdClient.delGraph("test"); - } catch (PDException e) { - e.printStackTrace(); - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDPulseTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDPulseTest.java deleted file mode 100644 index d27c4b5e11..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDPulseTest.java +++ /dev/null @@ -1,110 +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.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.hugegraph.pd.client.test.HgPDTestUtil; -import org.apache.hugegraph.pd.grpc.pulse.PartitionHeartbeatRequest; -import org.apache.hugegraph.pd.pulse.PulseServerNotice; -import org.junit.BeforeClass; -import org.junit.Test; - -public class PDPulseTest { - private static PDClient pdClient; - - private final long storeId = 0; - private final String storeAddress = "localhost"; - private final String graphName = "graph1"; - - @BeforeClass - public static void beforeClass() throws Exception { - PDConfig pdConfig = PDConfig.of("localhost:8686"); - pdConfig.setEnableCache(true); - pdClient = PDClient.create(pdConfig); - pdClient.getLeader(); - } - - @Test - public void listen() { - - PDPulse pulse = new PDPulseImpl(pdClient.getLeaderIp()); - CountDownLatch latch = new CountDownLatch(60); - - PDPulse.Notifier notifier1 = - pulse.connectPartition(new PulseListener(latch, "listener1")); - PDPulse.Notifier notifier2 = - pulse.connectPartition(new PulseListener(latch, "listener2")); - PDPulse.Notifier notifier3 = - pulse.connectPartition(new PulseListener(latch, "listener3")); - - try { - latch.await(120, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - PartitionHeartbeatRequest.Builder builder = PartitionHeartbeatRequest.newBuilder(); - - notifier1.notifyServer(builder); - - - notifier2.notifyServer(builder); - - notifier3.notifyServer(builder); - - notifier1.close(); - notifier2.close(); - notifier3.close(); - } - - - private class PulseListener implements PDPulse.Listener { - private final String listenerName; - CountDownLatch latch = new CountDownLatch(10); - - private PulseListener(CountDownLatch latch, String listenerName) { - this.latch = latch; - this.listenerName = listenerName; - } - - @Override - public void onNext(T response) { - // println(this.listenerName+" res: "+response); - // this.latch.countDown(); - } - - @Override - public void onNotice(PulseServerNotice notice) { - HgPDTestUtil.println(this.listenerName + " ---> res: " + notice.getContent()); - - notice.ack(); - this.latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - HgPDTestUtil.println(this.listenerName + " error: " + throwable.toString()); - } - - @Override - public void onCompleted() { - HgPDTestUtil.println(this.listenerName + " is completed"); - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDWatchTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDWatchTest.java deleted file mode 100644 index 180b725555..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/PDWatchTest.java +++ /dev/null @@ -1,86 +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.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import org.apache.hugegraph.pd.client.test.HgPDTestUtil; -import org.junit.BeforeClass; -import org.junit.Test; - -@Deprecated -public class PDWatchTest { - private static PDClient pdClient; - - private final long storeId = 0; - private final String storeAddr = "localhost"; - private final String graphName = "graph1"; - - @BeforeClass - public static void beforeClass() { - pdClient = PDClient.create(PDConfig.of("localhost:9000")); - } - - @Test - public void watch() { - PDWatch watch = pdClient.getWatchClient(); - CountDownLatch latch = new CountDownLatch(10); - - PDWatch.Watcher watcher1 = watch.watchPartition(new WatchListener<>(latch, "watcher1")); - PDWatch.Watcher watcher2 = watch.watchPartition(new WatchListener<>(latch, "watcher2")); - PDWatch.Watcher watcher3 = watch.watchPartition(new WatchListener<>(latch, "watcher3")); - - PDWatch.Watcher nodeWatcher1 = watch.watchNode(new WatchListener<>(latch, "nodeWatcher1")); - - try { - latch.await(15, TimeUnit.SECONDS); - } catch (InterruptedException e) { - e.printStackTrace(); - } - watcher1.close(); - watcher2.close(); - watcher3.close(); - } - - private class WatchListener implements PDWatch.Listener { - private final String watcherName; - CountDownLatch latch; - - private WatchListener(CountDownLatch latch, String watcherName) { - this.latch = latch; - this.watcherName = watcherName; - } - - @Override - public void onNext(T response) { - HgPDTestUtil.println(this.watcherName + " res: " + response); - this.latch.countDown(); - } - - @Override - public void onError(Throwable throwable) { - HgPDTestUtil.println(this.watcherName + " error: " + throwable.toString()); - } - - @Override - public void onCompleted() { - HgPDTestUtil.println(this.watcherName + " is completed"); - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/test/HgPDTestUtil.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/test/HgPDTestUtil.java deleted file mode 100644 index 2c581ea6ff..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/client/test/HgPDTestUtil.java +++ /dev/null @@ -1,92 +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.test; - -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.Iterator; -import java.util.List; - -public class HgPDTestUtil { - - public static void println(Object str) { - System.out.println(str); - } - - public static String toStr(byte[] b) { - if (b == null) return ""; - if (b.length == 0) return ""; - return new String(b, StandardCharsets.UTF_8); - } - - public static byte[] toBytes(String str) { - if (str == null) return null; - return str.getBytes(StandardCharsets.UTF_8); - } - - public static byte[] toBytes(long l) { - ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); - buffer.putLong(l); - return buffer.array(); - } - - private static byte[] toBytes(final int i) { - ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES); - buffer.putInt(i); - return buffer.array(); - } - - public static long toLong(byte[] bytes) { - ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); - buffer.put(bytes); - buffer.flip();//need flip - return buffer.getLong(); - } - - public static long toInt(byte[] bytes) { - ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES); - buffer.put(bytes); - buffer.flip();//need flip - return buffer.getInt(); - } - - public static String padLeftZeros(String str, int n) { - return String.format("%1$" + n + "s", str).replace(' ', '0'); - } - - public static String toSuffix(int num, int length) { - return "-" + padLeftZeros(String.valueOf(num), length); - } - - public static int amountOf(List list) { - if (list == null) { - return 0; - } - return list.size(); - } - - public static int amountOf(Iterator iterator) { - if (iterator == null) return 0; - int count = 0; - while (iterator.hasNext()) { - iterator.next(); - count++; - } - return count; - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/BaseCliToolsTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/BaseCliToolsTest.java deleted file mode 100644 index 146cffb139..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/BaseCliToolsTest.java +++ /dev/null @@ -1,34 +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.clitools; - -import org.junit.After; -import org.junit.BeforeClass; - - -public class BaseCliToolsTest { - @BeforeClass - public static void init() { - - } - - @After - public void teardown() { - // pass - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/CliToolsSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/CliToolsSuiteTest.java deleted file mode 100644 index abdcbea08f..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/CliToolsSuiteTest.java +++ /dev/null @@ -1,35 +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.clitools; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import lombok.extern.slf4j.Slf4j; - - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - MainTest.class -}) - -@Slf4j -public class CliToolsSuiteTest { - - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java deleted file mode 100644 index 526558ac95..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/clitools/MainTest.java +++ /dev/null @@ -1,89 +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.clitools; - -import java.util.Arrays; -import java.util.List; - -import org.apache.hugegraph.pd.clitools.Main; -import org.apache.hugegraph.pd.common.PDException; -import org.junit.Test; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class MainTest extends BaseCliToolsTest { - - - public static boolean test2sup(List arrays, int tail, int res) { - System.out.printf("%d %d%n", tail, res); - if (tail == 0) { - System.out.printf("a = %d %d%n", tail, res); - return false; - } else if (tail == 1) { - System.out.printf("b = %d %d%n", arrays.get(0), res); - return (arrays.get(0) == res); - } else if (tail == 2) { - System.out.printf("c = %d %d %d%n", arrays.get(0), arrays.get(1), res); - return (arrays.get(0) + arrays.get(1) == Math.abs(res)) || - (Math.abs(arrays.get(0) - arrays.get(1)) == Math.abs(res)); - } else { - return test2sup(arrays, tail - 1, res + arrays.get(tail - 1)) || - test2sup(arrays, tail - 1, res - arrays.get(tail - 1)); - } - } - - @Test - public void getConfig() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad"}); - } - - // @Test - public void setBatchTrue() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad= true "}); - } - - // @Test - public void setBatchFalse() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad=false"}); - } - - @Test - public void getConfig2() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "shardCount"}); - } - - // @Test - public void setShardCount1() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "shardCount=1"}); - } - - // @Test - public void setShardCount3() throws PDException { - Main.main(new String[]{"127.0.0.1:8686", "config", "shardCount=3"}); - } - - @Test - public void test2() { - Integer[] a = new Integer[]{1, 0, 3, 2}; - List aa = Arrays.asList(a); - System.out.printf(test2sup(aa, aa.size(), 0) ? "TRUE" : "FALSE"); - } - - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java index 6f676c6068..0395711caa 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/CommonSuiteTest.java @@ -17,8 +17,6 @@ package org.apache.hugegraph.pd.common; -import org.apache.hugegraph.pd.service.IdServiceTest; -import org.apache.hugegraph.pd.service.KvServiceTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -29,11 +27,8 @@ @Suite.SuiteClasses({ PartitionUtilsTest.class, PartitionCacheTest.class, - MetadataKeyHelperTest.class, - KvServiceTest.class, HgAssertTest.class, KVPairTest.class, - IdServiceTest.class }) @Slf4j diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java deleted file mode 100644 index ea239ed93c..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/MetadataKeyHelperTest.java +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.common; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.hugegraph.pd.grpc.Metapb; -import org.apache.hugegraph.pd.meta.MetadataKeyHelper; -import org.junit.Test; - -public class MetadataKeyHelperTest { - - @Test - public void testGetStoreInfoKey() { - assertThat(MetadataKeyHelper.getStoreInfoKey(0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetActiveStoreKey() { - assertThat(MetadataKeyHelper.getActiveStoreKey(0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetActiveStorePrefix() { - assertThat(MetadataKeyHelper.getActiveStorePrefix()).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetStorePrefix() { - assertThat(MetadataKeyHelper.getStorePrefix()).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetStoreStatusKey() { - assertThat(MetadataKeyHelper.getStoreStatusKey(0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetShardGroupKey() { - assertThat(MetadataKeyHelper.getShardGroupKey(0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetShardGroupPrefix() { - assertThat(MetadataKeyHelper.getShardGroupPrefix()).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetPartitionKey() { - assertThat(MetadataKeyHelper.getPartitionKey("graphName", 0)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetPartitionPrefix() { - assertThat(MetadataKeyHelper.getPartitionPrefix("graphName")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetShardKey() { - assertThat(MetadataKeyHelper.getShardKey(0L, 0)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetShardPrefix() { - assertThat(MetadataKeyHelper.getShardPrefix(0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetGraphKey() { - assertThat(MetadataKeyHelper.getGraphKey("graphName")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetGraphPrefix() { - assertThat(MetadataKeyHelper.getGraphPrefix()).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetPartitionStatusKey() { - assertThat(MetadataKeyHelper.getPartitionStatusKey("graphName", - 0)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetPartitionStatusPrefixKey() { - assertThat(MetadataKeyHelper.getPartitionStatusPrefixKey( - "graphName")).contains(MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetGraphSpaceKey() { - assertThat(MetadataKeyHelper.getGraphSpaceKey("graphSpace")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetPdConfigKey() { - assertThat(MetadataKeyHelper.getPdConfigKey("configKey")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetQueueItemPrefix() { - assertThat(MetadataKeyHelper.getQueueItemPrefix()).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetQueueItemKey() { - assertThat(MetadataKeyHelper.getQueueItemKey("itemId")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetSpitTaskKey() { - assertThat(MetadataKeyHelper.getSplitTaskKey("graphName", 0)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetSpitTaskPrefix() { - assertThat(MetadataKeyHelper.getSplitTaskPrefix("graph0")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetLogKey() { - // Setup - final Metapb.LogRecord record = Metapb.LogRecord.newBuilder() - .setAction("value") - .setTimestamp(0L) - .build(); - - // Run the test - final byte[] result = MetadataKeyHelper.getLogKey(record); - - // Verify the results - assertThat(result).contains(MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetLogKeyPrefix() { - assertThat(MetadataKeyHelper.getLogKeyPrefix("action", 0L)).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetKVPrefix() { - assertThat(MetadataKeyHelper.getKVPrefix("prefix", "key")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetKVTTLPrefix() { - assertThat(MetadataKeyHelper.getKVTTLPrefix("ttlPrefix", "prefix", - "key")).contains( - MetadataKeyHelper.getDelimiter()); - } - - @Test - public void testGetKVWatchKeyPrefix1() { - assertThat( - MetadataKeyHelper.getKVWatchKeyPrefix("key", "watchDelimiter", - 0L)).contains( - String.valueOf(MetadataKeyHelper.getDelimiter())); - } - - @Test - public void testGetKVWatchKeyPrefix2() { - assertThat(MetadataKeyHelper.getKVWatchKeyPrefix("key", - "watchDelimiter")).contains( - String.valueOf(MetadataKeyHelper.getDelimiter())); - } - - @Test - public void testGetDelimiter() { - assertThat(MetadataKeyHelper.getDelimiter()).isEqualTo('/'); - } - - @Test - public void testGetStringBuilderHelper() { - try { - MetadataKeyHelper.getStringBuilderHelper(); - } catch (Exception e) { - - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/PartitionCacheTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/PartitionCacheTest.java index d4126967f6..21e757ffa9 100644 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/PartitionCacheTest.java +++ b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/common/PartitionCacheTest.java @@ -157,7 +157,7 @@ public void testGetPartitions() { this.cache.updateShardGroup(creteShardGroup(1)); this.cache.updatePartition(partition2); assertEquals(this.cache.getPartitions("graph0").size(), 2); - System.out.print(this.cache.debugCacheByGraphName("graph0")); + System.out.println(this.cache.debugCacheByGraphName("graph0")); } @Test @@ -168,14 +168,14 @@ public void testAddPartition() { assertNotNull(ret); assertEquals(ret.getKey(), partition); assertNotNull(this.cache.getPartitionByCode("graph0", 2000)); - System.out.print(this.cache.debugCacheByGraphName("graph0")); + System.out.println(this.cache.debugCacheByGraphName("graph0")); var partition2 = createPartition(0, "graph0", 0, 1024); this.cache.addPartition("graph0", 0, partition2); ret = this.cache.getPartitionById("graph0", 0); assertNotNull(ret); assertEquals(ret.getKey(), partition2); assertNull(this.cache.getPartitionByCode("graph0", 2000)); - System.out.print(this.cache.debugCacheByGraphName("graph0")); + System.out.println(this.cache.debugCacheByGraphName("graph0")); } @Test @@ -211,7 +211,7 @@ public void testRemovePartition() { assertNotNull(this.cache.getPartitionById("graph0", 0)); this.cache.removePartition("graph0", 0); assertNull(this.cache.getPartitionById("graph0", 0)); - System.out.print(this.cache.debugCacheByGraphName("graph0")); + System.out.println(this.cache.debugCacheByGraphName("graph0")); } @Test @@ -223,14 +223,12 @@ public void testRange() { var partition3 = createPartition(3, "graph0", 1, 2); var partition4 = createPartition(4, "graph0", 2, 3); - this.cache.updatePartition(partition3); this.cache.updatePartition(partition4); System.out.println(this.cache.debugCacheByGraphName("graph0")); + var partition6 = createPartition(1, "graph0", 0, 1); this.cache.updatePartition(partition6); - - System.out.println(this.cache.debugCacheByGraphName("graph0")); var partition5 = createPartition(1, "graph0", 0, 3); @@ -244,13 +242,11 @@ public void testRange2() { var partition2 = createPartition(2, "graph0", 3, 6); this.cache.updatePartition(partition1); this.cache.updatePartition(partition2); - System.out.println(this.cache.debugCacheByGraphName("graph0")); // 中间有缺失 var partition3 = createPartition(1, "graph0", 2, 3); this.cache.updatePartition(partition3); - System.out.println(this.cache.debugCacheByGraphName("graph0")); var partition5 = createPartition(1, "graph0", 0, 3); 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 deleted file mode 100644 index dddbffb088..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/BaseCoreTest.java +++ /dev/null @@ -1,74 +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 org.apache.commons.io.FileUtils; -import org.apache.hugegraph.pd.ConfigService; -import org.apache.hugegraph.pd.config.PDConfig; -import org.junit.After; -import org.junit.BeforeClass; - - -public class BaseCoreTest { - - static org.apache.hugegraph.pd.config.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() {{ - 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() {{ - this.setMaxDownTime(3600); - this.setKeepAliveTimeout(3600); - }}); - - pdConfig.setPartition(new org.apache.hugegraph.pd.config.PDConfig().new Partition() {{ - this.setShardCount(3); - this.setMaxShardsPerStore(3); - }}); - pdConfig.setRaft(new org.apache.hugegraph.pd.config.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 void deleteDirectory(File dir) { - try { - FileUtils.deleteDirectory(dir); - } catch (IOException e) { - System.out.printf("Failed to start ....,%s%n", e.getMessage()); - } - } - - @After - public void teardown() throws Exception { - // pass - } -} 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 deleted file mode 100644 index 3f616e2123..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/PDCoreSuiteTest.java +++ /dev/null @@ -1,37 +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 org.apache.hugegraph.pd.core.meta.MetadataKeyHelperTest; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import lombok.extern.slf4j.Slf4j; - - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - StoreNodeServiceTest.class, - MetadataKeyHelperTest.class -}) - -@Slf4j -public class PDCoreSuiteTest { - - -} 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 c8c7bcf157..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/StoreNodeServiceTest.java +++ /dev/null @@ -1,119 +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.ArrayList; -import java.util.List; - -import org.apache.hugegraph.pd.PartitionService; -import org.apache.hugegraph.pd.StoreNodeService; -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Assert; -import org.junit.Test; - -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class StoreNodeServiceTest extends BaseCoreTest { - - - @Test - public void testStoreNodeService() throws PDException { - Assert.assertEquals(pdConfig.getPartition().getTotalCount(), - pdConfig.getInitialStoreMap().size() * - pdConfig.getPartition().getMaxShardsPerStore() - / pdConfig.getPartition().getShardCount()); - StoreNodeService storeService = new StoreNodeService(pdConfig); - storeService.init(new PartitionService(pdConfig, storeService)); - 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()); - // 设置leader - Assert.assertEquals(pdConfig.getPartition().getTotalCount(), - storeService.getShardGroups().size()); - 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()); - - - } - - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java deleted file mode 100644 index 7d38b9e132..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/core/meta/MetadataKeyHelperTest.java +++ /dev/null @@ -1,34 +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.meta; - -import static org.junit.Assert.assertArrayEquals; - -import org.apache.hugegraph.pd.meta.MetadataKeyHelper; -import org.junit.Test; - -public class MetadataKeyHelperTest { - - @Test - public void testMoveTaskKey() { - var key = MetadataKeyHelper.getMoveTaskKey("foo", 0, 1); - assertArrayEquals(key, "TASK_MOVE/foo/0/1".getBytes()); - var key2 = MetadataKeyHelper.getMoveTaskPrefix("foo"); - assertArrayEquals(key2, "TASK_MOVE/foo".getBytes()); - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java deleted file mode 100644 index 0e768d6119..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/BaseGrpcTest.java +++ /dev/null @@ -1,36 +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.grpc; - -import org.junit.After; -import org.junit.BeforeClass; - - -public class BaseGrpcTest { - - @BeforeClass - public static void init() { - - } - - @After - public void teardown() { - // pass - } - -} 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 deleted file mode 100644 index b994a1fd2e..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/grpc/GrpcSuiteTest.java +++ /dev/null @@ -1,33 +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.grpc; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -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/service/BaseServerTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/BaseServerTest.java deleted file mode 100644 index e9092a631c..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/BaseServerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.io.File; -import java.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; - - @BeforeClass - public static void init() { - client = HttpClient.newHttpClient(); - 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/service/ConfigServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ConfigServiceTest.java deleted file mode 100644 index faeacd834e..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ConfigServiceTest.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.util.List; - -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.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class ConfigServiceTest { - - private final PDConfig config = BaseServerTest.getConfig(); - - private ConfigService service; - - @Before - public void setUp() { - this.service = new ConfigService(this.config); - } - - @Test - public void testGetPDConfig() throws Exception { - // Setup - try { - final Metapb.PDConfig config = Metapb.PDConfig.newBuilder() - .setVersion(0L) - .setPartitionCount(0) - .setShardCount(55) - .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); - result = this.service.getPDConfig(); - Assert.assertTrue(result.getShardCount() == 55); - } catch (Exception e) { - - } - - } - - @Test - public void testGetGraphSpace() throws Exception { - // Setup - Metapb.GraphSpace space = Metapb.GraphSpace.newBuilder() - .setName("gs1") - .setTimestamp(0L).build(); - final List expectedResult = List.of(space); - this.service.setGraphSpace(space); - // Run the test - final List result = this.service.getGraphSpace( - "gs1"); - - Assert.assertEquals(1, result.size()); - } - - @Test - public void testUpdatePDConfig() { - try { - final Metapb.PDConfig mConfig = Metapb.PDConfig.newBuilder() - .setVersion(0L) - .setPartitionCount(0) - .setShardCount(0) - .setMaxShardsPerStore(0) - .setTimestamp(0L) - .build(); - final PDConfig expectedResult = new PDConfig(); - expectedResult.setConfigService(new ConfigService(new PDConfig())); - expectedResult.setIdService(new IdService(new PDConfig())); - expectedResult.setClusterId(0L); - expectedResult.setPatrolInterval(0L); - expectedResult.setDataPath("dataPath"); - expectedResult.setMinStoreCount(0); - expectedResult.setInitialStoreList("initialStoreList"); - expectedResult.setHost("host"); - expectedResult.setVerifyPath("verifyPath"); - expectedResult.setLicensePath("licensePath"); - this.service.updatePDConfig(mConfig); - } catch (Exception e) { - - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java deleted file mode 100644 index dd0d3feb24..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/IdServiceTest.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.io.File; - -import 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.junit.Assert; -import org.junit.Test; - -public class IdServiceTest { - @Test - public void testCid() { - try { - PDConfig pdConfig = BaseServerTest.getConfig(); - int max = 0x2000; - IdService idService = new IdService(pdConfig); - for (int i = 0; i < max; i++) { - idService.getCId("test", max); - } - idService.delCId("test", 1); - idService.delCId("test", 0x10); - idService.delCId("test", 0x100); - idService.delCId("test", 0x1000); - - Assert.assertEquals(1, idService.getCId("test", max)); - Assert.assertEquals(0x10, idService.getCId("test", max)); - Assert.assertEquals(0x100, idService.getCId("test", max)); - Assert.assertEquals(0x1000, idService.getCId("test", max)); - Assert.assertEquals(-1, idService.getCId("test", max)); - - idService.delCId("test", 1); - idService.delCId("test", 0x10); - idService.delCId("test", 0x100); - idService.delCId("test", 0x1000); - - long cid1 = idService.getCId("test", "name", max); - idService.delCIdDelay("test", "name", cid1); - long cid2 = idService.getCId("test", "name", max); - - Assert.assertEquals(cid1, cid2); - idService.delCIdDelay("test", "name", cid2); - Thread.sleep(5000); - long cid3 = idService.getCId("test", "name", max); - } catch (Exception e) { - - } - // MetadataFactory.closeStore(); - } - - @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/"); - }}; - IdService idService = new IdService(pdConfig); - long first = idService.getId("abc", 100); - Assert.assertEquals(first, 0L); - long second = idService.getId("abc", 100); - Assert.assertEquals(second, 100L); - idService.resetId("abc"); - first = idService.getId("abc", 100); - Assert.assertEquals(first, 0L); - } catch (Exception ignored) { - - } - // MetadataFactory.closeStore(); - } - - @Test - public void testMember() { - try { - PDConfig pdConfig = BaseServerTest.getConfig(); - IdService idService = new IdService(pdConfig); - idService.setPdConfig(pdConfig); - PDConfig config = idService.getPdConfig(); - config.getHost(); - } catch (Exception e) { - e.printStackTrace(); - } - // MetadataFactory.closeStore(); - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java deleted file mode 100644 index 02870b219e..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/KvServiceTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import org.apache.hugegraph.pd.KvService; -import org.apache.hugegraph.pd.config.PDConfig; -import org.junit.Assert; -import org.junit.Test; - -public class KvServiceTest { - - @Test - public void testKv() { - try { - PDConfig pdConfig = BaseServerTest.getConfig(); - KvService service = new KvService(pdConfig); - String key = "kvTest"; - String kvTest = service.get(key); - Assert.assertEquals(kvTest, ""); - service.put(key, "kvTestValue"); - kvTest = service.get(key); - Assert.assertEquals(kvTest, "kvTestValue"); - service.scanWithPrefix(key); - service.delete(key); - service.put(key, "kvTestValue"); - service.deleteWithPrefix(key); - service.put(key, "kvTestValue", 1000L); - service.keepAlive(key); - } catch (Exception e) { - - } - } - - @Test - public void testMember() { - try { - PDConfig pdConfig = BaseServerTest.getConfig(); - KvService service = new KvService(pdConfig); - service.setPdConfig(pdConfig); - PDConfig config = service.getPdConfig(); - } catch (Exception e) { - e.printStackTrace(); - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java deleted file mode 100644 index 266db76c56..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/LogServiceTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.util.List; - -import org.apache.hugegraph.pd.LogService; -import org.apache.hugegraph.pd.config.PDConfig; -import org.apache.hugegraph.pd.grpc.Metapb; -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(); - - private LogService logServiceUnderTest; - - @Before - public void setUp() { - this.logServiceUnderTest = new LogService(this.mockPdConfig); - } - - @Test - public void testGetLog() throws Exception { - this.logServiceUnderTest.insertLog("action", "message", - Any.newBuilder().build()); - - // Run the test - final List 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/service/PartitionServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PartitionServiceTest.java deleted file mode 100644 index 0a16402d33..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PartitionServiceTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.apache.hugegraph.pd.PartitionService; -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.grpc.MetaTask; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.apache.hugegraph.pd.grpc.pulse.CleanPartition; -import org.apache.hugegraph.pd.grpc.pulse.CleanType; -import org.junit.Before; -import org.junit.Test; - -public class PartitionServiceTest extends PdTestBase { - - private PartitionService service; - - @Before - public void init() { - this.service = getPartitionService(); - } - - @Test - public void testCombinePartition() throws PDException { - buildEnv(); - // 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); - assertEquals(0, partition.getStartKey()); - assertEquals(5462, partition.getEndKey()); - - var tasks = getStoreNodeService().getTaskInfoMeta().scanMoveTask("graph0"); - assertEquals(11, tasks.size()); - - for (MetaTask.Task task : tasks) { - var newTask = task.toBuilder().setState(MetaTask.TaskState.Task_Success).build(); - getTaskService().reportTask(newTask); - } - - tasks = getStoreNodeService().getTaskInfoMeta().scanMoveTask("graph0"); - assertEquals(0, tasks.size()); - } - - @Test - public void testCombinePartition2() throws PDException { - buildEnv(); - // 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); - assertEquals(0, partition.getStartKey()); - assertEquals(5462, partition.getEndKey()); - - var tasks = getStoreNodeService().getTaskInfoMeta().scanMoveTask("graph0"); - assertEquals(11, tasks.size()); - - for (MetaTask.Task task : tasks) { - var newTask = task.toBuilder().setState(MetaTask.TaskState.Task_Failure).build(); - getTaskService().reportTask(newTask); - } - - tasks = getStoreNodeService().getTaskInfoMeta().scanMoveTask("graph0"); - assertEquals(0, tasks.size()); - } - - @Test - public void testHandleCleanTask() { - MetaTask.Task task = MetaTask.Task.newBuilder() - .setType(MetaTask.TaskType.Clean_Partition) - .setPartition( - Metapb.Partition.newBuilder().setGraphName("foo") - .setId(0).build()) - .setCleanPartition(CleanPartition.newBuilder() - .setCleanType( - CleanType.CLEAN_TYPE_KEEP_RANGE) - .setDeletePartition(true) - .setKeyStart(0) - .setKeyEnd(10) - .build()) - .build(); - getTaskService().reportTask(task); - } - - private void buildEnv() throws PDException { - var storeInfoMeta = getStoreNodeService().getStoreInfoMeta(); - storeInfoMeta.updateStore(Metapb.Store.newBuilder() - .setId(99) - .setState(Metapb.StoreState.Up) - .build()); - - long lastId = 0; - for (int i = 0; i < 12; i++) { - Metapb.Shard shard = Metapb.Shard.newBuilder() - .setStoreId(99) - .setRole(Metapb.ShardRole.Leader) - .build(); - - Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder() - .setId(i) - .setState( - Metapb.PartitionState.PState_Normal) - .addAllShards(List.of(shard)) - .build(); - storeInfoMeta.updateShardGroup(shardGroup); - - var partitionShard = this.service.getPartitionByCode("graph0", lastId); - if (partitionShard != null) { - lastId = partitionShard.getPartition().getEndKey(); - } - } - - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java deleted file mode 100644 index 50eadb3a6d..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/PdTestBase.java +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.io.File; - -import org.apache.hugegraph.pd.ConfigService; -import org.apache.hugegraph.pd.IdService; -import org.apache.hugegraph.pd.PartitionInstructionListener; -import org.apache.hugegraph.pd.PartitionService; -import org.apache.hugegraph.pd.PartitionStatusListener; -import org.apache.hugegraph.pd.StoreMonitorDataService; -import org.apache.hugegraph.pd.StoreNodeService; -import org.apache.hugegraph.pd.StoreStatusListener; -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.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.apache.hugegraph.pd.raft.RaftEngine; -import org.junit.AfterClass; -import org.junit.BeforeClass; - -public class PdTestBase { - private static final String DATA_PATH = "/tmp/pd_data"; - private static PDConfig pdConfig; - private static StoreNodeService storeNodeService; - private static PartitionService partitionService; - private static TaskScheduleService taskService; - private static StoreMonitorDataService storeMonitorDataService; - - @BeforeClass - public static void initService() throws PDException { - deleteDir(new File(DATA_PATH)); - - PDConfig config = new PDConfig(); - config.setDataPath(DATA_PATH); - config.setMinStoreCount(3); - config.setInitialStoreList("127.0.0.1:8501"); - 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"); - raft.setDataPath(DATA_PATH); - raft.setHost("127.0.0.1"); - raft.setGrpcPort(8688); - raft.setPort(8621); - - config.setRaft(raft); - - config.setStore(new PDConfig().new Store()); - config.setPartition(new PDConfig().new Partition() {{ - setShardCount(1); - setTotalCount(12); - setMaxShardsPerStore(12); - }}); - config.setDiscovery(new PDConfig().new Discovery()); - - pdConfig = config; - - var configService = new ConfigService(pdConfig); - configService.loadConfig(); - - var engine = RaftEngine.getInstance(); - engine.addStateListener(configService); - engine.init(pdConfig.getRaft()); - engine.waitingForLeader(5000); - - storeNodeService = new StoreNodeService(pdConfig); - partitionService = new PartitionService(pdConfig, storeNodeService); - taskService = new TaskScheduleService(pdConfig, storeNodeService, partitionService); - var idService = new IdService(pdConfig); - storeMonitorDataService = new StoreMonitorDataService(pdConfig); - RaftEngine.getInstance().addStateListener(partitionService); - pdConfig.setIdService(idService); - - - storeNodeService.init(partitionService); - partitionService.init(); - 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 { - - } - - @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 { - - } - }); - - partitionService.addStatusListener(new PartitionStatusListener() { - @Override - public void onPartitionChanged(Metapb.Partition partition, - Metapb.Partition newPartition) { - - } - - @Override - public void onPartitionRemoved(Metapb.Partition partition) { - - } - }); - - storeNodeService.addStatusListener(new StoreStatusListener() { - @Override - public void onStoreStatusChanged(Metapb.Store store, Metapb.StoreState old, - Metapb.StoreState status) { - - } - - @Override - public void onGraphChange(Metapb.Graph graph, Metapb.GraphState stateOld, - Metapb.GraphState stateNew) { - - } - - @Override - public void onStoreRaftChanged(Metapb.Store store) { - - } - }); - - taskService.init(); - } - - @AfterClass - public static void shutdownService() { - var instance = RaftEngine.getInstance(); - if (instance != null) { - instance.shutDown(); - } - } - - private static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - for (File file : dir.listFiles()) { - deleteDir(file); - } - } - return dir.delete(); - } - - public static StoreNodeService getStoreNodeService() { - return storeNodeService; - } - - public static PartitionService getPartitionService() { - return partitionService; - } - - public static PDConfig getPdConfig() { - return pdConfig; - } - - public static TaskScheduleService getTaskService() { - return taskService; - } - - public static StoreMonitorDataService getStoreMonitorDataService() { - return storeMonitorDataService; - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java deleted file mode 100644 index 7e5fec381e..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/RestApiTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; - -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Test; - -public class RestApiTest extends BaseServerTest { - @Test - public void testQueryClusterInfo() throws URISyntaxException, IOException, InterruptedException, - JSONException { - String url = pdRestAddr + "/v1/cluster"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } - - @Test - public void testQueryClusterMembers() throws URISyntaxException, IOException, - InterruptedException, JSONException { - String url = pdRestAddr + "/v1/members"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } - - @Test - public void testQueryStoresInfo() throws URISyntaxException, IOException, InterruptedException, - JSONException { - String url = pdRestAddr + "/v1/stores"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } - - @Test - public void testQueryGraphsInfo() throws IOException, InterruptedException, JSONException, - URISyntaxException { - String url = pdRestAddr + "/v1/graphs"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } - - @Test - public void testQueryPartitionsInfo() throws IOException, InterruptedException, JSONException, - URISyntaxException { - String url = pdRestAddr + "/v1/highLevelPartitions"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } - - @Test - public void testQueryDebugPartitionsInfo() throws URISyntaxException, IOException, - InterruptedException { - String url = pdRestAddr + "/v1/partitions"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - assert response.statusCode() == 200; - } - - @Test - public void testQueryShards() throws URISyntaxException, IOException, InterruptedException, - JSONException { - String url = pdRestAddr + "/v1/shards"; - HttpRequest request = HttpRequest.newBuilder() - .uri(new URI(url)) - .GET() - .build(); - HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); - JSONObject obj = new JSONObject(response.body()); - assert obj.getInt("status") == 0; - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java deleted file mode 100644 index fe8c0ed044..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/ServerSuiteTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -import lombok.extern.slf4j.Slf4j; - - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - RestApiTest.class, - ConfigServiceTest.class, - IdServiceTest.class, - KvServiceTest.class, - LogServiceTest.class, - StoreServiceTest.class, - StoreNodeServiceNewTest.class, - StoreMonitorDataServiceTest.class, - TaskScheduleServiceTest.class, - PartitionServiceTest.class -}) - -@Slf4j -public class ServerSuiteTest { -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java deleted file mode 100644 index 21a2a37dde..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreMonitorDataServiceTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.apache.hugegraph.pd.StoreMonitorDataService; -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Before; -import org.junit.Test; - -public class StoreMonitorDataServiceTest extends PdTestBase { - - StoreMonitorDataService service; - - @Before - public void init() { - this.service = getStoreMonitorDataService(); - var store = getPdConfig().getStore(); - store.setMonitorDataEnabled(true); - store.setMonitorDataInterval("1s"); - getPdConfig().setStore(store); - } - - @Test - public void test() throws InterruptedException, PDException { - long now = System.currentTimeMillis() / 1000; - for (int i = 0; i < 5; i++) { - this.service.saveMonitorData(genStats()); - now = System.currentTimeMillis() / 1000; - Thread.sleep(1100); - } - assertTrue(this.service.getLatestStoreMonitorDataTimeStamp(1) == 0 || - this.service.getLatestStoreMonitorDataTimeStamp(1) == now); - - var data = this.service.getStoreMonitorData(1); - assertEquals(5, data.size()); - - assertNotNull(this.service.debugMonitorInfo(List.of(Metapb.RecordPair.newBuilder() - .setKey("key1") - .setValue(1) - .build()))); - - 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) - .addSystemMetrics( - Metapb.RecordPair.newBuilder().setKey("key1").setValue(1) - .build()) - .build(); - } - - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceNewTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreNodeServiceNewTest.java deleted file mode 100644 index 10d098d1f3..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/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.service; - -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 PdTestBase { - 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/service/StoreServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreServiceTest.java deleted file mode 100644 index af17db1c72..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/StoreServiceTest.java +++ /dev/null @@ -1,833 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.hugegraph.pd.service; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -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.config.PDConfig; -import org.apache.hugegraph.pd.grpc.MetaTask; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Before; -import org.junit.Test; - -public class StoreServiceTest { - - private PDConfig config; - - private StoreNodeService service; - - @Before - public void setUp() { - this.config = getConfig(); - this.service = new StoreNodeService(this.config); - } - - @Test - public void testInit() { - // Setup - PDConfig pdConfig = getConfig(); - final PDConfig pdConfig1 = getConfig(); - final PartitionService partitionService = new PartitionService(pdConfig, - new StoreNodeService( - pdConfig1)); - - // Run the test - this.service.init(partitionService); - - // 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 - // Run the test - final boolean result = this.service.isOK(); - - // Verify the results - assertThat(result).isTrue(); - } - - @Test - public void testRegister() throws Exception { - // Setup - final Metapb.Store store = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version").setState( - Metapb.StoreState.Unknown).setStartTimestamp(0L) - .setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build(); - final Metapb.Store expectedResult = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress( - "raftAddress") - .addLabels( - Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version") - .setState( - Metapb.StoreState.Unknown) - .setStartTimestamp(0L) - .setDeployPath( - "deployPath") - .setLastHeartbeat(0L) - .setStats( - Metapb.StoreStats - .newBuilder() - .setStoreId( - 0L) - .setPartitionCount( - 0) - .addGraphStats( - Metapb.GraphStats - .newBuilder() - .setGraphName( - "value") - .setApproximateSize( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .build()) - .setDataVersion(0) - .setCores(0) - .setDataPath("dataPath") - .build(); - - // Configure PDConfig.getInitialStoreMap(...). - final Map stringStringMap = Map.ofEntries( - Map.entry("value", "value")); - - // Run the test - final Metapb.Store result = this.service.register(store); - } - - @Test - public void testGetStore() throws Exception { - // Setup - try { - Metapb.GraphStats stats = Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole( - Metapb.ShardRole.None) - .build(); - Metapb.StoreStats storeStats = Metapb.StoreStats.newBuilder() - .setStoreId(0L) - .setPartitionCount( - 0) - .addGraphStats( - stats) - .build(); - final Metapb.Store expectedResult = Metapb.Store.newBuilder() - .setId(0L) - .setAddress( - "address") - .setRaftAddress( - "raftAddress") - .addLabels( - Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion( - "version") - .setState( - Metapb.StoreState.Unknown) - .setStartTimestamp( - 0L) - .setDeployPath( - "deployPath") - .setLastHeartbeat( - 0L) - .setStats( - storeStats) - .setDataVersion(0) - .setCores(0) - .setDataPath( - "dataPath") - .build(); - - // Run the test - final Metapb.Store result = this.service.getStore(0L); - } catch (Exception e) { - - } - } - - @Test - public void testUpdateStore() throws Exception { - // Setup - final Metapb.Store store = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version").setState( - Metapb.StoreState.Unknown).setStartTimestamp(0L) - .setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build(); - final Metapb.Store expectedResult = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress( - "raftAddress") - .addLabels( - Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version") - .setState( - Metapb.StoreState.Unknown) - .setStartTimestamp(0L) - .setDeployPath( - "deployPath") - .setLastHeartbeat(0L) - .setStats( - Metapb.StoreStats - .newBuilder() - .setStoreId( - 0L) - .setPartitionCount( - 0) - .addGraphStats( - Metapb.GraphStats - .newBuilder() - .setGraphName( - "value") - .setApproximateSize( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .build()) - .setDataVersion(0) - .setCores(0) - .setDataPath("dataPath") - .build(); - - // Configure PDConfig.getPartition(...). - final PDConfig.Partition partition = new PDConfig().new Partition(); - partition.setTotalCount(0); - partition.setMaxShardsPerStore(0); - partition.setShardCount(0); - - // Run the test - final Metapb.Store result = this.service.updateStore(store); - } - - @Test - public void testStoreTurnoff() throws Exception { - // Setup - final Metapb.Store store = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version").setState( - Metapb.StoreState.Unknown).setStartTimestamp(0L) - .setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build(); - - // Configure PDConfig.getPartition(...). - final PDConfig.Partition partition = new PDConfig().new Partition(); - partition.setTotalCount(0); - partition.setMaxShardsPerStore(0); - partition.setShardCount(0); - - // Run the test - this.service.storeTurnoff(store); - - // Verify the results - } - - - @Test - public void testGetStores1() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.Store.newBuilder().setId(0L).setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel.newBuilder().build()) - .setVersion("version") - .setState(Metapb.StoreState.Unknown) - .setStartTimestamp(0L).setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build()); - - // Run the test - final List result = this.service.getStores(); - } - - @Test - public void testGetStores2() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.Store.newBuilder().setId(0L).setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel.newBuilder().build()) - .setVersion("version") - .setState(Metapb.StoreState.Unknown) - .setStartTimestamp(0L).setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build()); - - // Run the test - final List result = this.service.getStores("graphName"); - } - - - @Test - public void testGetStoreStatus() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.Store.newBuilder().setId(0L).setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel.newBuilder().build()) - .setVersion("version") - .setState(Metapb.StoreState.Unknown) - .setStartTimestamp(0L).setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build()); - - // Run the test - final List result = this.service.getStoreStatus(false); - - } - - @Test - public void testGetShardGroups() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.ShardGroup.newBuilder().setId(0).addShards( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()) - .setState(Metapb.PartitionState.PState_None) - .build()); - - // Run the test - final List result = this.service.getShardGroups(); - - } - - @Test - public void testGetShardGroup() throws Exception { - // Setup - final Metapb.ShardGroup expectedResult = Metapb.ShardGroup.newBuilder() - .setId(0) - .addShards( - Metapb.Shard - .newBuilder() - .setStoreId( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .setState( - Metapb.PartitionState.PState_None) - .build(); - - // Run the test - final Metapb.ShardGroup result = this.service.getShardGroup(0); - - // Verify the results - } - - - @Test - public void testGetShardGroupsByStore() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.ShardGroup.newBuilder().setId(0).addShards( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()) - .setState(Metapb.PartitionState.PState_None) - .build()); - - // Run the test - final List result = this.service.getShardGroupsByStore( - 0L); - } - - @Test - public void testGetActiveStores1() throws Exception { - // Setup - final List expectedResult = List.of( - Metapb.Store.newBuilder().setId(0L).setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel.newBuilder().build()) - .setVersion("version") - .setState(Metapb.StoreState.Unknown) - .setStartTimestamp(0L).setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build()); - - // Run the test - final List result = this.service.getActiveStores("graphName"); - - // Verify the results - } - - @Test - public void testGetActiveStores1ThrowsPDException() { - try { - List stores = this.service.getActiveStores(); - assertThat(stores.size() == 0); - } catch (Exception e) { - - } - } - - @Test - public void testGetTombStores() throws Exception { - // Setup - final List storeList = List.of( - Metapb.Store.newBuilder().setId(0L).setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel.newBuilder().build()) - .setVersion("version") - .setState(Metapb.StoreState.Tombstone) - .setStartTimestamp(0L).setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build()); - this.service.register(storeList.get(0)); - - // Run the test - final List result = this.service.getTombStores(); - - // Verify the results - assertThat(result.size() == 1); - this.service.removeStore(result.get(0).getId()); - List stores = this.service.getStores(); - assertThat(stores.size() == 0); - } - - - @Test - public void testAllocShards() throws Exception { - // Setup - try { - final Metapb.Graph graph = Metapb.Graph.newBuilder() - .setGraphName("graphName") - .setGraphState( - Metapb.GraphState - .newBuilder() - .setMode( - Metapb.GraphMode.ReadWrite) - .setReason( - Metapb.GraphModeReason.Quota) - .build()) - .build(); - final List expectedResult = List.of( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()); - - // Configure PDConfig.getPartition(...). - final PDConfig.Partition partition = new PDConfig().new Partition(); - partition.setTotalCount(0); - partition.setMaxShardsPerStore(0); - partition.setShardCount(0); - - // Run the test - final List result = this.service.allocShards(graph, 0); - } catch (Exception e) { - - } - - } - - @Test - public void testReallocShards() throws Exception { - // Setup - try { - final Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder() - .setId(0) - .addShards( - Metapb.Shard - .newBuilder() - .setStoreId( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .setState( - Metapb.PartitionState.PState_None) - .build(); - final List expectedResult = List.of( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()); - - // Configure PDConfig.getPartition(...). - final PDConfig.Partition partition = new PDConfig().new Partition(); - partition.setTotalCount(0); - partition.setMaxShardsPerStore(0); - partition.setShardCount(0); - when(this.config.getPartition()).thenReturn(partition); - - // Run the test - final List result = this.service.reallocShards(shardGroup); - - // Verify the results - assertThat(result).isEqualTo(expectedResult); - } catch (Exception e) { - - } - - } - - @Test - public void testUpdateShardGroup() { - try { - final List shards = List.of( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()); - - // Run the test - this.service.updateShardGroup(0, shards, 0, 0); - } catch (Exception e) { - - } - } - - @Test - public void testUpdateShardGroupState() throws Exception { - try { - this.service.updateShardGroupState(0, Metapb.PartitionState.PState_None); - } catch (Exception e) { - - } - } - - @Test - public void testHeartBeat() throws Exception { - // Setup - try { - final Metapb.StoreStats storeStats = Metapb.StoreStats.newBuilder() - .setStoreId( - 0L) - .setPartitionCount( - 0) - .addGraphStats( - Metapb.GraphStats - .newBuilder() - .setGraphName( - "value") - .setApproximateSize( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .build(); - final Metapb.ClusterStats expectedResult = Metapb.ClusterStats - .newBuilder().setState(Metapb.ClusterState.Cluster_OK) - .setMessage("message").setTimestamp(0L).build(); - when(this.config.getMinStoreCount()).thenReturn(0); - - // Configure PDConfig.getPartition(...). - final PDConfig.Partition partition = new PDConfig().new Partition(); - partition.setTotalCount(0); - partition.setMaxShardsPerStore(0); - partition.setShardCount(0); - when(this.config.getPartition()).thenReturn(partition); - - // Run the test - final Metapb.ClusterStats result = this.service.heartBeat(storeStats); - - // Verify the results - assertThat(result).isEqualTo(expectedResult); - } catch (Exception e) { - - } - } - - - @Test - public void testUpdateClusterStatus1() { - // Setup - final Metapb.ClusterStats expectedResult = Metapb.ClusterStats - .newBuilder().setState(Metapb.ClusterState.Cluster_OK) - .setMessage("message").setTimestamp(0L).build(); - - // Run the test - final Metapb.ClusterStats result = this.service.updateClusterStatus( - Metapb.ClusterState.Cluster_OK); - } - - @Test - public void testUpdateClusterStatus2() { - // Setup - final Metapb.ClusterStats expectedResult = Metapb.ClusterStats - .newBuilder().setState(Metapb.ClusterState.Cluster_OK) - .setMessage("message").setTimestamp(0L).build(); - - // Run the test - final Metapb.ClusterStats result = this.service.updateClusterStatus( - Metapb.PartitionState.PState_None); - } - - @Test - public void testCheckStoreStatus() { - // Setup - // Run the test - this.service.checkStoreStatus(); - - // Verify the results - } - - @Test - public void testAddStatusListener() { - // Setup - final StoreStatusListener mockListener = mock( - StoreStatusListener.class); - - // Run the test - this.service.addStatusListener(mockListener); - - // Verify the results - } - - @Test - public void testOnStoreStatusChanged() { - // Setup - final Metapb.Store store = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress("raftAddress") - .addLabels(Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version").setState( - Metapb.StoreState.Unknown).setStartTimestamp(0L) - .setDeployPath("deployPath") - .setLastHeartbeat(0L).setStats( - Metapb.StoreStats.newBuilder().setStoreId(0L) - .setPartitionCount(0).addGraphStats( - Metapb.GraphStats.newBuilder() - .setGraphName("value") - .setApproximateSize(0L) - .setRole(Metapb.ShardRole.None) - .build()).build()) - .setDataVersion(0).setCores(0) - .setDataPath("dataPath").build(); - - // Verify the results - } - - @Test - public void testOnShardGroupSplit() { - // Setup - final Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder() - .setId(0) - .addShards( - Metapb.Shard - .newBuilder() - .setStoreId( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .setState( - Metapb.PartitionState.PState_None) - .build(); - final List newShardGroups = List.of( - Metapb.ShardGroup.newBuilder().setId(0).addShards( - Metapb.Shard.newBuilder().setStoreId(0L) - .setRole(Metapb.ShardRole.None).build()) - .setState(Metapb.PartitionState.PState_None) - .build()); - final Consumer mockTask = mock(Consumer.class); - - // Verify the results - } - - @Test - public void testCheckStoreCanOffline() { - // Setup - final Metapb.Store currentStore = Metapb.Store.newBuilder().setId(0L) - .setAddress("address") - .setRaftAddress( - "raftAddress") - .addLabels( - Metapb.StoreLabel - .newBuilder() - .build()) - .setVersion("version") - .setState( - Metapb.StoreState.Unknown) - .setStartTimestamp(0L) - .setDeployPath( - "deployPath") - .setLastHeartbeat(0L) - .setStats( - Metapb.StoreStats - .newBuilder() - .setStoreId( - 0L) - .setPartitionCount( - 0) - .addGraphStats( - Metapb.GraphStats - .newBuilder() - .setGraphName( - "value") - .setApproximateSize( - 0L) - .setRole( - Metapb.ShardRole.None) - .build()) - .build()) - .setDataVersion(0) - .setCores(0) - .setDataPath("dataPath") - .build(); - // Run the test - final boolean result = this.service.checkStoreCanOffline(currentStore); - - // Verify the results - assertThat(result).isTrue(); - } - - @Test - public void testShardGroupsDbCompaction() throws Exception { - // Setup - // Run the test - try { - this.service.shardGroupsDbCompaction(0, "tableName"); - } catch (Exception e) { - - } - - // Verify the results - } - - @Test - public void testGetQuota() throws Exception { - // Setup - // Run the test - try { - this.service.getQuota(); - } catch (Exception e) { - - } - } -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.java deleted file mode 100644 index 7966bb7125..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/service/TaskScheduleServiceTest.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.service; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.hugegraph.pd.TaskScheduleService; -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.grpc.Metapb; -import org.junit.Before; -import org.junit.Test; - -public class TaskScheduleServiceTest extends PdTestBase { - - TaskScheduleService service; - - @Before - public void init() { - this.service = getTaskService(); - } - - @Test - public void testStoreOffline() { - - } - - public void testPatrolStores() { - - } - - public void testPatrolPartitions() { - - } - - public void testBalancePartitionShard() { - - } - - @Test - public void testBalancePartitionLeader() throws PDException { - - var list = new ArrayList(); - for (int i = 0; i < 6; i++) { - getStoreNodeService().getStoreInfoMeta().updateShardGroup(genShardGroup(i)); - list.add(genPartition(i)); - } - - getPdConfig().getPartition().setShardCount(3); - - getPartitionService().updatePartition(list); - var rst = this.service.balancePartitionLeader(true); - assertTrue(rst.size() > 0); - // recover - getPdConfig().getPartition().setShardCount(1); - getStoreNodeService().getStoreInfoMeta().removeAll(); - } - - public void testSplitPartition() { - - } - - public void testSplitPartition2() { - - } - - public void testCanAllPartitionsMovedOut() { - - } - - private Metapb.ShardGroup genShardGroup(int groupId) { - return Metapb.ShardGroup.newBuilder() - .setId(groupId) - .addAllShards(genShards()) - .build(); - } - - private Metapb.Partition genPartition(int groupId) { - return Metapb.Partition.newBuilder() - .setId(groupId) - .setState(Metapb.PartitionState.PState_Normal) - .setGraphName("graph1") - .setStartKey(groupId * 10) - .setEndKey(groupId * 10 + 10) - .build(); - } - - private List genShards() { - return List.of( - Metapb.Shard.newBuilder().setStoreId(1).setRole(Metapb.ShardRole.Leader).build(), - Metapb.Shard.newBuilder().setStoreId(2).setRole(Metapb.ShardRole.Follower).build(), - Metapb.Shard.newBuilder().setStoreId(3).setRole(Metapb.ShardRole.Follower).build()); - } - -} diff --git a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java b/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java deleted file mode 100644 index 342ac9bc44..0000000000 --- a/hugegraph-pd/hg-pd-test/src/main/java/org/apache/hugegraph/pd/store/HgKVStoreImplTest.java +++ /dev/null @@ -1,105 +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.store; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; - -import org.apache.commons.io.FileUtils; -import org.apache.hugegraph.pd.common.PDException; -import org.apache.hugegraph.pd.config.PDConfig; -import org.junit.Assert; -import org.junit.BeforeClass; - -public class HgKVStoreImplTest { - static final String testPath = "tmp/test"; - static PDConfig pdConfig; - - @BeforeClass - public static void init() throws IOException { - File testFile = new File(testPath); - if (testFile.exists()) { - FileUtils.deleteDirectory(testFile); - } - FileUtils.forceMkdir(testFile); - pdConfig = new PDConfig() {{ - setDataPath(testPath); - }}; - } - - // @Test - public void Test() throws PDException { - HgKVStore kvStore = new HgKVStoreImpl(); - kvStore.init(pdConfig); - - { - byte[] key = "hello".getBytes(); - byte[] value = "pd".getBytes(); - kvStore.put(key, value); - } - for (int i = 0; i < 100; i++) { - byte[] key = String.format("k%03d", i).getBytes(); - byte[] value = ("value" + i).getBytes(); - kvStore.put(key, value); - } - - Assert.assertEquals(100, kvStore.scanPrefix("k".getBytes()).size()); - - kvStore.removeByPrefix("k".getBytes()); - Assert.assertEquals(0, kvStore.scanPrefix("k".getBytes()).size()); - } - - // @Test - public void TestSnapshot() throws PDException { - HgKVStore kvStore = new HgKVStoreImpl(); - kvStore.init(pdConfig); - - // put 100 data - for (int i = 0; i < 100; i++) { - byte[] key = String.format("k%03d", i).getBytes(); - byte[] value = ("value" + i).getBytes(); - kvStore.put(key, value); - } - Assert.assertEquals(100, kvStore.scanPrefix("k".getBytes()).size()); - - // save snapshot - String snapshotPath = Paths.get(testPath, "snapshot").toString(); - kvStore.saveSnapshot(snapshotPath); - - // put another 100 data - for (int i = 100; i < 200; i++) { - byte[] key = String.format("k%03d", i).getBytes(); - byte[] value = ("value" + i).getBytes(); - kvStore.put(key, value); - } - Assert.assertEquals(200, kvStore.scanPrefix("k".getBytes()).size()); - - // load snapshot - kvStore.loadSnapshot(snapshotPath); - Assert.assertEquals(100, kvStore.scanPrefix("k".getBytes()).size()); - - // put another 100 data - for (int i = 100; i < 200; i++) { - byte[] key = String.format("k%03d", i).getBytes(); - byte[] value = ("value" + i).getBytes(); - kvStore.put(key, value); - } - Assert.assertEquals(200, kvStore.scanPrefix("k".getBytes()).size()); - } -} diff --git a/hugegraph-pd/pom.xml b/hugegraph-pd/pom.xml index 49fd28f384..6dde68c402 100644 --- a/hugegraph-pd/pom.xml +++ b/hugegraph-pd/pom.xml @@ -147,79 +147,7 @@ - - - pd-client-test - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - pd-client-test - - test - - test - - - - - - - - pd-core-test - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - pd-core-test - - test - - test - - - - - - - - pd-cli-tools-test - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - pd-cli-tools-test - - test - - test - - - - - - + pd-common-test @@ -244,29 +172,5 @@ - - pd-service-test - - true - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 - - - pd-service-test - - test - - test - - - - - - diff --git a/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh new file mode 100644 index 0000000000..6da114a707 --- /dev/null +++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/start-pd.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# 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. +# +set -ev + +HOME_DIR=$(pwd) +PD_DIR=$HOME_DIR/hugegraph-pd/dist/hugegraph-pd-1.5.0.1 + +pushd $PD_DIR +. bin/start-hugegraph-pd.sh +sleep 10 +popd