Search in sources :

Example 1 with GlobalBeginResponseProto

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

the class GlobalBeginResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
    globalBeginResponse.setResultCode(ResultCode.Failed);
    globalBeginResponse.setMsg("msg");
    globalBeginResponse.setExtraData("extraData");
    globalBeginResponse.setXid("xid");
    globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRollbackFailed_Retriable);
    GlobalBeginResponseConvertor convertor = new GlobalBeginResponseConvertor();
    GlobalBeginResponseProto proto = convertor.convert2Proto(globalBeginResponse);
    GlobalBeginResponse real = convertor.convert2Model(proto);
    assertThat((real.getTypeCode())).isEqualTo(globalBeginResponse.getTypeCode());
    assertThat((real.getMsg())).isEqualTo(globalBeginResponse.getMsg());
    assertThat((real.getResultCode())).isEqualTo(globalBeginResponse.getResultCode());
    assertThat((real.getTransactionExceptionCode())).isEqualTo(globalBeginResponse.getTransactionExceptionCode());
}
Also used : GlobalBeginResponseProto(io.seata.serializer.protobuf.generated.GlobalBeginResponseProto) GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) Test(org.junit.jupiter.api.Test)

Example 2 with GlobalBeginResponseProto

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

the class GlobalBeginResponseConvertor method convert2Proto.

@Override
public GlobalBeginResponseProto convert2Proto(GlobalBeginResponse globalBeginResponse) {
    final short typeCode = globalBeginResponse.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    final String msg = globalBeginResponse.getMsg();
    final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(globalBeginResponse.getResultCode().name())).setAbstractMessage(abstractMessage).build();
    final AbstractTransactionResponseProto abstractTransactionRequestProto = AbstractTransactionResponseProto.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(TransactionExceptionCodeProto.valueOf(globalBeginResponse.getTransactionExceptionCode().name())).build();
    final String extraData = globalBeginResponse.getExtraData();
    GlobalBeginResponseProto result = GlobalBeginResponseProto.newBuilder().setAbstractTransactionResponse(abstractTransactionRequestProto).setExtraData(extraData == null ? "" : extraData).setXid(globalBeginResponse.getXid()).build();
    return result;
}
Also used : AbstractResultMessageProto(io.seata.serializer.protobuf.generated.AbstractResultMessageProto) GlobalBeginResponseProto(io.seata.serializer.protobuf.generated.GlobalBeginResponseProto) AbstractTransactionResponseProto(io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto)

Aggregations

GlobalBeginResponseProto (io.seata.serializer.protobuf.generated.GlobalBeginResponseProto)2 GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 AbstractResultMessageProto (io.seata.serializer.protobuf.generated.AbstractResultMessageProto)1 AbstractTransactionResponseProto (io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto)1 Test (org.junit.jupiter.api.Test)1