Search in sources :

Example 1 with GlobalStatusResponse

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

Example 2 with GlobalStatusResponse

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

Example 3 with GlobalStatusResponse

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());
}
Also used : GlobalStatusResponse(io.seata.core.protocol.transaction.GlobalStatusResponse) Test(org.junit.jupiter.api.Test)

Example 4 with GlobalStatusResponse

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());
}
Also used : GlobalStatusResponseProto(io.seata.serializer.protobuf.generated.GlobalStatusResponseProto) GlobalStatusResponse(io.seata.core.protocol.transaction.GlobalStatusResponse) Test(org.junit.jupiter.api.Test)

Example 5 with GlobalStatusResponse

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;
}
Also used : AbstractGlobalEndResponseProto(io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto) AbstractTransactionResponseProto(io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto) GlobalStatusResponse(io.seata.core.protocol.transaction.GlobalStatusResponse)

Aggregations

GlobalStatusResponse (io.seata.core.protocol.transaction.GlobalStatusResponse)5 GlobalStatusRequest (io.seata.core.protocol.transaction.GlobalStatusRequest)2 Test (org.junit.jupiter.api.Test)2 StoreException (io.seata.common.exception.StoreException)1 TransactionException (io.seata.core.exception.TransactionException)1 AbstractGlobalEndResponseProto (io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto)1 AbstractTransactionResponseProto (io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto)1 GlobalStatusResponseProto (io.seata.serializer.protobuf.generated.GlobalStatusResponseProto)1