Search in sources :

Example 1 with BranchCommitRequestProto

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

the class BranchCommitRequestConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
    branchCommitRequest.setBranchType(BranchType.AT);
    branchCommitRequest.setXid("xid");
    branchCommitRequest.setResourceId("resourceId");
    branchCommitRequest.setBranchId(123);
    branchCommitRequest.setApplicationData("app");
    BranchCommitRequestConvertor branchCommitRequestConvertor = new BranchCommitRequestConvertor();
    BranchCommitRequestProto proto = branchCommitRequestConvertor.convert2Proto(branchCommitRequest);
    BranchCommitRequest realRequest = branchCommitRequestConvertor.convert2Model(proto);
    assertThat(realRequest.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
    assertThat(realRequest.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
    assertThat(realRequest.getXid()).isEqualTo(branchCommitRequest.getXid());
    assertThat(realRequest.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
    assertThat(realRequest.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
    assertThat(realRequest.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
}
Also used : BranchCommitRequestProto(io.seata.serializer.protobuf.generated.BranchCommitRequestProto) BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) Test(org.junit.jupiter.api.Test)

Example 2 with BranchCommitRequestProto

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

the class BranchCommitRequestConvertor method convert2Proto.

@Override
public BranchCommitRequestProto convert2Proto(BranchCommitRequest branchCommitRequest) {
    final short typeCode = branchCommitRequest.getTypeCode();
    final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType(MessageTypeProto.forNumber(typeCode)).build();
    final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto.newBuilder().setAbstractMessage(abstractMessage).build();
    final String applicationData = branchCommitRequest.getApplicationData();
    final AbstractBranchEndRequestProto abstractBranchEndRequestProto = AbstractBranchEndRequestProto.newBuilder().setAbstractTransactionRequest(abstractTransactionRequestProto).setXid(branchCommitRequest.getXid()).setBranchId(branchCommitRequest.getBranchId()).setBranchType(BranchTypeProto.valueOf(branchCommitRequest.getBranchType().name())).setApplicationData(applicationData == null ? "" : applicationData).setResourceId(branchCommitRequest.getResourceId()).build();
    BranchCommitRequestProto result = BranchCommitRequestProto.newBuilder().setAbstractBranchEndRequest(abstractBranchEndRequestProto).build();
    return result;
}
Also used : AbstractBranchEndRequestProto(io.seata.serializer.protobuf.generated.AbstractBranchEndRequestProto) BranchCommitRequestProto(io.seata.serializer.protobuf.generated.BranchCommitRequestProto) AbstractMessageProto(io.seata.serializer.protobuf.generated.AbstractMessageProto) AbstractTransactionRequestProto(io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto)

Aggregations

BranchCommitRequestProto (io.seata.serializer.protobuf.generated.BranchCommitRequestProto)2 BranchCommitRequest (io.seata.core.protocol.transaction.BranchCommitRequest)1 AbstractBranchEndRequestProto (io.seata.serializer.protobuf.generated.AbstractBranchEndRequestProto)1 AbstractMessageProto (io.seata.serializer.protobuf.generated.AbstractMessageProto)1 AbstractTransactionRequestProto (io.seata.serializer.protobuf.generated.AbstractTransactionRequestProto)1 Test (org.junit.jupiter.api.Test)1