use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class RemovePeerRequestProcessorTest method verify.
@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
assertEquals(interest, RemovePeerRequest.class.getName());
Mockito.verify(node).removePeer(eq(new PeerId("localhost", 8082)), doneArg.capture());
Closure done = doneArg.getValue();
assertNotNull(done);
done.run(Status.OK());
assertNotNull(this.asyncContext.getResponseObject());
assertEquals("[localhost:8081, localhost:8082, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getOldPeersList().toString());
assertEquals("[localhost:8081, localhost:8083]", this.asyncContext.as(RemovePeerResponse.class).getNewPeersList().toString());
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class DefaultRheaKVStore method getLeaderByRegionEngine.
private Endpoint getLeaderByRegionEngine(final long regionId) {
final RegionEngine regionEngine = getRegionEngine(regionId);
if (regionEngine != null) {
final PeerId leader = regionEngine.getLeaderId();
if (leader != null) {
final String raftGroupId = JRaftHelper.getJRaftGroupId(this.pdClient.getClusterName(), regionId);
RouteTable.getInstance().updateLeader(raftGroupId, leader);
return leader.getEndpoint();
}
}
return null;
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class NodeRequestProcessorTest method testOK.
@Test
public void testOK() {
Node node = Mockito.mock(Node.class, withSettings().extraInterfaces(RaftServerService.class));
Mockito.when(node.getGroupId()).thenReturn("test");
PeerId peerId = new PeerId("localhost", 8081);
Mockito.when(node.getNodeId()).thenReturn(new NodeId("test", peerId));
NodeManager.getInstance().addAddress(peerId.getEndpoint());
NodeManager.getInstance().add(node);
this.processor.handleRequest(asyncContext, TestUtils.createPingRequest());
ErrorResponse resp = (ErrorResponse) asyncContext.getResponseObject();
assertNotNull(resp);
assertEquals(0, resp.getErrorCode());
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class StoreEngine method inConfiguration.
private boolean inConfiguration(final String curr, final String all) {
final PeerId currPeer = new PeerId();
if (!currPeer.parse(curr)) {
return false;
}
final Configuration allConf = new Configuration();
if (!allConf.parse(all)) {
return false;
}
return allConf.contains(currPeer) || allConf.getLearners().contains(currPeer);
}
use of com.alipay.sofa.jraft.entity.PeerId in project sofa-jraft by sofastack.
the class RegionEngine method transferLeadershipTo.
public boolean transferLeadershipTo(final Endpoint endpoint) {
final PeerId peerId = new PeerId(endpoint, 0);
final Status status = this.node.transferLeadershipTo(peerId);
final boolean isOk = status.isOk();
if (isOk) {
LOG.info("Transfer-leadership succeeded: [{} --> {}].", this.storeEngine.getSelfEndpoint(), endpoint);
} else {
LOG.error("Transfer-leadership failed: {}, [{} --> {}].", status, this.storeEngine.getSelfEndpoint(), endpoint);
}
return isOk;
}
Aggregations