Search in sources :

Example 1 with AppendEntriesRequestHeader

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());
}
Also used : AppendEntriesRequestHeader(com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequestHeader) AppendEntriesRequest(com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest) RpcCommandFactory(com.alipay.remoting.rpc.RpcCommandFactory) RpcRequestCommand(com.alipay.remoting.rpc.protocol.RpcRequestCommand) Test(org.junit.Test)

Aggregations

RpcCommandFactory (com.alipay.remoting.rpc.RpcCommandFactory)1 RpcRequestCommand (com.alipay.remoting.rpc.protocol.RpcRequestCommand)1 AppendEntriesRequest (com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequest)1 AppendEntriesRequestHeader (com.alipay.sofa.jraft.rpc.RpcRequests.AppendEntriesRequestHeader)1 Test (org.junit.Test)1