Search in sources :

Example 1 with BranchRollbackResponseProto

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

the class BranchRollbackResponseConvertor method convert2Proto.

@Override
public BranchRollbackResponseProto convert2Proto(BranchRollbackResponse branchRollbackResponse) {
    final short typeCode = branchRollbackResponse.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    final String msg = branchRollbackResponse.getMsg();
    final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg(msg == null ? "" : msg).setResultCode(ResultCodeProto.valueOf(branchRollbackResponse.getResultCode().name())).setAbstractMessage(abstractMessage).build();
    final AbstractTransactionResponseProto abstractTransactionRequestProto = AbstractTransactionResponseProto.newBuilder().setAbstractResultMessage(abstractResultMessageProto).setTransactionExceptionCode(TransactionExceptionCodeProto.valueOf(branchRollbackResponse.getTransactionExceptionCode().name())).build();
    final AbstractBranchEndResponseProto abstractBranchEndResponse = AbstractBranchEndResponseProto.newBuilder().setAbstractTransactionResponse(abstractTransactionRequestProto).setXid(branchRollbackResponse.getXid()).setBranchId(branchRollbackResponse.getBranchId()).setBranchStatus(BranchStatusProto.forNumber(branchRollbackResponse.getBranchStatus().getCode())).build();
    BranchRollbackResponseProto result = BranchRollbackResponseProto.newBuilder().setAbstractBranchEndResponse(abstractBranchEndResponse).build();
    return result;
}
Also used : AbstractResultMessageProto(io.seata.serializer.protobuf.generated.AbstractResultMessageProto) BranchRollbackResponseProto(io.seata.serializer.protobuf.generated.BranchRollbackResponseProto) AbstractBranchEndResponseProto(io.seata.serializer.protobuf.generated.AbstractBranchEndResponseProto) AbstractTransactionResponseProto(io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto)

Example 2 with BranchRollbackResponseProto

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

the class BranchRollbackResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchRollbackResponse branchRollbackResponse = new BranchRollbackResponse();
    branchRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
    branchRollbackResponse.setResultCode(ResultCode.Success);
    branchRollbackResponse.setMsg("xx");
    branchRollbackResponse.setXid("xid");
    branchRollbackResponse.setBranchStatus(BranchStatus.PhaseTwo_Rollbacked);
    branchRollbackResponse.setBranchId(123);
    BranchRollbackResponseConvertor convertor = new BranchRollbackResponseConvertor();
    BranchRollbackResponseProto proto = convertor.convert2Proto(branchRollbackResponse);
    BranchRollbackResponse real = convertor.convert2Model(proto);
    assertThat(real.getTypeCode()).isEqualTo(branchRollbackResponse.getTypeCode());
    assertThat(real.getMsg()).isEqualTo(branchRollbackResponse.getMsg());
    assertThat(real.getXid()).isEqualTo(branchRollbackResponse.getXid());
    assertThat(real.getTransactionExceptionCode()).isEqualTo(branchRollbackResponse.getTransactionExceptionCode());
    assertThat(real.getBranchStatus()).isEqualTo(branchRollbackResponse.getBranchStatus());
    assertThat(real.getResultCode()).isEqualTo(branchRollbackResponse.getResultCode());
}
Also used : BranchRollbackResponseProto(io.seata.serializer.protobuf.generated.BranchRollbackResponseProto) BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BranchRollbackResponseProto (io.seata.serializer.protobuf.generated.BranchRollbackResponseProto)2 BranchRollbackResponse (io.seata.core.protocol.transaction.BranchRollbackResponse)1 AbstractBranchEndResponseProto (io.seata.serializer.protobuf.generated.AbstractBranchEndResponseProto)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