use of io.seata.core.protocol.transaction.GlobalBeginRequest in project seata by seata.
the class DefaultTransactionManager method begin.
@Override
public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException {
GlobalBeginRequest request = new GlobalBeginRequest();
request.setTransactionName(name);
request.setTimeout(timeout);
GlobalBeginResponse response = (GlobalBeginResponse) syncCall(request);
if (response.getResultCode() == ResultCode.Failed) {
throw new TmTransactionException(TransactionExceptionCode.BeginFailed, response.getMsg());
}
return response.getXid();
}
use of io.seata.core.protocol.transaction.GlobalBeginRequest in project seata by seata.
the class AbstractTCInboundHandler method handle.
@Override
public GlobalBeginResponse handle(GlobalBeginRequest request, final RpcContext rpcContext) {
GlobalBeginResponse response = new GlobalBeginResponse();
exceptionHandleTemplate(new AbstractCallback<GlobalBeginRequest, GlobalBeginResponse>() {
@Override
public void execute(GlobalBeginRequest request, GlobalBeginResponse response) throws TransactionException {
try {
doGlobalBegin(request, response, rpcContext);
} catch (StoreException e) {
throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("begin global request failed. xid=%s, msg=%s", response.getXid(), e.getMessage()), e);
}
}
}, request, response);
return response;
}
use of io.seata.core.protocol.transaction.GlobalBeginRequest in project seata by seata.
the class MergedWarpMessageSerializerTest method buildGlobalBeginRequest.
private GlobalBeginRequest buildGlobalBeginRequest(String name) {
final GlobalBeginRequest globalBeginRequest = new GlobalBeginRequest();
globalBeginRequest.setTransactionName(name);
globalBeginRequest.setTimeout(3000);
return globalBeginRequest;
}
use of io.seata.core.protocol.transaction.GlobalBeginRequest in project seata by seata.
the class MergeMessageConvertorTest method test.
@Test
public void test() {
MergedWarpMessage mergedWarpMessage = new MergedWarpMessage();
final ArrayList<AbstractMessage> msgs = new ArrayList<>();
final GlobalBeginRequest globalBeginRequest = buildGlobalBeginRequest();
msgs.add(globalBeginRequest);
mergedWarpMessage.msgs = msgs;
MergedWarpMessageConvertor pbConvertor = new MergedWarpMessageConvertor();
MergedWarpMessageProto globalBeginRequestProto = pbConvertor.convert2Proto(mergedWarpMessage);
MergedWarpMessage model = pbConvertor.convert2Model(globalBeginRequestProto);
GlobalBeginRequest decodeModel = (GlobalBeginRequest) model.msgs.get(0);
assertThat(decodeModel.getTransactionName()).isEqualTo(globalBeginRequest.getTransactionName());
assertThat(decodeModel.getTimeout()).isEqualTo(globalBeginRequest.getTimeout());
assertThat(decodeModel.getTypeCode()).isEqualTo(globalBeginRequest.getTypeCode());
}
Aggregations