use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.
the class AbstractTCInboundHandler method handle.
@Override
public BranchReportResponse handle(BranchReportRequest request, final RpcContext rpcContext) {
BranchReportResponse response = new BranchReportResponse();
exceptionHandleTemplate(new AbstractCallback<BranchReportRequest, BranchReportResponse>() {
@Override
public void execute(BranchReportRequest request, BranchReportResponse response) throws TransactionException {
try {
doBranchReport(request, response, rpcContext);
} catch (StoreException e) {
throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("branch report request failed. xid=%s, branchId=%s, msg=%s", request.getXid(), request.getBranchId(), e.getMessage()), e);
}
}
}, request, response);
return response;
}
use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.
the class BranchReportResponseSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
BranchReportResponse branchReportResponse = new BranchReportResponse();
branchReportResponse.setMsg("abac");
branchReportResponse.setResultCode(ResultCode.Failed);
branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
byte[] bytes = seataSerializer.serialize(branchReportResponse);
BranchReportResponse branchReportResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchReportResponse2.getMsg()).isEqualTo(branchReportResponse.getMsg());
assertThat(branchReportResponse2.getResultCode()).isEqualTo(branchReportResponse.getResultCode());
assertThat(branchReportResponse2.getTransactionExceptionCode()).isEqualTo(branchReportResponse.getTransactionExceptionCode());
}
use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.
the class AbstractResourceManager method branchReport.
/**
* report branch status
*
* @param branchType the branch type
* @param xid the xid
* @param branchId the branch id
* @param status the status
* @param applicationData the application data
* @throws TransactionException TransactionException
*/
@Override
public void branchReport(BranchType branchType, String xid, long branchId, BranchStatus status, String applicationData) throws TransactionException {
try {
BranchReportRequest request = new BranchReportRequest();
request.setXid(xid);
request.setBranchId(branchId);
request.setStatus(status);
request.setApplicationData(applicationData);
BranchReportResponse response = (BranchReportResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
if (response.getResultCode() == ResultCode.Failed) {
throw new RmTransactionException(response.getTransactionExceptionCode(), String.format("Response[ %s ]", response.getMsg()));
}
} catch (TimeoutException toe) {
throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
} catch (RuntimeException rex) {
throw new RmTransactionException(TransactionExceptionCode.BranchReportFailed, "Runtime", rex);
}
}
use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.
the class BranchReportResponseConvertor method convert2Model.
@Override
public BranchReportResponse convert2Model(BranchReportResponseProto branchReportResponseProto) {
BranchReportResponse branchRegisterResponse = new BranchReportResponse();
final AbstractResultMessageProto abstractResultMessage = branchReportResponseProto.getAbstractTransactionResponse().getAbstractResultMessage();
branchRegisterResponse.setMsg(abstractResultMessage.getMsg());
branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getResultCode().name()));
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(branchReportResponseProto.getAbstractTransactionResponse().getTransactionExceptionCode().name()));
return branchRegisterResponse;
}
use of io.seata.core.protocol.transaction.BranchReportResponse in project seata by seata.
the class BranchReportResponseConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
BranchReportResponse branchReportResponse = new BranchReportResponse();
branchReportResponse.setMsg("msg");
branchReportResponse.setResultCode(ResultCode.Failed);
branchReportResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
BranchReportResponseConvertor convertor = new BranchReportResponseConvertor();
BranchReportResponseProto proto = convertor.convert2Proto(branchReportResponse);
BranchReportResponse real = convertor.convert2Model(proto);
assertThat((real.getTypeCode())).isEqualTo(branchReportResponse.getTypeCode());
assertThat((real.getMsg())).isEqualTo(branchReportResponse.getMsg());
assertThat((real.getResultCode())).isEqualTo(branchReportResponse.getResultCode());
assertThat((real.getTransactionExceptionCode())).isEqualTo(branchReportResponse.getTransactionExceptionCode());
}
Aggregations