use of io.seata.core.protocol.transaction.GlobalRollbackRequest in project seata by seata.
the class GlobalRollbackRequestTest method testToString.
/**
* Test to string.
*/
@Test
public void testToString() {
GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
globalRollbackRequest.setXid("127.0.0.1:8091:1249853");
globalRollbackRequest.setExtraData("test_extra_data");
Assertions.assertEquals("xid=127.0.0.1:8091:1249853,extraData=test_extra_data", globalRollbackRequest.toString());
}
use of io.seata.core.protocol.transaction.GlobalRollbackRequest in project seata by seata.
the class GlobalRollbackRequestCodecTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
GlobalRollbackRequest globalRollbackRequest = new GlobalRollbackRequest();
globalRollbackRequest.setExtraData("aaaa");
globalRollbackRequest.setXid("aaaa");
byte[] bytes = seataSerializer.serialize(globalRollbackRequest);
GlobalRollbackRequest globalRollbackRequest2 = seataSerializer.deserialize(bytes);
assertThat(globalRollbackRequest2.getXid()).isEqualTo(globalRollbackRequest.getXid());
assertThat(globalRollbackRequest2.getExtraData()).isEqualTo(globalRollbackRequest.getExtraData());
}
use of io.seata.core.protocol.transaction.GlobalRollbackRequest 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;
}
use of io.seata.core.protocol.transaction.GlobalRollbackRequest 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();
}
}
use of io.seata.core.protocol.transaction.GlobalRollbackRequest in project seata by seata.
the class DefaultTransactionManager method rollback.
@Override
public GlobalStatus rollback(String xid) throws TransactionException {
GlobalRollbackRequest globalRollback = new GlobalRollbackRequest();
globalRollback.setXid(xid);
GlobalRollbackResponse response = (GlobalRollbackResponse) syncCall(globalRollback);
return response.getGlobalStatus();
}
Aggregations