Search in sources :

Example 1 with RpcContext

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

the class AppendEntriesRequestProcessorTest method testSendSequenceResponse.

@Test
public void testSendSequenceResponse() {
    mockNode();
    final AppendEntriesRequestProcessor processor = (AppendEntriesRequestProcessor) newProcessor();
    final PeerPair pair = processor.pairOf(this.peerIdStr, this.serverId);
    processor.getOrCreatePeerRequestContext(this.groupId, pair, nodeManager);
    final PingRequest msg = TestUtils.createPingRequest();
    final RpcContext asyncContext = Mockito.mock(RpcContext.class);
    processor.sendSequenceResponse(this.groupId, pair, 1, asyncContext, msg);
    Mockito.verify(asyncContext, Mockito.never()).sendResponse(msg);
    processor.sendSequenceResponse(this.groupId, pair, 0, asyncContext, msg);
    Mockito.verify(asyncContext, Mockito.times(2)).sendResponse(msg);
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) PingRequest(org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest) PeerPair(org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair) Test(org.junit.jupiter.api.Test)

Example 2 with RpcContext

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

the class FileServiceTest method testGetLargeFileData.

@Test
public void testGetLargeFileData() throws IOException {
    final String data = writeLargeData();
    final long readerId = FileService.getInstance().addReader(this.fileReader);
    int fileOffset = 0;
    while (true) {
        final RpcRequests.GetFileRequest request = msgFactory.getFileRequest().count(4096).filename("data").offset(fileOffset).readerId(readerId).build();
        final RpcContext asyncContext = Mockito.mock(RpcContext.class);
        final Message msg = // 
        FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext, msgFactory));
        assertTrue(msg instanceof RpcRequests.GetFileResponse);
        final RpcRequests.GetFileResponse response = (RpcRequests.GetFileResponse) msg;
        final byte[] sourceArray = data.getBytes(UTF_8);
        final byte[] respData = response.data().toByteArray();
        final int length = sourceArray.length;
        int offset = 0;
        while (offset + length <= respData.length) {
            final byte[] respArray = new byte[length];
            System.arraycopy(respData, offset, respArray, 0, length);
            try {
                assertArrayEquals(sourceArray, respArray, "Offset: " + fileOffset);
            } catch (AssertionError e) {
                LOG.error("arrayComparisonFailure", e);
            }
            offset += length;
        }
        fileOffset += offset;
        if (response.eof()) {
            break;
        }
    }
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) Test(org.junit.jupiter.api.Test)

Example 3 with RpcContext

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

the class FileServiceTest method testGetFileData.

@Test
public void testGetFileData() throws IOException {
    writeData();
    long readerId = FileService.getInstance().addReader(this.fileReader);
    RpcRequests.GetFileRequest request = msgFactory.getFileRequest().count(Integer.MAX_VALUE).filename("data").offset(0).readerId(readerId).build();
    RpcContext asyncContext = Mockito.mock(RpcContext.class);
    Message msg = FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext, msgFactory));
    assertTrue(msg instanceof RpcRequests.GetFileResponse);
    RpcRequests.GetFileResponse response = (RpcRequests.GetFileResponse) msg;
    assertTrue(response.eof());
    assertEquals("jraft is great!", new String(response.data().toByteArray(), UTF_8));
    assertEquals(-1, response.readSize());
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) Test(org.junit.jupiter.api.Test)

Example 4 with RpcContext

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

the class FileServiceTest method testGetFileNotFoundReader.

@Test
public void testGetFileNotFoundReader() {
    RpcRequests.GetFileRequest request = msgFactory.getFileRequest().count(Integer.MAX_VALUE).filename("data").offset(0).readerId(1).build();
    RpcContext asyncContext = Mockito.mock(RpcContext.class);
    Message msg = FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext, msgFactory));
    assertTrue(msg instanceof RpcRequests.ErrorResponse);
    RpcRequests.ErrorResponse response = (RpcRequests.ErrorResponse) msg;
    assertEquals(RaftError.ENOENT.getNumber(), response.errorCode());
    assertEquals("Fail to find reader=1", response.errorMsg());
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) Test(org.junit.jupiter.api.Test)

Example 5 with RpcContext

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

the class FileServiceTest method testGetFileNotFound.

@Test
public void testGetFileNotFound() {
    long readerId = FileService.getInstance().addReader(this.fileReader);
    RpcRequests.GetFileRequest request = msgFactory.getFileRequest().count(Integer.MAX_VALUE).filename("data").offset(0).readerId(readerId).build();
    RpcContext asyncContext = Mockito.mock(RpcContext.class);
    Message msg = FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext, msgFactory));
    assertTrue(msg instanceof RpcRequests.ErrorResponse);
    RpcRequests.ErrorResponse response = (RpcRequests.ErrorResponse) msg;
    assertEquals(RaftError.EIO.getNumber(), response.errorCode());
    assertEquals(String.format("Fail to read from path=%s filename=data", this.path), response.errorMsg());
}
Also used : RpcContext(org.apache.ignite.raft.jraft.rpc.RpcContext) Message(org.apache.ignite.raft.jraft.rpc.Message) RpcRequests(org.apache.ignite.raft.jraft.rpc.RpcRequests) RpcRequestClosure(org.apache.ignite.raft.jraft.rpc.RpcRequestClosure) Test(org.junit.jupiter.api.Test)

Aggregations

RpcContext (org.apache.ignite.raft.jraft.rpc.RpcContext)6 Test (org.junit.jupiter.api.Test)6 Message (org.apache.ignite.raft.jraft.rpc.Message)4 RpcRequestClosure (org.apache.ignite.raft.jraft.rpc.RpcRequestClosure)4 RpcRequests (org.apache.ignite.raft.jraft.rpc.RpcRequests)4 PingRequest (org.apache.ignite.raft.jraft.rpc.RpcRequests.PingRequest)2 PeerPair (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerPair)2 PeerId (org.apache.ignite.raft.jraft.entity.PeerId)1 PeerRequestContext (org.apache.ignite.raft.jraft.rpc.impl.core.AppendEntriesRequestProcessor.PeerRequestContext)1