Search in sources :

Example 1 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class IteratorImpl method runTheRestClosureWithError.

protected void runTheRestClosureWithError() {
    for (long i = Math.max(this.currentIndex, this.firstClosureIndex); i <= this.committedIndex; i++) {
        final Closure done = this.closures.get((int) (i - this.firstClosureIndex));
        if (done != null) {
            Requires.requireNonNull(this.error, "error");
            Requires.requireNonNull(this.error.getStatus(), "error.status");
            final Status status = this.error.getStatus();
            Utils.runClosureInThread(options.getCommonExecutor(), done, status);
        }
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Closure(org.apache.ignite.raft.jraft.Closure)

Example 2 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class AddPeerRequestProcessorTest method verify.

@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
    assertEquals(AddPeerRequest.class.getName(), interest);
    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).oldPeersList().toString());
    assertEquals("[localhost:8081, localhost:8082, localhost:8083, test:8181]", this.asyncContext.as(AddPeerResponse.class).newPeersList().toString());
}
Also used : Closure(org.apache.ignite.raft.jraft.Closure) AddPeerRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerRequest) AddPeerResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.AddPeerResponse) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 3 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class ChangePeersRequestProcessorTest method verify.

@Override
public void verify(String interest, Node node, ArgumentCaptor<Closure> doneArg) {
    assertEquals(ChangePeersRequest.class.getName(), interest);
    Mockito.verify(node).changePeers(eq(JRaftUtils.getConfiguration("localhost:8084,localhost:8085")), 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(ChangePeersResponse.class).oldPeersList().toString());
    assertEquals("[localhost:8084, localhost:8085]", this.asyncContext.as(ChangePeersResponse.class).newPeersList().toString());
}
Also used : ChangePeersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersRequest) Closure(org.apache.ignite.raft.jraft.Closure) ChangePeersResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.ChangePeersResponse)

Example 4 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

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).oldLearnersList().toString());
    assertEquals("[learner:8081, learner:8083]", this.asyncContext.as(LearnersOpResponse.class).newLearnersList().toString());
}
Also used : RemoveLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.RemoveLearnersRequest) Closure(org.apache.ignite.raft.jraft.Closure) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Example 5 with Closure

use of org.apache.ignite.raft.jraft.Closure in project ignite-3 by apache.

the class ResetLearnersRequestProcessorTest method verify.

@Override
public void verify(final String interest, final Node node, final ArgumentCaptor<Closure> doneArg) {
    assertEquals(interest, ResetLearnersRequest.class.getName());
    Mockito.verify(node).resetLearners(eq(Arrays.asList(new PeerId("learner", 8082), new PeerId("test", 8182), 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).oldLearnersList().toString());
    assertEquals("[learner:8082, test:8182, test:8183]", this.asyncContext.as(LearnersOpResponse.class).newLearnersList().toString());
}
Also used : Closure(org.apache.ignite.raft.jraft.Closure) LearnersOpResponse(org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse) ResetLearnersRequest(org.apache.ignite.raft.jraft.rpc.CliRequests.ResetLearnersRequest) PeerId(org.apache.ignite.raft.jraft.entity.PeerId)

Aggregations

Closure (org.apache.ignite.raft.jraft.Closure)18 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)9 Status (org.apache.ignite.raft.jraft.Status)8 Test (org.junit.jupiter.api.Test)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 ArrayList (java.util.ArrayList)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 CatchUpClosure (org.apache.ignite.raft.jraft.closure.CatchUpClosure)3 ReadIndexClosure (org.apache.ignite.raft.jraft.closure.ReadIndexClosure)3 SynchronizedClosure (org.apache.ignite.raft.jraft.closure.SynchronizedClosure)3 Configuration (org.apache.ignite.raft.jraft.conf.Configuration)3 LogEntry (org.apache.ignite.raft.jraft.entity.LogEntry)3 LogId (org.apache.ignite.raft.jraft.entity.LogId)3 NodeId (org.apache.ignite.raft.jraft.entity.NodeId)3 NodeOptions (org.apache.ignite.raft.jraft.option.NodeOptions)3 LearnersOpResponse (org.apache.ignite.raft.jraft.rpc.CliRequests.LearnersOpResponse)3 RpcRequestClosure (org.apache.ignite.raft.jraft.rpc.RpcRequestClosure)3 RpcResponseClosure (org.apache.ignite.raft.jraft.rpc.RpcResponseClosure)3 EventHandler (com.lmax.disruptor.EventHandler)2 EventTranslator (com.lmax.disruptor.EventTranslator)2