forked from hugegraph/hugegraph-sync
fix(pd-store): intro `Useless` annotation & refactor and mark the failed tests in `hg-pd-test` (#2480)
* add value for Useless annotation --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
f34b528885
commit
67aba571cc
|
|
@ -45,29 +45,30 @@ jobs:
|
|||
run: |
|
||||
mvn clean package -U -Dmaven.javadoc.skip=true -Dmaven.test.skip=true -ntp
|
||||
|
||||
- name: Run common test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test
|
||||
|
||||
- name: Run core test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test
|
||||
|
||||
# The above tests do not require starting a PD instance.
|
||||
- name: Prepare env and service
|
||||
run: |
|
||||
$TRAVIS_DIR/start-pd.sh
|
||||
|
||||
- name: Run client test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-client-test -Dmaven.test.failure.ignore=true
|
||||
|
||||
- name: Run core test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-core-test -Dmaven.test.failure.ignore=true
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-client-test
|
||||
|
||||
- name: Run cli-tools test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-cli-tools-test -Dmaven.test.failure.ignore=true
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-cli-tools-test
|
||||
|
||||
- name: Run common test
|
||||
- name: Run rest test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-common-test -Dmaven.test.failure.ignore=true
|
||||
|
||||
- name: Run service test
|
||||
run: |
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-service-test -Dmaven.test.failure.ignore=true
|
||||
mvn test -pl hugegraph-pd/hg-pd-test -am -P pd-rest-test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3.0.0
|
||||
|
|
|
|||
|
|
@ -17,9 +17,11 @@
|
|||
|
||||
package org.apache.hugegraph.pd.client;
|
||||
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.Query;
|
||||
|
||||
@Useless
|
||||
public interface Discoverable {
|
||||
|
||||
NodeInfos getNodeInfos(Query query);
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.function.Consumer;
|
|||
import java.util.function.Function;
|
||||
|
||||
import org.apache.hugegraph.pd.common.PDException;
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.DiscoveryServiceGrpc;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.NodeInfos;
|
||||
|
|
@ -38,6 +39,7 @@ import io.grpc.ManagedChannel;
|
|||
import io.grpc.ManagedChannelBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Useless
|
||||
@Slf4j
|
||||
public abstract class DiscoveryClient implements Closeable, Discoverable {
|
||||
|
||||
|
|
|
|||
|
|
@ -20,9 +20,11 @@ package org.apache.hugegraph.pd.client;
|
|||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.NodeInfo;
|
||||
import org.apache.hugegraph.pd.grpc.discovery.RegisterType;
|
||||
|
||||
@Useless
|
||||
public class DiscoveryClientImpl extends DiscoveryClient {
|
||||
|
||||
private final String id;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.hugegraph.pd.client;
|
||||
|
||||
import org.apache.hugegraph.pd.common.KVPair;
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.grpc.PDGrpc;
|
||||
import org.apache.hugegraph.pd.grpc.Pdpb;
|
||||
|
||||
|
|
@ -27,6 +28,7 @@ import io.grpc.stub.AbstractBlockingStub;
|
|||
import io.grpc.stub.AbstractStub;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Useless
|
||||
@Slf4j
|
||||
public class LicenseClient extends AbstractClient {
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.common;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* The "Useless" annotation indicates that the annotated object can be safely removed without
|
||||
* affecting existing functionality, including objects that are only referenced in tests.
|
||||
*/
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
public @interface Useless {
|
||||
|
||||
String value() default "Remove or handle it later";
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.hugegraph.pd;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.hugegraph.pd.common.PDException;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
|
|
@ -128,7 +129,11 @@ public class ConfigService implements RaftStateListener {
|
|||
* @throws PDException when io error
|
||||
*/
|
||||
public int getPartitionCount() throws PDException {
|
||||
return getPDConfig().getPartitionCount();
|
||||
Metapb.PDConfig config = getPDConfig();
|
||||
if (Objects.nonNull(config)) {
|
||||
return config.getPartitionCount();
|
||||
}
|
||||
return pdConfig.getInitialPartitionCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -159,6 +159,9 @@ public class RaftEngine {
|
|||
}
|
||||
|
||||
public boolean isLeader() {
|
||||
if (Objects.isNull(this.raftNode)) {
|
||||
return false;
|
||||
}
|
||||
return this.raftNode.isLeader(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -292,14 +292,14 @@
|
|||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>pd-service-test</id>
|
||||
<id>pd-rest-test</id>
|
||||
<configuration>
|
||||
<testSourceDirectory>${basedir}/src/main/java/
|
||||
</testSourceDirectory>
|
||||
<testClassesDirectory>${basedir}/target/classes/
|
||||
</testClassesDirectory>
|
||||
<includes>
|
||||
<include>**/ServerSuiteTest.java</include>
|
||||
<include>**/PDRestSuiteTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
|
|
|||
|
|
@ -24,12 +24,14 @@ import java.util.Map;
|
|||
|
||||
import org.apache.hugegraph.pd.common.KVPair;
|
||||
import org.apache.hugegraph.pd.common.PartitionCache;
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
|
||||
import com.google.common.collect.Range;
|
||||
import com.google.common.collect.RangeMap;
|
||||
import com.google.common.collect.TreeRangeMap;
|
||||
|
||||
@Useless("can be merged to org.apache.hugegraph.pd.common.PartitionCacheTest")
|
||||
public class PartitionCacheTest {
|
||||
|
||||
// @Test
|
||||
|
|
|
|||
|
|
@ -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<Metapb.Shard> 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<Metapb.Shard> shardList2 = new ArrayList<>(stats.getShardList());
|
||||
Collections.shuffle(shardList2);
|
||||
shardList2.forEach(shard -> {
|
||||
System.out.println(shard.getStoreId());
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -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<Metapb.Shard> shards = storeService.allocShards(graph, 1);
|
||||
|
||||
|
||||
Assert.assertEquals(3, shards.size());
|
||||
|
||||
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
|
||||
storeService.getShardGroups().size()); // 设置leader
|
||||
Metapb.Shard leader = Metapb.Shard.newBuilder(shards.get(0))
|
||||
.setRole(Metapb.ShardRole.Leader).build();
|
||||
shards = new ArrayList<>(shards);
|
||||
shards.set(0, leader);
|
||||
// 增加shard
|
||||
pdConfig.getPartition().setShardCount(5);
|
||||
|
||||
Metapb.ShardGroup shardGroup = Metapb.ShardGroup.newBuilder()
|
||||
.setId(1)
|
||||
.addAllShards(shards).build();
|
||||
shards = storeService.reallocShards(shardGroup);
|
||||
|
||||
Assert.assertEquals(5, shards.size());
|
||||
// 减少shard
|
||||
pdConfig.getPartition().setShardCount(3);
|
||||
shards = storeService.reallocShards(shardGroup);
|
||||
Assert.assertEquals(3, shards.size());
|
||||
// 包含leader,leader不能被删除
|
||||
Assert.assertTrue(shards.contains(leader));
|
||||
|
||||
// 减少shard
|
||||
pdConfig.getPartition().setShardCount(1);
|
||||
graph = Metapb.Graph.newBuilder(graph).build();
|
||||
shards = storeService.reallocShards(shardGroup);
|
||||
Assert.assertEquals(1, shards.size());
|
||||
// 包含leader,leader不能被删除
|
||||
Assert.assertTrue(shards.contains(leader));
|
||||
|
||||
for (Metapb.Store store : stores) {
|
||||
storeService.removeStore(store.getId());
|
||||
}
|
||||
Assert.assertEquals(0, storeService.getStores("").size());
|
||||
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testSplitPartition() throws PDException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
|
||||
storeService.init(partitionService);
|
||||
partitionService.addInstructionListener(new PartitionInstructionListener() {
|
||||
|
||||
@Override
|
||||
public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferLeader(Metapb.Partition partition,
|
||||
TransferLeader transferLeader) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void splitPartition(Metapb.Partition partition,
|
||||
SplitPartition splitPartition) throws PDException {
|
||||
splitPartition.getNewPartitionList().forEach(p -> {
|
||||
System.out.println("SplitPartition " + p.getId() + " " + p.getStartKey() + "," +
|
||||
p.getEndKey());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePartition(Metapb.Partition partition,
|
||||
MovePartition movePartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPartition(Metapb.Partition partition,
|
||||
CleanPartition cleanPartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePartitionKeyRange(Metapb.Partition partition,
|
||||
PartitionKeyRange partitionKeyRange) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
});
|
||||
int count = 6;
|
||||
Metapb.Store[] stores = new Metapb.Store[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Metapb.Store store = Metapb.Store.newBuilder()
|
||||
.setId(0)
|
||||
.setAddress("127.0.0.1:850" + i)
|
||||
.setDeployPath("/data")
|
||||
.addLabels(Metapb.StoreLabel.newBuilder()
|
||||
.setKey("namespace")
|
||||
.setValue("default")
|
||||
.build())
|
||||
.build();
|
||||
stores[i] = storeService.register(store);
|
||||
System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
|
||||
}
|
||||
Assert.assertEquals(count, storeService.getStores().size());
|
||||
|
||||
Metapb.Graph graph = Metapb.Graph.newBuilder()
|
||||
.setGraphName("defaultGH")
|
||||
.build();
|
||||
Metapb.PartitionShard ptShard =
|
||||
partitionService.getPartitionByCode(graph.getGraphName(), 0);
|
||||
System.out.println(ptShard.getPartition().getId());
|
||||
{
|
||||
Metapb.Partition pt = ptShard.getPartition();
|
||||
System.out.println(pt.getId() + " " + pt.getStartKey() + "," + pt.getEndKey());
|
||||
}
|
||||
|
||||
Assert.assertEquals(6, storeService.getShardGroups().size());
|
||||
// storeService.splitShardGroups(ptShard.getPartition().getId(), 4);
|
||||
Assert.assertEquals(9, storeService.getShardGroups().size());
|
||||
storeService.getShardGroups().forEach(shardGroup -> {
|
||||
System.out.println("shardGroup id = " + shardGroup.getId());
|
||||
});
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testPartitionService() throws PDException, ExecutionException,
|
||||
InterruptedException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
int count = 6;
|
||||
Metapb.Store[] stores = new Metapb.Store[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Metapb.Store store = Metapb.Store.newBuilder()
|
||||
.setId(0)
|
||||
.setAddress(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<Metapb.Shard> shard = new AtomicReference<>();
|
||||
Metapb.PartitionShard ss =
|
||||
partitionService.getPartitionShardById(partition.getGraphName(), partition.getId());
|
||||
storeService.getShardList(partition.getId()).forEach(s -> {
|
||||
if (s.getRole() == Metapb.ShardRole.Leader) {
|
||||
Assert.assertNull(shard.get());
|
||||
shard.set(s);
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(leader.getStoreId(), shard.get().getStoreId());
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testMergeGraphParams() throws PDException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
|
||||
Metapb.Graph dfGraph = Metapb.Graph.newBuilder()
|
||||
|
||||
.setPartitionCount(
|
||||
pdConfig.getPartition().getTotalCount())
|
||||
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph1 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.setPartitionCount(20)
|
||||
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph2 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.setPartitionCount(7).build();
|
||||
Metapb.Graph graph3 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.build();
|
||||
Metapb.Graph graph4 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph2).build();
|
||||
Assert.assertEquals(graph2.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(graph2.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
|
||||
graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph3).build();
|
||||
Assert.assertEquals(graph3.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
|
||||
graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph4).build();
|
||||
Assert.assertEquals(graph4.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
}
|
||||
|
||||
// @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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,9 @@ package org.apache.hugegraph.pd;
|
|||
|
||||
import java.io.File;
|
||||
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
|
||||
@Useless
|
||||
public class UnitTestBase {
|
||||
public static boolean deleteDir(File dir) {
|
||||
if (dir.isDirectory()) {
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ 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.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
|
|
@ -161,6 +162,7 @@ public class PDClientTest extends BaseClientTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testUpdatePartitionLeader() {
|
||||
System.out.println("updatePartitionLeader start");
|
||||
|
|
@ -398,6 +400,7 @@ public class PDClientTest extends BaseClientTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testDelPartition() {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -15,15 +15,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd;
|
||||
package org.apache.hugegraph.pd.client;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hugegraph.pd.client.PDClient;
|
||||
import org.apache.hugegraph.pd.client.PDConfig;
|
||||
import org.apache.hugegraph.pd.client.PDPulse;
|
||||
import org.apache.hugegraph.pd.client.PDPulseImpl;
|
||||
import org.apache.hugegraph.pd.common.KVPair;
|
||||
import org.apache.hugegraph.pd.common.PDException;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
|
|
@ -20,8 +20,8 @@ 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.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -48,6 +48,7 @@ public class MainTest extends BaseCliToolsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void getConfig() throws PDException {
|
||||
Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad"});
|
||||
|
|
@ -63,6 +64,7 @@ public class MainTest extends BaseCliToolsTest {
|
|||
Main.main(new String[]{"127.0.0.1:8686", "config", "enableBatchLoad=false"});
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void getConfig2() throws PDException {
|
||||
Main.main(new String[]{"127.0.0.1:8686", "config", "shardCount"});
|
||||
|
|
|
|||
|
|
@ -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 @@ import lombok.extern.slf4j.Slf4j;
|
|||
@Suite.SuiteClasses({
|
||||
PartitionUtilsTest.class,
|
||||
PartitionCacheTest.class,
|
||||
MetadataKeyHelperTest.class,
|
||||
KvServiceTest.class,
|
||||
HgAssertTest.class,
|
||||
KVPairTest.class,
|
||||
IdServiceTest.class
|
||||
})
|
||||
|
||||
@Slf4j
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -22,11 +22,12 @@ import java.io.IOException;
|
|||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.hugegraph.pd.ConfigService;
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
||||
@Useless
|
||||
public class BaseCoreTest {
|
||||
|
||||
static org.apache.hugegraph.pd.config.PDConfig pdConfig;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ import org.apache.hugegraph.pd.ConfigService;
|
|||
import org.apache.hugegraph.pd.IdService;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
import org.apache.hugegraph.pd.rest.BaseServerTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ import org.apache.commons.io.FileUtils;
|
|||
import org.apache.hugegraph.pd.IdService;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.meta.IdMetaStore;
|
||||
import org.apache.hugegraph.pd.rest.BaseServerTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -15,10 +15,11 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import org.apache.hugegraph.pd.KvService;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.rest.BaseServerTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -15,13 +15,14 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hugegraph.pd.LogService;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
import org.apache.hugegraph.pd.rest.BaseServerTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -15,17 +15,20 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.apache.hugegraph.pd.PartitionService;
|
||||
import org.apache.hugegraph.pd.StoreNodeService;
|
||||
import org.apache.hugegraph.pd.TaskScheduleService;
|
||||
import org.apache.hugegraph.pd.common.PDException;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
// import org.junit.Test;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MonitorServiceTest {
|
||||
static PDConfig pdConfig;
|
||||
|
|
@ -35,6 +38,8 @@ public class MonitorServiceTest {
|
|||
pdConfig = new PDConfig() {{
|
||||
this.setClusterId(100);
|
||||
this.setPatrolInterval(1);
|
||||
this.setInitialStoreList("127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502," +
|
||||
"127.0.0.1:8503,127.0.0.1:8504,127.0.0.1:8505");
|
||||
}};
|
||||
|
||||
//pdConfig.setEtcd(new PDConfig().new Etcd() {{
|
||||
|
|
@ -51,6 +56,10 @@ public class MonitorServiceTest {
|
|||
this.setTotalCount(10);
|
||||
}});
|
||||
|
||||
pdConfig.setRaft(new PDConfig().new Raft() {{
|
||||
this.setEnable(false);
|
||||
}});
|
||||
|
||||
clearClusterData();
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +76,8 @@ public class MonitorServiceTest {
|
|||
//client.close();
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Ignore
|
||||
@Test
|
||||
public void testPatrolStores() throws PDException, InterruptedException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
|
|
@ -18,6 +18,7 @@
|
|||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import org.apache.hugegraph.pd.core.meta.MetadataKeyHelperTest;
|
||||
import org.apache.hugegraph.pd.core.store.HgKVStoreImplTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
|
|
@ -26,8 +27,19 @@ import lombok.extern.slf4j.Slf4j;
|
|||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
MetadataKeyHelperTest.class,
|
||||
HgKVStoreImplTest.class,
|
||||
ConfigServiceTest.class,
|
||||
IdServiceTest.class,
|
||||
KvServiceTest.class,
|
||||
LogServiceTest.class,
|
||||
MonitorServiceTest.class,
|
||||
PartitionServiceTest.class,
|
||||
StoreMonitorDataServiceTest.class,
|
||||
StoreNodeServiceNewTest.class,
|
||||
StoreNodeServiceTest.class,
|
||||
MetadataKeyHelperTest.class
|
||||
StoreServiceTest.class,
|
||||
TaskScheduleServiceTest.class
|
||||
})
|
||||
|
||||
@Slf4j
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
|
|
@ -42,7 +42,7 @@ import org.apache.hugegraph.pd.raft.RaftEngine;
|
|||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
public class PdTestBase {
|
||||
public class PDCoreTestBase {
|
||||
private static final String DATA_PATH = "/tmp/pd_data";
|
||||
private static PDConfig pdConfig;
|
||||
private static StoreNodeService storeNodeService;
|
||||
|
|
@ -15,10 +15,12 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.hugegraph.pd.PartitionService;
|
||||
|
|
@ -30,7 +32,7 @@ import org.apache.hugegraph.pd.grpc.pulse.CleanType;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class PartitionServiceTest extends PdTestBase {
|
||||
public class PartitionServiceTest extends PDCoreTestBase {
|
||||
|
||||
private PartitionService service;
|
||||
|
||||
|
|
@ -130,4 +132,22 @@ public class PartitionServiceTest extends PdTestBase {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPartitionHeartbeat() {
|
||||
List<Metapb.Shard> 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<Metapb.Shard> shardList2 = new ArrayList<>(stats.getShardList());
|
||||
Collections.shuffle(shardList2);
|
||||
shardList2.forEach(shard -> {
|
||||
System.out.println(shard.getStoreId());
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
|
@ -29,7 +29,7 @@ import org.apache.hugegraph.pd.grpc.Metapb;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StoreMonitorDataServiceTest extends PdTestBase {
|
||||
public class StoreMonitorDataServiceTest extends PDCoreTestBase {
|
||||
|
||||
StoreMonitorDataService service;
|
||||
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -26,7 +26,7 @@ import org.apache.hugegraph.pd.grpc.Metapb;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StoreNodeServiceNewTest extends PdTestBase {
|
||||
public class StoreNodeServiceNewTest extends PDCoreTestBase {
|
||||
private StoreNodeService service;
|
||||
|
||||
@Before
|
||||
|
|
@ -17,30 +17,94 @@
|
|||
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.hugegraph.pd.ConfigService;
|
||||
import org.apache.hugegraph.pd.PartitionInstructionListener;
|
||||
import org.apache.hugegraph.pd.PartitionService;
|
||||
import org.apache.hugegraph.pd.PartitionStatusListener;
|
||||
import org.apache.hugegraph.pd.StoreNodeService;
|
||||
import org.apache.hugegraph.pd.common.PDException;
|
||||
import org.apache.hugegraph.pd.config.PDConfig;
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.ChangeShard;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.CleanPartition;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.DbCompaction;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.MovePartition;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.PartitionKeyRange;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.SplitPartition;
|
||||
import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
public class StoreNodeServiceTest {
|
||||
static PDConfig pdConfig;
|
||||
|
||||
@Slf4j
|
||||
public class StoreNodeServiceTest extends BaseCoreTest {
|
||||
@BeforeClass
|
||||
public static void init() throws Exception {
|
||||
String path = "tmp/unitTest";
|
||||
deleteDirectory(new File(path));
|
||||
pdConfig = new PDConfig() {{
|
||||
this.setClusterId(100);
|
||||
this.setInitialStoreList(
|
||||
"127.0.0.1:8500,127.0.0.1:8501,127.0.0.1:8502,127.0.0.1:8503,127.0.0.1:8504," +
|
||||
"127.0.0.1:8505");
|
||||
}};
|
||||
|
||||
pdConfig.setStore(new PDConfig().new Store() {{
|
||||
this.setMaxDownTime(3600);
|
||||
this.setKeepAliveTimeout(3600);
|
||||
}});
|
||||
|
||||
pdConfig.setPartition(new PDConfig().new Partition() {{
|
||||
this.setShardCount(3);
|
||||
this.setMaxShardsPerStore(3);
|
||||
}});
|
||||
pdConfig.setRaft(new PDConfig().new Raft() {{
|
||||
this.setEnable(false);
|
||||
}});
|
||||
pdConfig.setDiscovery(new PDConfig().new Discovery());
|
||||
pdConfig.setDataPath(path);
|
||||
ConfigService configService = new ConfigService(pdConfig);
|
||||
pdConfig = configService.loadConfig();
|
||||
}
|
||||
|
||||
public static byte[] intToByteArray(int i) {
|
||||
byte[] result = new byte[4];
|
||||
result[0] = (byte) ((i >> 24) & 0xFF);
|
||||
result[1] = (byte) ((i >> 16) & 0xFF);
|
||||
result[2] = (byte) ((i >> 8) & 0xFF);
|
||||
result[3] = (byte) (i & 0xFF);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void deleteDirectory(File dir) {
|
||||
try {
|
||||
FileUtils.deleteDirectory(dir);
|
||||
} catch (IOException e) {
|
||||
System.out.printf("Failed to start ....,%s%n", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testStoreNodeService() throws PDException {
|
||||
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
|
||||
pdConfig.getInitialStoreMap().size() *
|
||||
(long) pdConfig.getInitialStoreMap().size() *
|
||||
pdConfig.getPartition().getMaxShardsPerStore()
|
||||
/ pdConfig.getPartition().getShardCount());
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
storeService.init(new PartitionService(pdConfig, storeService));
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
storeService.init(partitionService);
|
||||
|
||||
int count = 6;
|
||||
Metapb.Store[] stores = new Metapb.Store[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
|
|
@ -76,9 +140,9 @@ public class StoreNodeServiceTest extends BaseCoreTest {
|
|||
|
||||
|
||||
Assert.assertEquals(3, shards.size());
|
||||
// 设置leader
|
||||
|
||||
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
|
||||
storeService.getShardGroups().size());
|
||||
storeService.getShardGroups().size()); // 设置leader
|
||||
Metapb.Shard leader = Metapb.Shard.newBuilder(shards.get(0))
|
||||
.setRole(Metapb.ShardRole.Leader).build();
|
||||
shards = new ArrayList<>(shards);
|
||||
|
|
@ -115,5 +179,301 @@ public class StoreNodeServiceTest extends BaseCoreTest {
|
|||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testSplitPartition() throws PDException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
storeService.init(partitionService);
|
||||
partitionService.addInstructionListener(new PartitionInstructionListener() {
|
||||
|
||||
@Override
|
||||
public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferLeader(Metapb.Partition partition,
|
||||
TransferLeader transferLeader) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void splitPartition(Metapb.Partition partition,
|
||||
SplitPartition splitPartition) throws PDException {
|
||||
splitPartition.getNewPartitionList().forEach(p -> {
|
||||
System.out.println("SplitPartition " + p.getId() + " " + p.getStartKey() + "," +
|
||||
p.getEndKey());
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePartition(Metapb.Partition partition,
|
||||
MovePartition movePartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPartition(Metapb.Partition partition,
|
||||
CleanPartition cleanPartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePartitionKeyRange(Metapb.Partition partition,
|
||||
PartitionKeyRange partitionKeyRange) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
});
|
||||
int count = 6;
|
||||
Metapb.Store[] stores = new Metapb.Store[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Metapb.Store store = Metapb.Store.newBuilder()
|
||||
.setId(0)
|
||||
.setAddress("127.0.0.1:850" + i)
|
||||
.setDeployPath("/data")
|
||||
.addLabels(Metapb.StoreLabel.newBuilder()
|
||||
.setKey("namespace")
|
||||
.setValue("default")
|
||||
.build())
|
||||
.build();
|
||||
stores[i] = storeService.register(store);
|
||||
System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
|
||||
}
|
||||
Assert.assertEquals(count, storeService.getStores().size());
|
||||
|
||||
Metapb.Graph graph = Metapb.Graph.newBuilder()
|
||||
.setGraphName("defaultGH")
|
||||
.build();
|
||||
Metapb.PartitionShard ptShard =
|
||||
partitionService.getPartitionByCode(graph.getGraphName(), 0);
|
||||
System.out.println(ptShard.getPartition().getId());
|
||||
{
|
||||
Metapb.Partition pt = ptShard.getPartition();
|
||||
System.out.println(pt.getId() + " " + pt.getStartKey() + "," + pt.getEndKey());
|
||||
}
|
||||
|
||||
Assert.assertEquals(6, storeService.getShardGroups().size());
|
||||
// storeService.splitShardGroups(ptShard.getPartition().getId(), 4);
|
||||
Assert.assertEquals(9, storeService.getShardGroups().size());
|
||||
storeService.getShardGroups().forEach(shardGroup -> {
|
||||
System.out.println("shardGroup id = " + shardGroup.getId());
|
||||
});
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testPartitionService() throws PDException, ExecutionException,
|
||||
InterruptedException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
int count = 6;
|
||||
Metapb.Store[] stores = new Metapb.Store[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
Metapb.Store store = Metapb.Store.newBuilder()
|
||||
.setId(0)
|
||||
.setAddress("127.0.0.1:850" + i)
|
||||
.setDeployPath("/data")
|
||||
.addLabels(Metapb.StoreLabel.newBuilder()
|
||||
.setKey("namespace")
|
||||
.setValue("default")
|
||||
.build())
|
||||
.build();
|
||||
stores[i] = storeService.register(store);
|
||||
System.out.println("新注册store, id = " + Long.toHexString(stores[i].getId()));
|
||||
}
|
||||
Assert.assertEquals(count, storeService.getStores("").size());
|
||||
|
||||
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
|
||||
Metapb.Graph graph = Metapb.Graph.newBuilder()
|
||||
.setGraphName("defaultGH")
|
||||
|
||||
.setPartitionCount(10)
|
||||
.build();
|
||||
// 申请分区
|
||||
Metapb.PartitionShard[] partitions = new Metapb.PartitionShard[10];
|
||||
for (int i = 0; i < partitions.length; i++) {
|
||||
partitions[i] =
|
||||
partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
|
||||
Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
|
||||
}
|
||||
System.out.println(
|
||||
"分区数量: " + partitionService.getPartitions(graph.getGraphName()).size());
|
||||
|
||||
int[] caseNo = {0}; //1 测试增加shard, 2 //测试store下线
|
||||
|
||||
Metapb.Shard leader = null;
|
||||
int[] finalCaseNo = caseNo;
|
||||
|
||||
partitionService.addInstructionListener(new PartitionInstructionListener() {
|
||||
|
||||
@Override
|
||||
public void changeShard(Metapb.Partition partition, ChangeShard changeShard) throws
|
||||
PDException {
|
||||
switch (finalCaseNo[0]) {
|
||||
case 2:
|
||||
Assert.assertEquals(5, storeService.getShardGroup(partition.getId())
|
||||
.getShardsCount());
|
||||
break;
|
||||
case 3:
|
||||
storeService.getShardGroup(partition.getId()).getShardsList()
|
||||
.forEach(shard -> {
|
||||
Assert.assertNotEquals(shard.getStoreId(),
|
||||
stores[0].getId());
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void transferLeader(Metapb.Partition partition, TransferLeader transferLeader) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void splitPartition(Metapb.Partition partition, SplitPartition splitPartition) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dbCompaction(Metapb.Partition partition, DbCompaction dbCompaction) throws
|
||||
PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void movePartition(Metapb.Partition partition,
|
||||
MovePartition movePartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanPartition(Metapb.Partition partition,
|
||||
CleanPartition cleanPartition) throws PDException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changePartitionKeyRange(Metapb.Partition partition,
|
||||
PartitionKeyRange partitionKeyRange)
|
||||
throws PDException {
|
||||
|
||||
}
|
||||
});
|
||||
Metapb.Partition partition = partitions[0].getPartition();
|
||||
leader = Metapb.Shard.newBuilder(
|
||||
storeService.getShardGroup(partition.getId()).getShardsList().get(0)).build();
|
||||
Metapb.Shard finalLeader = leader;
|
||||
partitionService.addStatusListener(new PartitionStatusListener() {
|
||||
@Override
|
||||
public void onPartitionChanged(Metapb.Partition partition,
|
||||
Metapb.Partition newPartition) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPartitionRemoved(Metapb.Partition partition) {
|
||||
|
||||
}
|
||||
});
|
||||
// 测试修改图
|
||||
caseNo[0] = 1;
|
||||
partitionService.updateGraph(graph);
|
||||
for (int i = 0; i < partitions.length; i++) {
|
||||
partitions[i] =
|
||||
partitionService.getPartitionShard(graph.getGraphName(), intToByteArray(i));
|
||||
Assert.assertEquals(3, storeService.getShardGroup(i).getShardsCount());
|
||||
}
|
||||
|
||||
graph = Metapb.Graph.newBuilder(graph)
|
||||
.setGraphName("defaultGH")
|
||||
|
||||
.setPartitionCount(10)
|
||||
.build();
|
||||
caseNo[0] = 2;
|
||||
partitionService.updateGraph(graph);
|
||||
|
||||
// 测试store离线
|
||||
caseNo[0] = 3;
|
||||
partitionService.storeOffline(stores[0]);
|
||||
|
||||
|
||||
Metapb.PartitionStats stats = Metapb.PartitionStats.newBuilder()
|
||||
.addGraphName(partition.getGraphName())
|
||||
.setId(partition.getId())
|
||||
.setLeader(
|
||||
Metapb.Shard.newBuilder(leader)
|
||||
.setRole(
|
||||
Metapb.ShardRole.Leader))
|
||||
.build();
|
||||
// 测试leader飘移
|
||||
caseNo[0] = 4;
|
||||
partitionService.partitionHeartbeat(stats);
|
||||
AtomicReference<Metapb.Shard> shard = new AtomicReference<>();
|
||||
Metapb.PartitionShard ss =
|
||||
partitionService.getPartitionShardById(partition.getGraphName(), partition.getId());
|
||||
storeService.getShardList(partition.getId()).forEach(s -> {
|
||||
if (s.getRole() == Metapb.ShardRole.Leader) {
|
||||
Assert.assertNull(shard.get());
|
||||
shard.set(s);
|
||||
}
|
||||
});
|
||||
|
||||
Assert.assertEquals(leader.getStoreId(), shard.get().getStoreId());
|
||||
|
||||
}
|
||||
|
||||
// @Test
|
||||
public void testMergeGraphParams() throws PDException {
|
||||
StoreNodeService storeService = new StoreNodeService(pdConfig);
|
||||
PartitionService partitionService = new PartitionService(pdConfig, storeService);
|
||||
|
||||
Metapb.Graph dfGraph = Metapb.Graph.newBuilder()
|
||||
|
||||
.setPartitionCount(
|
||||
pdConfig.getPartition().getTotalCount())
|
||||
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph1 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.setPartitionCount(20)
|
||||
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph2 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.setPartitionCount(7).build();
|
||||
Metapb.Graph graph3 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.build();
|
||||
Metapb.Graph graph4 = Metapb.Graph.newBuilder()
|
||||
.setGraphName("test")
|
||||
.build();
|
||||
|
||||
Metapb.Graph graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph2).build();
|
||||
Assert.assertEquals(graph2.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(graph2.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
|
||||
graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph3).build();
|
||||
Assert.assertEquals(graph3.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
|
||||
graph = Metapb.Graph.newBuilder(dfGraph).mergeFrom(graph4).build();
|
||||
Assert.assertEquals(graph4.getGraphName(), graph.getGraphName());
|
||||
|
||||
Assert.assertEquals(dfGraph.getPartitionCount(), graph.getPartitionCount());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
|
@ -33,7 +33,9 @@ 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.apache.hugegraph.pd.rest.BaseServerTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StoreServiceTest {
|
||||
|
|
@ -287,6 +289,7 @@ public class StoreServiceTest {
|
|||
final Metapb.Store result = this.service.updateStore(store);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testStoreTurnoff() throws Exception {
|
||||
// Setup
|
||||
|
|
@ -491,6 +494,7 @@ public class StoreServiceTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Ignore
|
||||
@Test
|
||||
public void testGetTombStores() throws Exception {
|
||||
// Setup
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.core;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ import org.apache.hugegraph.pd.grpc.Metapb;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TaskScheduleServiceTest extends PdTestBase {
|
||||
public class TaskScheduleServiceTest extends PDCoreTestBase {
|
||||
|
||||
TaskScheduleService service;
|
||||
|
||||
|
|
@ -17,8 +17,10 @@
|
|||
|
||||
package org.apache.hugegraph.pd.core.meta;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import org.apache.hugegraph.pd.grpc.Metapb;
|
||||
import org.apache.hugegraph.pd.meta.MetadataKeyHelper;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -31,4 +33,194 @@ public class MetadataKeyHelperTest {
|
|||
var key2 = MetadataKeyHelper.getMoveTaskPrefix("foo");
|
||||
assertArrayEquals(key2, "TASK_MOVE/foo".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStoreInfoKey() {
|
||||
assertThat(MetadataKeyHelper.getStoreInfoKey(0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActiveStoreKey() {
|
||||
assertThat(MetadataKeyHelper.getActiveStoreKey(0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetActiveStorePrefix() {
|
||||
assertThat(MetadataKeyHelper.getActiveStorePrefix()).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStorePrefix() {
|
||||
assertThat(MetadataKeyHelper.getStorePrefix()).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStoreStatusKey() {
|
||||
assertThat(MetadataKeyHelper.getStoreStatusKey(0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShardGroupKey() {
|
||||
assertThat(MetadataKeyHelper.getShardGroupKey(0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShardGroupPrefix() {
|
||||
assertThat(MetadataKeyHelper.getShardGroupPrefix()).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPartitionKey() {
|
||||
assertThat(MetadataKeyHelper.getPartitionKey("graphName", 0)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPartitionPrefix() {
|
||||
assertThat(MetadataKeyHelper.getPartitionPrefix("graphName")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShardKey() {
|
||||
assertThat(MetadataKeyHelper.getShardKey(0L, 0)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShardPrefix() {
|
||||
assertThat(MetadataKeyHelper.getShardPrefix(0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGraphKey() {
|
||||
assertThat(MetadataKeyHelper.getGraphKey("graphName")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGraphPrefix() {
|
||||
assertThat(MetadataKeyHelper.getGraphPrefix()).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPartitionStatusKey() {
|
||||
assertThat(MetadataKeyHelper.getPartitionStatusKey("graphName",
|
||||
0)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPartitionStatusPrefixKey() {
|
||||
assertThat(MetadataKeyHelper.getPartitionStatusPrefixKey(
|
||||
"graphName")).contains(MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetGraphSpaceKey() {
|
||||
assertThat(MetadataKeyHelper.getGraphSpaceKey("graphSpace")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPdConfigKey() {
|
||||
assertThat(MetadataKeyHelper.getPdConfigKey("configKey")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQueueItemPrefix() {
|
||||
assertThat(MetadataKeyHelper.getQueueItemPrefix()).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetQueueItemKey() {
|
||||
assertThat(MetadataKeyHelper.getQueueItemKey("itemId")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSpitTaskKey() {
|
||||
assertThat(MetadataKeyHelper.getSplitTaskKey("graphName", 0)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetSpitTaskPrefix() {
|
||||
assertThat(MetadataKeyHelper.getSplitTaskPrefix("graph0")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLogKey() {
|
||||
// Setup
|
||||
final Metapb.LogRecord record = Metapb.LogRecord.newBuilder()
|
||||
.setAction("value")
|
||||
.setTimestamp(0L)
|
||||
.build();
|
||||
|
||||
// Run the test
|
||||
final byte[] result = MetadataKeyHelper.getLogKey(record);
|
||||
|
||||
// Verify the results
|
||||
assertThat(result).contains(MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetLogKeyPrefix() {
|
||||
assertThat(MetadataKeyHelper.getLogKeyPrefix("action", 0L)).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKVPrefix() {
|
||||
assertThat(MetadataKeyHelper.getKVPrefix("prefix", "key")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKVTTLPrefix() {
|
||||
assertThat(MetadataKeyHelper.getKVTTLPrefix("ttlPrefix", "prefix",
|
||||
"key")).contains(
|
||||
MetadataKeyHelper.getDelimiter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKVWatchKeyPrefix1() {
|
||||
assertThat(
|
||||
MetadataKeyHelper.getKVWatchKeyPrefix("key", "watchDelimiter",
|
||||
0L)).contains(
|
||||
String.valueOf(MetadataKeyHelper.getDelimiter()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetKVWatchKeyPrefix2() {
|
||||
assertThat(MetadataKeyHelper.getKVWatchKeyPrefix("key",
|
||||
"watchDelimiter")).contains(
|
||||
String.valueOf(MetadataKeyHelper.getDelimiter()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDelimiter() {
|
||||
assertThat(MetadataKeyHelper.getDelimiter()).isEqualTo('/');
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStringBuilderHelper() {
|
||||
try {
|
||||
MetadataKeyHelper.getStringBuilderHelper();
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.store;
|
||||
package org.apache.hugegraph.pd.core.store;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
|
@ -24,8 +24,11 @@ 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.apache.hugegraph.pd.store.HgKVStore;
|
||||
import org.apache.hugegraph.pd.store.HgKVStoreImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HgKVStoreImplTest {
|
||||
static final String testPath = "tmp/test";
|
||||
|
|
@ -43,7 +46,7 @@ public class HgKVStoreImplTest {
|
|||
}};
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void Test() throws PDException {
|
||||
HgKVStore kvStore = new HgKVStoreImpl();
|
||||
kvStore.init(pdConfig);
|
||||
|
|
@ -63,9 +66,11 @@ public class HgKVStoreImplTest {
|
|||
|
||||
kvStore.removeByPrefix("k".getBytes());
|
||||
Assert.assertEquals(0, kvStore.scanPrefix("k".getBytes()).size());
|
||||
|
||||
kvStore.close();
|
||||
}
|
||||
|
||||
// @Test
|
||||
@Test
|
||||
public void TestSnapshot() throws PDException {
|
||||
HgKVStore kvStore = new HgKVStoreImpl();
|
||||
kvStore.init(pdConfig);
|
||||
|
|
@ -101,5 +106,7 @@ public class HgKVStoreImplTest {
|
|||
kvStore.put(key, value);
|
||||
}
|
||||
Assert.assertEquals(200, kvStore.scanPrefix("k".getBytes()).size());
|
||||
|
||||
kvStore.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -17,10 +17,11 @@
|
|||
|
||||
package org.apache.hugegraph.pd.grpc;
|
||||
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
|
||||
@Useless
|
||||
public class BaseGrpcTest {
|
||||
|
||||
@BeforeClass
|
||||
|
|
|
|||
|
|
@ -17,12 +17,13 @@
|
|||
|
||||
package org.apache.hugegraph.pd.grpc;
|
||||
|
||||
import org.apache.hugegraph.pd.common.Useless;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Useless
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
})
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.rest;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.http.HttpClient;
|
||||
|
|
@ -15,28 +15,19 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.rest;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@RunWith(Suite.class)
|
||||
@Suite.SuiteClasses({
|
||||
RestApiTest.class,
|
||||
ConfigServiceTest.class,
|
||||
IdServiceTest.class,
|
||||
KvServiceTest.class,
|
||||
LogServiceTest.class,
|
||||
StoreServiceTest.class,
|
||||
StoreNodeServiceNewTest.class,
|
||||
StoreMonitorDataServiceTest.class,
|
||||
TaskScheduleServiceTest.class,
|
||||
PartitionServiceTest.class
|
||||
})
|
||||
|
||||
@Slf4j
|
||||
public class ServerSuiteTest {
|
||||
public class PDRestSuiteTest {
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.hugegraph.pd.service;
|
||||
package org.apache.hugegraph.pd.rest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
|
|
@ -245,7 +245,7 @@
|
|||
</build>
|
||||
</profile>
|
||||
<profile>
|
||||
<id>pd-service-test</id>
|
||||
<id>pd-rest-test</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
|
|
@ -257,7 +257,7 @@
|
|||
<version>2.20</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>pd-service-test</id>
|
||||
<id>pd-rest-test</id>
|
||||
<goals>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
|
|
|
|||
Loading…
Reference in New Issue