Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pd-store): intro Useless annotation & refactor and mark the failed tests in hg-pd-test #2480

Merged
merged 18 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,7 +129,11 @@
* @throws PDException when io error
*/
public int getPartitionCount() throws PDException {
return getPDConfig().getPartitionCount();
Metapb.PDConfig config = getPDConfig();
if (Objects.nonNull(config)) {
return config.getPartitionCount();

Check warning on line 134 in hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-pd/hg-pd-core/src/main/java/org/apache/hugegraph/pd/ConfigService.java#L134

Added line #L134 was not covered by tests
}
return pdConfig.getInitialPartitionCount();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ public void shutDown() {
}

public boolean isLeader() {
if (Objects.isNull(this.raftNode)) {
return false;
}
return this.raftNode.isLeader(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
import org.junit.Assert;
import org.junit.BeforeClass;

// import org.junit.Test;

public class MonitorServiceTest {
static PDConfig pdConfig;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
import org.apache.hugegraph.pd.common.KVPair;
import org.apache.hugegraph.pd.common.PartitionCache;
import org.apache.hugegraph.pd.grpc.Metapb;
import org.junit.Test;

import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.TreeRangeMap;

public class PartitionCacheTest {

// @Test
@Test
public void test() {
PartitionCache cache = new PartitionCache();
for (int i = 0; i < 10; i++) {
Expand All @@ -51,7 +52,7 @@ public void test() {
}


// @Test
@Test
public void test1() {
Map<String, RangeMap<Long, Integer>> keyToPartIdCache = new HashMap<>();
// graphName + PartitionID组成key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.hugegraph.pd.grpc.pulse.TransferLeader;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class StoreNodeServiceTest {
static PDConfig pdConfig;
Expand Down Expand Up @@ -87,13 +88,16 @@ public static void deleteDirectory(File dir) {
}
}

// @Test
@Test
public void testStoreNodeService() throws PDException {
Assert.assertEquals(pdConfig.getPartition().getTotalCount(),
(long) pdConfig.getInitialStoreMap().size() *
pdConfig.getPartition().getMaxShardsPerStore()
/ pdConfig.getPartition().getShardCount());
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
storeService.init(partitionService);

int count = 6;
Metapb.Store[] stores = new Metapb.Store[count];
for (int i = 0; i < count; i++) {
Expand Down Expand Up @@ -168,7 +172,7 @@ public void testStoreNodeService() throws PDException {

}

// @Test
@Test
public void testSplitPartition() throws PDException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
Expand Down Expand Up @@ -258,7 +262,7 @@ public void changePartitionKeyRange(Metapb.Partition partition,
});
}

// @Test
@Test
public void testPartitionService() throws PDException, ExecutionException,
InterruptedException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
Expand All @@ -267,7 +271,7 @@ public void testPartitionService() throws PDException, ExecutionException,
for (int i = 0; i < count; i++) {
Metapb.Store store = Metapb.Store.newBuilder()
.setId(0)
.setAddress(String.valueOf(i))
.setAddress("127.0.0.1:850" + i)
.setDeployPath("/data")
.addLabels(Metapb.StoreLabel.newBuilder()
.setKey("namespace")
Expand All @@ -281,6 +285,7 @@ public void testPartitionService() throws PDException, ExecutionException,


PartitionService partitionService = new PartitionService(pdConfig, storeService);
storeService.init(partitionService);

Metapb.Graph graph = Metapb.Graph.newBuilder()
.setGraphName("defaultGH")
Expand Down Expand Up @@ -420,7 +425,7 @@ public void onPartitionRemoved(Metapb.Partition partition) {

}

// @Test
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a test is hard to ensure the meaning or currently we can't run it well, we could add @Ignore for it rather than comment @Test (so
that we could search ignore in future)

maybe we could also add a annotation @useless for other useless classes/method?

@Test
public void testMergeGraphParams() throws PDException {
StoreNodeService storeService = new StoreNodeService(pdConfig);
PartitionService partitionService = new PartitionService(pdConfig, storeService);
Expand Down Expand Up @@ -466,20 +471,4 @@ public void testMergeGraphParams() throws PDException {
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]);
}
}
}

This file was deleted.

Loading