Search in sources :

Example 1 with BranchRollbackRequest

use of io.seata.core.protocol.transaction.BranchRollbackRequest in project seata by seata.

the class BranchRollbackRequestSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    BranchRollbackRequest branchRollbackRequest = new BranchRollbackRequest();
    branchRollbackRequest.setApplicationData("abcd");
    branchRollbackRequest.setBranchId(112232);
    branchRollbackRequest.setBranchType(BranchType.TCC);
    branchRollbackRequest.setResourceId("343");
    branchRollbackRequest.setXid("123");
    byte[] bytes = seataSerializer.serialize(branchRollbackRequest);
    BranchRollbackRequest branchRollbackRequest2 = seataSerializer.deserialize(bytes);
    assertThat(branchRollbackRequest2.getApplicationData()).isEqualTo(branchRollbackRequest.getApplicationData());
    assertThat(branchRollbackRequest2.getBranchId()).isEqualTo(branchRollbackRequest.getBranchId());
    assertThat(branchRollbackRequest2.getBranchType()).isEqualTo(branchRollbackRequest.getBranchType());
    assertThat(branchRollbackRequest2.getResourceId()).isEqualTo(branchRollbackRequest.getResourceId());
    assertThat(branchRollbackRequest2.getXid()).isEqualTo(branchRollbackRequest.getXid());
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest) Test(org.junit.jupiter.api.Test)

Example 2 with BranchRollbackRequest

use of io.seata.core.protocol.transaction.BranchRollbackRequest in project seata by seata.

the class BranchRollbackRequestConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchRollbackRequest branchRegisterRequest = new BranchRollbackRequest();
    branchRegisterRequest.setApplicationData("data");
    branchRegisterRequest.setBranchType(BranchType.AT);
    branchRegisterRequest.setResourceId("resourceId");
    branchRegisterRequest.setXid("xid");
    branchRegisterRequest.setBranchId(123);
    BranchRollbackRequestConvertor convertor = new BranchRollbackRequestConvertor();
    BranchRollbackRequestProto proto = convertor.convert2Proto(branchRegisterRequest);
    BranchRollbackRequest real = convertor.convert2Model(proto);
    assertThat((real.getTypeCode())).isEqualTo(branchRegisterRequest.getTypeCode());
    assertThat((real.getApplicationData())).isEqualTo(branchRegisterRequest.getApplicationData());
    assertThat((real.getBranchType())).isEqualTo(branchRegisterRequest.getBranchType());
    assertThat((real.getXid())).isEqualTo(branchRegisterRequest.getXid());
    assertThat((real.getResourceId())).isEqualTo(branchRegisterRequest.getResourceId());
    assertThat((real.getBranchId())).isEqualTo(branchRegisterRequest.getBranchId());
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest) BranchRollbackRequestProto(io.seata.serializer.protobuf.generated.BranchRollbackRequestProto) Test(org.junit.jupiter.api.Test)

Example 3 with BranchRollbackRequest

use of io.seata.core.protocol.transaction.BranchRollbackRequest in project seata by seata.

the class AbstractCore method branchRollback.

@Override
public BranchStatus branchRollback(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
    try {
        BranchRollbackRequest request = new BranchRollbackRequest();
        request.setXid(branchSession.getXid());
        request.setBranchId(branchSession.getBranchId());
        request.setResourceId(branchSession.getResourceId());
        request.setApplicationData(branchSession.getApplicationData());
        request.setBranchType(branchSession.getBranchType());
        return branchRollbackSend(request, globalSession, branchSession);
    } catch (IOException | TimeoutException e) {
        throw new BranchTransactionException(FailedToSendBranchRollbackRequest, String.format("Send branch rollback failed, xid = %s branchId = %s", branchSession.getXid(), branchSession.getBranchId()), e);
    }
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest) FailedToSendBranchRollbackRequest(io.seata.core.exception.TransactionExceptionCode.FailedToSendBranchRollbackRequest) IOException(java.io.IOException) BranchTransactionException(io.seata.core.exception.BranchTransactionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with BranchRollbackRequest

use of io.seata.core.protocol.transaction.BranchRollbackRequest in project seata by seata.

the class BranchRollbackRequestConvertor method convert2Model.

@Override
public BranchRollbackRequest convert2Model(BranchRollbackRequestProto branchRollbackRequestProto) {
    BranchRollbackRequest branchCommitRequest = new BranchRollbackRequest();
    branchCommitRequest.setApplicationData(branchRollbackRequestProto.getAbstractBranchEndRequest().getApplicationData());
    branchCommitRequest.setBranchId(branchRollbackRequestProto.getAbstractBranchEndRequest().getBranchId());
    branchCommitRequest.setResourceId(branchRollbackRequestProto.getAbstractBranchEndRequest().getResourceId());
    branchCommitRequest.setXid(branchRollbackRequestProto.getAbstractBranchEndRequest().getXid());
    branchCommitRequest.setBranchType(BranchType.valueOf(branchRollbackRequestProto.getAbstractBranchEndRequest().getBranchType().name()));
    return branchCommitRequest;
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest)

Example 5 with BranchRollbackRequest

use of io.seata.core.protocol.transaction.BranchRollbackRequest in project seata by seata.

the class AbstractRMHandler method handle.

@Override
public BranchRollbackResponse handle(BranchRollbackRequest request) {
    BranchRollbackResponse response = new BranchRollbackResponse();
    exceptionHandleTemplate(new AbstractCallback<BranchRollbackRequest, BranchRollbackResponse>() {

        @Override
        public void execute(BranchRollbackRequest request, BranchRollbackResponse response) throws TransactionException {
            doBranchRollback(request, response);
        }
    }, request, response);
    return response;
}
Also used : BranchRollbackRequest(io.seata.core.protocol.transaction.BranchRollbackRequest) TransactionException(io.seata.core.exception.TransactionException) BranchRollbackResponse(io.seata.core.protocol.transaction.BranchRollbackResponse)

Aggregations

BranchRollbackRequest (io.seata.core.protocol.transaction.BranchRollbackRequest)6 BranchTransactionException (io.seata.core.exception.BranchTransactionException)2 IOException (java.io.IOException)2 TimeoutException (java.util.concurrent.TimeoutException)2 Test (org.junit.jupiter.api.Test)2 TransactionException (io.seata.core.exception.TransactionException)1 FailedToSendBranchRollbackRequest (io.seata.core.exception.TransactionExceptionCode.FailedToSendBranchRollbackRequest)1 BranchRollbackResponse (io.seata.core.protocol.transaction.BranchRollbackResponse)1 BranchRollbackRequestProto (io.seata.serializer.protobuf.generated.BranchRollbackRequestProto)1