Search in sources :

Example 11 with GlobalBeginRequest

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();
}
Also used : GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) TmTransactionException(io.seata.core.exception.TmTransactionException)

Example 12 with GlobalBeginRequest

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;
}
Also used : GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) TransactionException(io.seata.core.exception.TransactionException) GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) StoreException(io.seata.common.exception.StoreException)

Example 13 with GlobalBeginRequest

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;
}
Also used : GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest)

Example 14 with 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());
}
Also used : MergedWarpMessageProto(io.seata.serializer.protobuf.generated.MergedWarpMessageProto) GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) AbstractMessage(io.seata.core.protocol.AbstractMessage) ArrayList(java.util.ArrayList) MergedWarpMessage(io.seata.core.protocol.MergedWarpMessage) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)14 Test (org.junit.jupiter.api.Test)6 GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)3 AbstractMessage (io.seata.core.protocol.AbstractMessage)2 MergedWarpMessage (io.seata.core.protocol.MergedWarpMessage)2 ArrayList (java.util.ArrayList)2 StoreException (io.seata.common.exception.StoreException)1 TmTransactionException (io.seata.core.exception.TmTransactionException)1 TransactionException (io.seata.core.exception.TransactionException)1 GlobalCommitRequest (io.seata.core.protocol.transaction.GlobalCommitRequest)1 GlobalCommitResponse (io.seata.core.protocol.transaction.GlobalCommitResponse)1 GlobalRollbackRequest (io.seata.core.protocol.transaction.GlobalRollbackRequest)1 GlobalRollbackResponse (io.seata.core.protocol.transaction.GlobalRollbackResponse)1 RpcContext (io.seata.core.rpc.RpcContext)1 Measurement (io.seata.metrics.Measurement)1 GlobalBeginRequestProto (io.seata.serializer.protobuf.generated.GlobalBeginRequestProto)1 MergedWarpMessageProto (io.seata.serializer.protobuf.generated.MergedWarpMessageProto)1 MockServerMessageSender (io.seata.server.coordinator.DefaultCoordinatorTest.MockServerMessageSender)1 HashMap (java.util.HashMap)1