Search in sources :

Example 1 with BranchCommitResponseProto

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

the class BranchCommitResponseConvertorTest method convert2Proto.

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

Example 2 with BranchCommitResponseProto

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

the class BranchCommitResponseConvertor method convert2Proto.

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

Aggregations

BranchCommitResponseProto (io.seata.serializer.protobuf.generated.BranchCommitResponseProto)2 BranchCommitResponse (io.seata.core.protocol.transaction.BranchCommitResponse)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