use of com.alipay.sofa.jraft.rpc.RpcRequestClosure in project sofa-jraft by sofastack.
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 = //
RpcRequests.GetFileRequest.newBuilder().setCount(4096).setFilename(//
"data").setOffset(//
fileOffset).setReaderId(//
readerId).build();
final RpcContext asyncContext = Mockito.mock(RpcContext.class);
final Message msg = //
FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext));
assertTrue(msg instanceof RpcRequests.GetFileResponse);
final RpcRequests.GetFileResponse response = (RpcRequests.GetFileResponse) msg;
final byte[] sourceArray = data.getBytes();
final byte[] respData = response.getData().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);
assertArrayEquals(sourceArray, respArray);
offset += length;
}
fileOffset += offset;
if (response.getEof()) {
break;
}
}
}
use of com.alipay.sofa.jraft.rpc.RpcRequestClosure in project sofa-jraft by sofastack.
the class FileServiceTest method testGetFileNotFoundReader.
@Test
public void testGetFileNotFoundReader() {
RpcRequests.GetFileRequest request = RpcRequests.GetFileRequest.newBuilder().setCount(Integer.MAX_VALUE).setFilename("data").setOffset(0).setReaderId(1).build();
RpcContext asyncContext = Mockito.mock(RpcContext.class);
Message msg = FileService.getInstance().handleGetFile(request, new RpcRequestClosure(asyncContext));
assertTrue(msg instanceof RpcRequests.ErrorResponse);
RpcRequests.ErrorResponse response = (RpcRequests.ErrorResponse) msg;
Assert.assertEquals(RaftError.ENOENT.getNumber(), response.getErrorCode());
assertEquals("Fail to find reader=1", response.getErrorMsg());
}
Aggregations