Search in sources :

Example 6 with GlobalLockQueryResponse

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);
    }
}
Also used : TransactionException(io.seata.core.exception.TransactionException) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryRequest(io.seata.core.protocol.transaction.GlobalLockQueryRequest) RmTransactionException(io.seata.core.exception.RmTransactionException) GlobalLockQueryResponse(io.seata.core.protocol.transaction.GlobalLockQueryResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 7 with GlobalLockQueryResponse

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

Aggregations

GlobalLockQueryResponse (io.seata.core.protocol.transaction.GlobalLockQueryResponse)7 TransactionException (io.seata.core.exception.TransactionException)2 GlobalLockQueryRequest (io.seata.core.protocol.transaction.GlobalLockQueryRequest)2 Test (org.junit.jupiter.api.Test)2 StoreException (io.seata.common.exception.StoreException)1 RmTransactionException (io.seata.core.exception.RmTransactionException)1 AbstractResultMessageProto (io.seata.serializer.protobuf.generated.AbstractResultMessageProto)1 AbstractTransactionResponseProto (io.seata.serializer.protobuf.generated.AbstractTransactionResponseProto)1 GlobalLockQueryResponseProto (io.seata.serializer.protobuf.generated.GlobalLockQueryResponseProto)1 TimeoutException (java.util.concurrent.TimeoutException)1