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());
}
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());
}
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);
}
}
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;
}
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;
}
Aggregations