use of io.seata.core.protocol.transaction.GlobalStatusResponse in project seata by seata.
the class DefaultTransactionManager method getStatus.
@Override
public GlobalStatus getStatus(String xid) throws TransactionException {
GlobalStatusRequest queryGlobalStatus = new GlobalStatusRequest();
queryGlobalStatus.setXid(xid);
GlobalStatusResponse response = (GlobalStatusResponse) syncCall(queryGlobalStatus);
return response.getGlobalStatus();
}
use of io.seata.core.protocol.transaction.GlobalStatusResponse in project seata by seata.
the class AbstractTCInboundHandler method handle.
@Override
public GlobalStatusResponse handle(GlobalStatusRequest request, final RpcContext rpcContext) {
GlobalStatusResponse response = new GlobalStatusResponse();
response.setGlobalStatus(GlobalStatus.UnKnown);
exceptionHandleTemplate(new AbstractCallback<GlobalStatusRequest, GlobalStatusResponse>() {
@Override
public void execute(GlobalStatusRequest request, GlobalStatusResponse response) throws TransactionException {
try {
doGlobalStatus(request, response, rpcContext);
} catch (StoreException e) {
throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("global status request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
}
}
@Override
public void onTransactionException(GlobalStatusRequest request, GlobalStatusResponse response, TransactionException tex) {
super.onTransactionException(request, response, tex);
checkTransactionStatus(request, response);
}
@Override
public void onException(GlobalStatusRequest request, GlobalStatusResponse response, Exception rex) {
super.onException(request, response, rex);
checkTransactionStatus(request, response);
}
}, request, response);
return response;
}
use of io.seata.core.protocol.transaction.GlobalStatusResponse in project seata by seata.
the class GlobalStatusResponseSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
GlobalStatusResponse globalStatusResponse = new GlobalStatusResponse();
globalStatusResponse.setGlobalStatus(GlobalStatus.CommitRetrying);
globalStatusResponse.setMsg("aaaa");
globalStatusResponse.setResultCode(ResultCode.Failed);
globalStatusResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
byte[] bytes = seataSerializer.serialize(globalStatusResponse);
GlobalStatusResponse globalStatusResponse2 = seataSerializer.deserialize(bytes);
assertThat(globalStatusResponse2.getGlobalStatus()).isEqualTo(globalStatusResponse.getGlobalStatus());
assertThat(globalStatusResponse2.getMsg()).isEqualTo(globalStatusResponse.getMsg());
assertThat(globalStatusResponse2.getTransactionExceptionCode()).isEqualTo(globalStatusResponse.getTransactionExceptionCode());
assertThat(globalStatusResponse2.getResultCode()).isEqualTo(globalStatusResponse.getResultCode());
}
use of io.seata.core.protocol.transaction.GlobalStatusResponse in project seata by seata.
the class GlobalStatusResponseConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
GlobalStatusResponse globalStatusResponse = new GlobalStatusResponse();
globalStatusResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
globalStatusResponse.setMsg("msg");
globalStatusResponse.setResultCode(ResultCode.Failed);
globalStatusResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
GlobalStatusResponseConvertor convertor = new GlobalStatusResponseConvertor();
GlobalStatusResponseProto proto = convertor.convert2Proto(globalStatusResponse);
GlobalStatusResponse real = convertor.convert2Model(proto);
assertThat((real.getTypeCode())).isEqualTo(globalStatusResponse.getTypeCode());
assertThat((real.getMsg())).isEqualTo(globalStatusResponse.getMsg());
assertThat((real.getResultCode())).isEqualTo(globalStatusResponse.getResultCode());
assertThat((real.getTransactionExceptionCode())).isEqualTo(globalStatusResponse.getTransactionExceptionCode());
}
use of io.seata.core.protocol.transaction.GlobalStatusResponse in project seata by seata.
the class GlobalStatusResponseConvertor method convert2Model.
@Override
public GlobalStatusResponse convert2Model(GlobalStatusResponseProto globalStatusResponseProto) {
GlobalStatusResponse branchRegisterResponse = new GlobalStatusResponse();
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalStatusResponseProto.getAbstractGlobalEndResponse();
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse.getAbstractTransactionResponse();
branchRegisterResponse.setMsg(abstractResultMessage.getAbstractResultMessage().getMsg());
branchRegisterResponse.setResultCode(ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name()));
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(abstractResultMessage.getTransactionExceptionCode().name()));
branchRegisterResponse.setGlobalStatus(GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name()));
return branchRegisterResponse;
}
Aggregations