Search in sources :

Example 1 with NodeId

use of com.alipay.sofa.jraft.entity.NodeId in project sofa-jraft by sofastack.

the class AbstractCliRequestProcessorTest method testHandleRequest.

@Test
public void testHandleRequest() {
    this.mockNodes(3);
    Mockito.when(this.node.getGroupId()).thenReturn(this.groupId);
    PeerId peerId = new PeerId();
    peerId.parse(this.peerIdStr);
    Mockito.when(this.node.getOptions()).thenReturn(new NodeOptions());
    Mockito.when(this.node.getNodeId()).thenReturn(new NodeId("test", peerId));
    NodeManager.getInstance().addAddress(peerId.getEndpoint());
    NodeManager.getInstance().add(this.node);
    BaseCliRequestProcessor<T> processor = newProcessor();
    processor.handleRequest(this.asyncContext, createRequest(this.groupId, peerId));
    ArgumentCaptor<Closure> doneArg = ArgumentCaptor.forClass(Closure.class);
    verify(processor.interest(), this.node, doneArg);
}
Also used : Closure(com.alipay.sofa.jraft.Closure) NodeId(com.alipay.sofa.jraft.entity.NodeId) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions) PeerId(com.alipay.sofa.jraft.entity.PeerId) Test(org.junit.Test)

Example 2 with NodeId

use of com.alipay.sofa.jraft.entity.NodeId in project sofa-jraft by sofastack.

the class BaseCliRequestProcessorTest method mockNode.

private Node mockNode(boolean disableCli) {
    Node node = Mockito.mock(Node.class);
    Mockito.when(node.getGroupId()).thenReturn("test");
    Mockito.when(node.getNodeId()).thenReturn(new NodeId("test", this.peer.copy()));
    NodeOptions opts = new NodeOptions();
    opts.setDisableCli(disableCli);
    Mockito.when(node.getOptions()).thenReturn(opts);
    NodeManager.getInstance().addAddress(this.peer.getEndpoint());
    NodeManager.getInstance().add(node);
    return node;
}
Also used : Node(com.alipay.sofa.jraft.Node) NodeId(com.alipay.sofa.jraft.entity.NodeId) NodeOptions(com.alipay.sofa.jraft.option.NodeOptions)

Example 3 with NodeId

use of com.alipay.sofa.jraft.entity.NodeId 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());
}
Also used : Node(com.alipay.sofa.jraft.Node) NodeId(com.alipay.sofa.jraft.entity.NodeId) RaftServerService(com.alipay.sofa.jraft.rpc.RaftServerService) PeerId(com.alipay.sofa.jraft.entity.PeerId) ErrorResponse(com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse) Test(org.junit.Test)

Example 4 with NodeId

use of com.alipay.sofa.jraft.entity.NodeId in project sofa-jraft by sofastack.

the class BaseNodeRequestProcessorTest method mockNode.

protected PeerId mockNode() {
    Mockito.when(node.getGroupId()).thenReturn(this.groupId);
    final PeerId peerId = new PeerId();
    peerId.parse(this.peerIdStr);
    Mockito.when(node.getNodeId()).thenReturn(new NodeId(groupId, peerId));
    NodeManager.getInstance().addAddress(peerId.getEndpoint());
    NodeManager.getInstance().add(node);
    return peerId;
}
Also used : NodeId(com.alipay.sofa.jraft.entity.NodeId) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 5 with NodeId

use of com.alipay.sofa.jraft.entity.NodeId in project sofa-jraft by sofastack.

the class ReplicatorGroupTest method setup.

@Before
public void setup() {
    this.timerManager = new TimerManager(5);
    this.replicatorGroup = new ReplicatorGroupImpl();
    final ReplicatorGroupOptions rgOpts = new ReplicatorGroupOptions();
    rgOpts.setHeartbeatTimeoutMs(heartbeatTimeout(this.options.getElectionTimeoutMs()));
    rgOpts.setElectionTimeoutMs(this.options.getElectionTimeoutMs());
    rgOpts.setLogManager(this.logManager);
    rgOpts.setBallotBox(this.ballotBox);
    rgOpts.setNode(this.node);
    rgOpts.setRaftRpcClientService(this.rpcService);
    rgOpts.setSnapshotStorage(this.snapshotStorage);
    rgOpts.setRaftOptions(this.raftOptions);
    rgOpts.setTimerManager(this.timerManager);
    Mockito.when(this.logManager.getLastLogIndex()).thenReturn(10L);
    Mockito.when(this.logManager.getTerm(10)).thenReturn(1L);
    Mockito.when(this.node.getNodeMetrics()).thenReturn(new NodeMetrics(false));
    Mockito.when(this.node.getNodeId()).thenReturn(new NodeId("test", new PeerId("localhost", 8081)));
    mockSendEmptyEntries();
    assertTrue(this.replicatorGroup.init(this.node.getNodeId(), rgOpts));
}
Also used : ReplicatorGroupOptions(com.alipay.sofa.jraft.option.ReplicatorGroupOptions) NodeId(com.alipay.sofa.jraft.entity.NodeId) PeerId(com.alipay.sofa.jraft.entity.PeerId) Before(org.junit.Before)

Aggregations

NodeId (com.alipay.sofa.jraft.entity.NodeId)8 PeerId (com.alipay.sofa.jraft.entity.PeerId)5 Node (com.alipay.sofa.jraft.Node)3 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)3 Test (org.junit.Test)3 ReplicatorGroupOptions (com.alipay.sofa.jraft.option.ReplicatorGroupOptions)2 ErrorResponse (com.alipay.sofa.jraft.rpc.RpcRequests.ErrorResponse)2 Closure (com.alipay.sofa.jraft.Closure)1 Status (com.alipay.sofa.jraft.Status)1 ConfigurationEntry (com.alipay.sofa.jraft.conf.ConfigurationEntry)1 ConfigurationManager (com.alipay.sofa.jraft.conf.ConfigurationManager)1 LogId (com.alipay.sofa.jraft.entity.LogId)1 BallotBoxOptions (com.alipay.sofa.jraft.option.BallotBoxOptions)1 ReadOnlyServiceOptions (com.alipay.sofa.jraft.option.ReadOnlyServiceOptions)1 RaftServerService (com.alipay.sofa.jraft.rpc.RaftServerService)1 DefaultRaftClientService (com.alipay.sofa.jraft.rpc.impl.core.DefaultRaftClientService)1 DisruptorMetricSet (com.alipay.sofa.jraft.util.DisruptorMetricSet)1 Endpoint (com.alipay.sofa.jraft.util.Endpoint)1 NamedThreadFactory (com.alipay.sofa.jraft.util.NamedThreadFactory)1 RepeatedTimer (com.alipay.sofa.jraft.util.RepeatedTimer)1