use of io.seata.core.protocol.transaction.GlobalLockQueryResponse in project seata by seata.
the class DataSourceManager method lockQuery.
@Override
public boolean lockQuery(BranchType branchType, String resourceId, String xid, String lockKeys) throws TransactionException {
GlobalLockQueryRequest request = new GlobalLockQueryRequest();
request.setXid(xid);
request.setLockKey(lockKeys);
request.setResourceId(resourceId);
try {
GlobalLockQueryResponse response;
if (RootContext.inGlobalTransaction() || RootContext.requireGlobalLock()) {
response = (GlobalLockQueryResponse) RmNettyRemotingClient.getInstance().sendSyncRequest(request);
} else {
throw new RuntimeException("unknow situation!");
}
if (response.getResultCode() == ResultCode.Failed) {
throw new TransactionException(response.getTransactionExceptionCode(), "Response[" + response.getMsg() + "]");
}
return response.isLockable();
} catch (TimeoutException toe) {
throw new RmTransactionException(TransactionExceptionCode.IO, "RPC Timeout", toe);
} catch (RuntimeException rex) {
throw new RmTransactionException(TransactionExceptionCode.LockableCheckFailed, "Runtime", rex);
}
}
use of io.seata.core.protocol.transaction.GlobalLockQueryResponse in project seata by seata.
the class GlobalLockQueryResponseConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
GlobalLockQueryResponse globalLockQueryResponse = new GlobalLockQueryResponse();
globalLockQueryResponse.setLockable(true);
globalLockQueryResponse.setMsg("msg");
globalLockQueryResponse.setResultCode(ResultCode.Failed);
globalLockQueryResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotActive);
GlobalLockQueryResponseConvertor convertor = new GlobalLockQueryResponseConvertor();
GlobalLockQueryResponseProto proto = convertor.convert2Proto(globalLockQueryResponse);
GlobalLockQueryResponse real = convertor.convert2Model(proto);
assertThat((real.getTypeCode())).isEqualTo(globalLockQueryResponse.getTypeCode());
assertThat((real.getMsg())).isEqualTo(globalLockQueryResponse.getMsg());
assertThat((real.getResultCode())).isEqualTo(globalLockQueryResponse.getResultCode());
assertThat((real.getTransactionExceptionCode())).isEqualTo(globalLockQueryResponse.getTransactionExceptionCode());
}
Aggregations