Search in sources :

Example 1 with MergedResultMessageProto

use of io.seata.serializer.protobuf.generated.MergedResultMessageProto in project seata by seata.

the class MergeResultMessageConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    MergeResultMessage mergeResultMessage = new MergeResultMessage();
    AbstractResultMessage[] msgs = new AbstractResultMessage[1];
    final GlobalCommitResponse globalCommitResponse = new GlobalCommitResponse();
    globalCommitResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
    globalCommitResponse.setMsg("msg");
    globalCommitResponse.setResultCode(ResultCode.Failed);
    globalCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
    msgs[0] = globalCommitResponse;
    mergeResultMessage.setMsgs(msgs);
    MergeResultMessageConvertor convertor = new MergeResultMessageConvertor();
    MergedResultMessageProto proto = convertor.convert2Proto(mergeResultMessage);
    MergeResultMessage real = convertor.convert2Model(proto);
    GlobalCommitResponse realObj = (GlobalCommitResponse) real.getMsgs()[0];
    assertThat((realObj.getTypeCode())).isEqualTo(globalCommitResponse.getTypeCode());
    assertThat((realObj.getMsg())).isEqualTo(globalCommitResponse.getMsg());
    assertThat((realObj.getResultCode())).isEqualTo(globalCommitResponse.getResultCode());
    assertThat((realObj.getTransactionExceptionCode())).isEqualTo(globalCommitResponse.getTransactionExceptionCode());
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) GlobalCommitResponse(io.seata.core.protocol.transaction.GlobalCommitResponse) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) MergedResultMessageProto(io.seata.serializer.protobuf.generated.MergedResultMessageProto) Test(org.junit.jupiter.api.Test)

Example 2 with MergedResultMessageProto

use of io.seata.serializer.protobuf.generated.MergedResultMessageProto in project seata by seata.

the class MergeResultMessageConvertor method convert2Proto.

@Override
public MergedResultMessageProto convert2Proto(MergeResultMessage mergeResultMessage) {
    final short typeCode = mergeResultMessage.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    List<Any> lists = new ArrayList<>();
    for (AbstractMessage msg : mergeResultMessage.msgs) {
        final PbConvertor pbConvertor = ProtobufConvertManager.getInstance().fetchConvertor(msg.getClass().getName());
        lists.add(Any.pack((Message) pbConvertor.convert2Proto(msg)));
    }
    MergedResultMessageProto mergedWarpMessageProto = MergedResultMessageProto.newBuilder().setAbstractMessage(abstractMessage).addAllMsgs(lists).build();
    return mergedWarpMessageProto;
}
Also used : AbstractMessage(io.seata.core.protocol.AbstractMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) AbstractMessage(io.seata.core.protocol.AbstractMessage) Message(com.google.protobuf.Message) ArrayList(java.util.ArrayList) Any(com.google.protobuf.Any) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto) MergedResultMessageProto(io.seata.serializer.protobuf.generated.MergedResultMessageProto)

Aggregations

AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)2 MergeResultMessage (io.seata.core.protocol.MergeResultMessage)2 MergedResultMessageProto (io.seata.serializer.protobuf.generated.MergedResultMessageProto)2 Any (com.google.protobuf.Any)1 Message (com.google.protobuf.Message)1 AbstractMessage (io.seata.core.protocol.AbstractMessage)1 GlobalCommitResponse (io.seata.core.protocol.transaction.GlobalCommitResponse)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1