Search in sources :

Example 1 with GlobalRollbackResponse

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

the class AbstractTCInboundHandler method handle.

@Override
public GlobalRollbackResponse handle(GlobalRollbackRequest request, final RpcContext rpcContext) {
    GlobalRollbackResponse response = new GlobalRollbackResponse();
    response.setGlobalStatus(GlobalStatus.Rollbacking);
    exceptionHandleTemplate(new AbstractCallback<GlobalRollbackRequest, GlobalRollbackResponse>() {

        @Override
        public void execute(GlobalRollbackRequest request, GlobalRollbackResponse response) throws TransactionException {
            try {
                doGlobalRollback(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("global rollback request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
            }
        }

        @Override
        public void onTransactionException(GlobalRollbackRequest request, GlobalRollbackResponse response, TransactionException tex) {
            super.onTransactionException(request, response, tex);
            // may be appears StoreException outer layer method catch
            checkTransactionStatus(request, response);
        }

        @Override
        public void onException(GlobalRollbackRequest request, GlobalRollbackResponse response, Exception rex) {
            super.onException(request, response, rex);
            // may be appears StoreException outer layer method catch
            checkTransactionStatus(request, response);
        }
    }, request, response);
    return response;
}
Also used : GlobalRollbackRequest(io.seata.core.protocol.transaction.GlobalRollbackRequest) TransactionException(io.seata.core.exception.TransactionException) GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) TransactionException(io.seata.core.exception.TransactionException) StoreException(io.seata.common.exception.StoreException) StoreException(io.seata.common.exception.StoreException)

Example 2 with GlobalRollbackResponse

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

the class DefaultCoordinatorMetricsTest method test.

@Test
public void test() throws IOException, TransactionException, InterruptedException {
    SessionHolder.init(null);
    DefaultCoordinator coordinator = new DefaultCoordinator(new MockServerMessageSender());
    coordinator.init();
    try {
        MetricsManager.get().init();
        // start a transaction
        GlobalBeginRequest request = new GlobalBeginRequest();
        request.setTransactionName("test_transaction");
        GlobalBeginResponse response = new GlobalBeginResponse();
        coordinator.doGlobalBegin(request, response, new RpcContext());
        Map<String, Measurement> measurements = new HashMap<>();
        MetricsManager.get().getRegistry().measure().forEach(measurement -> measurements.put(measurement.getId().toString(), measurement));
        Assertions.assertEquals(1, measurements.size());
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=active)").getValue(), 0);
        // commit this transaction
        GlobalCommitRequest commitRequest = new GlobalCommitRequest();
        commitRequest.setXid(response.getXid());
        coordinator.doGlobalCommit(commitRequest, new GlobalCommitResponse(), new RpcContext());
        // we need sleep for a short while because default canBeCommittedAsync() is true
        Thread.sleep(200);
        measurements.clear();
        MetricsManager.get().getRegistry().measure().forEach(measurement -> measurements.put(measurement.getId().toString(), measurement));
        Assertions.assertEquals(9, measurements.size());
        Assertions.assertEquals(0, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=active)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=committed)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=count,status=committed)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=total,status=committed)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=timer,role=tc,statistic=count,status=committed)").getValue(), 0);
        // start another new transaction
        request = new GlobalBeginRequest();
        request.setTransactionName("test_transaction_2");
        response = new GlobalBeginResponse();
        coordinator.doGlobalBegin(request, response, new RpcContext());
        // rollback this transaction
        GlobalRollbackRequest rollbackRequest = new GlobalRollbackRequest();
        rollbackRequest.setXid(response.getXid());
        coordinator.doGlobalRollback(rollbackRequest, new GlobalRollbackResponse(), new RpcContext());
        Thread.sleep(200);
        measurements.clear();
        MetricsManager.get().getRegistry().measure().forEach(measurement -> measurements.put(measurement.getId().toString(), measurement));
        Assertions.assertEquals(17, measurements.size());
        Assertions.assertEquals(0, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=active)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=committed)").getValue(), 0);
        Assertions.assertEquals(0, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=count,status=committed)").getValue(), 0);
        Assertions.assertEquals(0, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=total,status=committed)").getValue(), 0);
        Assertions.assertEquals(0, measurements.get("seata.transaction(applicationId=null,group=null,meter=timer,role=tc,statistic=count,status=committed)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=counter,role=tc,status=rollbacked)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=count,status=rollbacked)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=summary,role=tc,statistic=total,status=rollbacked)").getValue(), 0);
        Assertions.assertEquals(1, measurements.get("seata.transaction(applicationId=null,group=null,meter=timer,role=tc,statistic=count,status=rollbacked)").getValue(), 0);
    } finally {
        coordinator.destroy();
        SessionHolder.destroy();
    }
}
Also used : MockServerMessageSender(io.seata.server.coordinator.DefaultCoordinatorTest.MockServerMessageSender) Measurement(io.seata.metrics.Measurement) GlobalCommitRequest(io.seata.core.protocol.transaction.GlobalCommitRequest) HashMap(java.util.HashMap) GlobalCommitResponse(io.seata.core.protocol.transaction.GlobalCommitResponse) GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) RpcContext(io.seata.core.rpc.RpcContext) GlobalRollbackRequest(io.seata.core.protocol.transaction.GlobalRollbackRequest) GlobalBeginRequest(io.seata.core.protocol.transaction.GlobalBeginRequest) GlobalBeginResponse(io.seata.core.protocol.transaction.GlobalBeginResponse) Test(org.junit.jupiter.api.Test)

Example 3 with GlobalRollbackResponse

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

the class GlobalRollbackResponseConvertor method convert2Model.

@Override
public GlobalRollbackResponse convert2Model(GlobalRollbackResponseProto globalRollbackResponseProto) {
    GlobalRollbackResponse branchRegisterResponse = new GlobalRollbackResponse();
    final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalRollbackResponseProto.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) GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) AbstractTransactionResponseProto(io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto)

Example 4 with GlobalRollbackResponse

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

the class GlobalRollbackResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    GlobalRollbackResponse globalRollbackResponse = new GlobalRollbackResponse();
    globalRollbackResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
    globalRollbackResponse.setMsg("msg");
    globalRollbackResponse.setResultCode(ResultCode.Failed);
    globalRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchRegisterFailed);
    GlobalRollbackResponseConvertor convertor = new GlobalRollbackResponseConvertor();
    GlobalRollbackResponseProto proto = convertor.convert2Proto(globalRollbackResponse);
    GlobalRollbackResponse real = convertor.convert2Model(proto);
    assertThat((real.getTypeCode())).isEqualTo(globalRollbackResponse.getTypeCode());
    assertThat((real.getMsg())).isEqualTo(globalRollbackResponse.getMsg());
    assertThat((real.getResultCode())).isEqualTo(globalRollbackResponse.getResultCode());
    assertThat((real.getTransactionExceptionCode())).isEqualTo(globalRollbackResponse.getTransactionExceptionCode());
}
Also used : GlobalRollbackResponseProto(io.seata.serializer.protobuf.generated.GlobalRollbackResponseProto) GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) Test(org.junit.jupiter.api.Test)

Example 5 with GlobalRollbackResponse

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

the class GlobalRollbackResponseSerializerTest method test_codec.

/**
 * Test codec.
 */
@Test
public void test_codec() {
    GlobalRollbackResponse globalRollbackResponse = new GlobalRollbackResponse();
    globalRollbackResponse.setGlobalStatus(GlobalStatus.AsyncCommitting);
    globalRollbackResponse.setMsg("aaa");
    globalRollbackResponse.setResultCode(ResultCode.Failed);
    globalRollbackResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotExist);
    byte[] bytes = seataSerializer.serialize(globalRollbackResponse);
    GlobalRollbackResponse globalRollbackResponse2 = seataSerializer.deserialize(bytes);
    assertThat(globalRollbackResponse2.getGlobalStatus()).isEqualTo(globalRollbackResponse.getGlobalStatus());
    assertThat(globalRollbackResponse2.getMsg()).isEqualTo(globalRollbackResponse.getMsg());
    assertThat(globalRollbackResponse2.getResultCode()).isEqualTo(globalRollbackResponse.getResultCode());
    assertThat(globalRollbackResponse2.getTransactionExceptionCode()).isEqualTo(globalRollbackResponse.getTransactionExceptionCode());
}
Also used : GlobalRollbackResponse(io.seata.core.protocol.transaction.GlobalRollbackResponse) Test(org.junit.jupiter.api.Test)

Aggregations

GlobalRollbackResponse (io.seata.core.protocol.transaction.GlobalRollbackResponse)6 GlobalRollbackRequest (io.seata.core.protocol.transaction.GlobalRollbackRequest)3 Test (org.junit.jupiter.api.Test)3 StoreException (io.seata.common.exception.StoreException)1 TransactionException (io.seata.core.exception.TransactionException)1 GlobalBeginRequest (io.seata.core.protocol.transaction.GlobalBeginRequest)1 GlobalBeginResponse (io.seata.core.protocol.transaction.GlobalBeginResponse)1 GlobalCommitRequest (io.seata.core.protocol.transaction.GlobalCommitRequest)1 GlobalCommitResponse (io.seata.core.protocol.transaction.GlobalCommitResponse)1 RpcContext (io.seata.core.rpc.RpcContext)1 Measurement (io.seata.metrics.Measurement)1 AbstractGlobalEndResponseProto (io.seata.serializer.protobuf.generated.AbstractGlobalEndResponseProto)1 AbstractTransactionResponseProto (io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto)1 GlobalRollbackResponseProto (io.seata.serializer.protobuf.generated.GlobalRollbackResponseProto)1 MockServerMessageSender (io.seata.server.coordinator.DefaultCoordinatorTest.MockServerMessageSender)1 HashMap (java.util.HashMap)1