Search in sources :

Example 6 with GlobalBeginResponse

use of io.seata.core.protocol.transaction.GlobalBeginResponse 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 7 with GlobalBeginResponse

use of io.seata.core.protocol.transaction.GlobalBeginResponse 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 8 with GlobalBeginResponse

use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.

the class MergeResultMessageSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    MergeResultMessage mergeResultMessage = new MergeResultMessage();
    final AbstractResultMessage[] msgs = new AbstractResultMessage[2];
    final GlobalBeginResponse globalBeginResponse1 = buildGlobalBeginResponse("a1");
    final GlobalBeginResponse globalBeginResponse2 = buildGlobalBeginResponse("a2");
    msgs[0] = globalBeginResponse1;
    msgs[1] = globalBeginResponse2;
    mergeResultMessage.setMsgs(msgs);
    byte[] body = seataSerializer.serialize(mergeResultMessage);
    MergeResultMessage mergeResultMessage2 = seataSerializer.deserialize(body);
    assertThat(mergeResultMessage2.msgs.length).isEqualTo(mergeResultMessage.msgs.length);
    GlobalBeginResponse globalBeginResponse21 = (GlobalBeginResponse) mergeResultMessage2.msgs[0];
    assertThat(globalBeginResponse21.getXid()).isEqualTo(globalBeginResponse1.getXid());
    assertThat(globalBeginResponse21.getExtraData()).isEqualTo(globalBeginResponse1.getExtraData());
    assertThat(globalBeginResponse21.getMsg()).isEqualTo(globalBeginResponse1.getMsg());
    assertThat(globalBeginResponse21.getResultCode()).isEqualTo(globalBeginResponse1.getResultCode());
    assertThat(globalBeginResponse21.getTransactionExceptionCode()).isEqualTo(globalBeginResponse1.getTransactionExceptionCode());
    GlobalBeginResponse globalBeginResponse22 = (GlobalBeginResponse) mergeResultMessage2.msgs[1];
    assertThat(globalBeginResponse22.getXid()).isEqualTo(globalBeginResponse2.getXid());
    assertThat(globalBeginResponse22.getExtraData()).isEqualTo(globalBeginResponse2.getExtraData());
    assertThat(globalBeginResponse22.getMsg()).isEqualTo(globalBeginResponse2.getMsg());
    assertThat(globalBeginResponse22.getResultCode()).isEqualTo(globalBeginResponse2.getResultCode());
    assertThat(globalBeginResponse22.getTransactionExceptionCode()).isEqualTo(globalBeginResponse2.getTransactionExceptionCode());
}
Also used : AbstractResultMessage(io.seata.core.protocol.AbstractResultMessage) MergeResultMessage(io.seata.core.protocol.MergeResultMessage) GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) Test(org.junit.jupiter.api.Test)

Example 9 with GlobalBeginResponse

use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.

the class MergeResultMessageSerializerTest method buildGlobalBeginResponse.

private GlobalBeginResponse buildGlobalBeginResponse(String xid) {
    final GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
    globalBeginResponse.setXid(xid);
    globalBeginResponse.setExtraData("data");
    globalBeginResponse.setMsg("success");
    globalBeginResponse.setResultCode(ResultCode.Failed);
    globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
    return globalBeginResponse;
}
Also used : GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse)

Example 10 with GlobalBeginResponse

use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.

the class MergeResultMessageTest method getAndSetMsgs.

@Test
public void getAndSetMsgs() {
    MergeResultMessage mergeResultMessage = new MergeResultMessage();
    final AbstractResultMessage[] msgs = new AbstractResultMessage[1];
    final GlobalBeginResponse globalBeginResponse = buildGlobalBeginResponse();
    msgs[0] = globalBeginResponse;
    mergeResultMessage.setMsgs(msgs);
    assertThat(globalBeginResponse).isEqualTo(mergeResultMessage.getMsgs()[0]);
}
Also used : GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)12 Test (org.junit.jupiter.api.Test)5 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)3 StoreException (io.seata.common.exception.StoreException)1 TmTransactionException (io.seata.core.exception.TmTransactionException)1 TransactionException (io.seata.core.exception.TransactionException)1 AbstractResultMessage (io.seata.core.protocol.AbstractResultMessage)1 MergeResultMessage (io.seata.core.protocol.MergeResultMessage)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 GlobalBeginResponseProto (io.seata.serializer.protobuf.generated.GlobalBeginResponseProto)1 MockServerMessageSender (io.seata.server.coordinator.DefaultCoordinatorTest.MockServerMessageSender)1 HashMap (java.util.HashMap)1