Search in sources :

Example 16 with Closure

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

the class IteratorImplTest method testRunTheRestClosureWithError.

@Test
public void testRunTheRestClosureWithError() throws Exception {
    testSetErrorAndRollback();
    for (final Closure closure : this.closures) {
        final MockClosure mc = (MockClosure) closure;
        assertNull(mc.s);
    }
    this.iter.runTheRestClosureWithError();
    Thread.sleep(500);
    int i = 0;
    for (final Closure closure : this.closures) {
        i++;
        final MockClosure mc = (MockClosure) closure;
        if (i < 7) {
            assertNull(mc.s);
        } else {
            final Status s = mc.s;
            assertEquals(RaftError.ESTATEMACHINE.getNumber(), s.getCode());
            assertEquals("StateMachine meet critical error when applying one or more tasks since index=6, Status[UNKNOWN<-1>: test]", s.getErrorMsg());
        }
    }
}
Also used : Status(org.apache.ignite.raft.jraft.Status) Closure(org.apache.ignite.raft.jraft.Closure) Test(org.junit.jupiter.api.Test)

Example 17 with Closure

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

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));
    if (asyncContext != null)
        asyncContext.getNodeManager().add(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(org.apache.ignite.raft.jraft.Closure) NodeId(org.apache.ignite.raft.jraft.entity.NodeId) NodeOptions(org.apache.ignite.raft.jraft.option.NodeOptions) PeerId(org.apache.ignite.raft.jraft.entity.PeerId) Test(org.junit.jupiter.api.Test)

Example 18 with Closure

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

the class RemovePeerRequestProcessorTest method verify.

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