use of com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequestHeader in project sofa-jraft by sofastack.
the class ProtobufSerializerTest method testEncodeDecodeAppendEntiresRequestHeader.
@Test
public void testEncodeDecodeAppendEntiresRequestHeader() throws Exception {
final AppendEntriesRequest reqObject = //
AppendEntriesRequest.newBuilder().setGroupId(//
"testGroup").setPeerId(//
"testPeer").setServerId(//
"testServer").setTerm(//
1).setPrevLogIndex(//
1).setPrevLogTerm(//
0).setCommittedIndex(1).build();
final RpcCommandFactory cmdFactory = new RpcCommandFactory();
final RpcRequestCommand request = cmdFactory.createRequestCommand(reqObject);
request.setRequestClass(AppendEntriesRequest.class.getName());
assertNull(request.getHeader());
assertTrue(serializer.serializeContent(request, null));
assertTrue(serializer.serializeHeader(request, null));
assertNull(request.getRequestHeader());
request.setRequestObject(null);
assertTrue(serializer.deserializeContent(request));
assertTrue(serializer.deserializeHeader(request));
assertNotNull(request.getRequestObject());
assertNotNull(request.getRequestHeader());
assertEquals(reqObject, request.getRequestObject());
assertNotSame(reqObject, request.getRequestObject());
final AppendEntriesRequestHeader header = (AppendEntriesRequestHeader) request.getRequestHeader();
assertEquals("testGroup", header.getGroupId());
assertEquals("testPeer", header.getPeerId());
assertEquals("testServer", header.getServerId());
}
Aggregations