Search in sources :

Example 6 with PeerId

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

the class TransferLeadershipRequestProcessorTest method verify.

@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
    assertEquals(TransferLeaderRequest.class.getName(), interest);
    Mockito.verify(node).transferLeadershipTo(new PeerId("localhost", 8082));
    assertNotNull(asyncContext.getResponseObject());
}
Also used : TransferLeaderRequest(com.alipay.sofa.jraft.rpc.CliRequests.TransferLeaderRequest) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 7 with PeerId

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

the class LocalRaftMetaStorageTest method testSaveFail.

@Test
public void testSaveFail() throws IOException {
    FileUtils.deleteDirectory(new File(this.path));
    assertFalse(this.raftMetaStorage.setVotedFor(new PeerId("localhost", 8081)));
    Mockito.verify(this.node, Mockito.times(1)).onError((RaftException) Mockito.any());
}
Also used : File(java.io.File) PeerId(com.alipay.sofa.jraft.entity.PeerId) Test(org.junit.Test) BaseStorageTest(com.alipay.sofa.jraft.storage.BaseStorageTest)

Example 8 with PeerId

use of com.alipay.sofa.jraft.entity.PeerId 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 9 with PeerId

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

the class AddPeerRequestProcessorTest method verify.

@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
    assertEquals(interest, AddPeerRequest.class.getName());
    Mockito.verify(node).addPeer(eq(new PeerId("test", 8181)), 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(AddPeerResponse.class).getOldPeersList().toString());
    assertEquals("[localhost:8081, localhost:8082, localhost:8083, test:8181]", this.asyncContext.as(AddPeerResponse.class).getNewPeersList().toString());
}
Also used : Closure(com.alipay.sofa.jraft.Closure) AddPeerRequest(com.alipay.sofa.jraft.rpc.CliRequests.AddPeerRequest) AddPeerResponse(com.alipay.sofa.jraft.rpc.CliRequests.AddPeerResponse) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 10 with PeerId

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

the class RemoveLearnersRequestProcessorTest method verify.

@Override
public void verify(final String interest, final Node node, final ArgumentCaptor<Closure> doneArg) {
    assertEquals(interest, RemoveLearnersRequest.class.getName());
    Mockito.verify(node).removeLearners(eq(Arrays.asList(new PeerId("learner", 8082), new PeerId("test", 8183))), doneArg.capture());
    Closure done = doneArg.getValue();
    assertNotNull(done);
    done.run(Status.OK());
    assertNotNull(this.asyncContext.getResponseObject());
    assertEquals("[learner:8081, learner:8082, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).getOldLearnersList().toString());
    assertEquals("[learner:8081, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).getNewLearnersList().toString());
}
Also used : RemoveLearnersRequest(com.alipay.sofa.jraft.rpc.CliRequests.RemoveLearnersRequest) Closure(com.alipay.sofa.jraft.Closure) LearnersOpResponse(com.alipay.sofa.jraft.rpc.CliRequests.LearnersOpResponse) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Aggregations

PeerId (com.alipay.sofa.jraft.entity.PeerId)236 Test (org.junit.Test)107 Node (com.alipay.sofa.jraft.Node)70 Configuration (com.alipay.sofa.jraft.conf.Configuration)54 Status (com.alipay.sofa.jraft.Status)49 Endpoint (com.alipay.sofa.jraft.util.Endpoint)43 ArrayList (java.util.ArrayList)32 CountDownLatch (java.util.concurrent.CountDownLatch)28 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)24 LogId (com.alipay.sofa.jraft.entity.LogId)17 Message (com.google.protobuf.Message)15 ByteBuffer (java.nio.ByteBuffer)15 Task (com.alipay.sofa.jraft.entity.Task)13 File (java.io.File)12 SynchronizedClosure (com.alipay.sofa.jraft.closure.SynchronizedClosure)11 LogEntry (com.alipay.sofa.jraft.entity.LogEntry)11 JRaftException (com.alipay.sofa.jraft.error.JRaftException)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)9 RaftGroupService (com.alipay.sofa.jraft.RaftGroupService)8