use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.
the class DefaultTransactionManager method begin.
@Override
public String begin(String applicationId, String transactionServiceGroup, String name, int timeout) throws TransactionException {
GlobalBeginRequest request = new GlobalBeginRequest();
request.setTransactionName(name);
request.setTimeout(timeout);
GlobalBeginResponse response = (GlobalBeginResponse) syncCall(request);
if (response.getResultCode() == ResultCode.Failed) {
throw new TmTransactionException(TransactionExceptionCode.BeginFailed, response.getMsg());
}
return response.getXid();
}
use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.
the class AbstractTCInboundHandler method handle.
@Override
public GlobalBeginResponse handle(GlobalBeginRequest request, final RpcContext rpcContext) {
GlobalBeginResponse response = new GlobalBeginResponse();
exceptionHandleTemplate(new AbstractCallback<GlobalBeginRequest, GlobalBeginResponse>() {
@Override
public void execute(GlobalBeginRequest request, GlobalBeginResponse response) throws TransactionException {
try {
doGlobalBegin(request, response, rpcContext);
} catch (StoreException e) {
throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("begin global request failed. xid=%s, msg=%s", response.getXid(), e.getMessage()), e);
}
}
}, request, response);
return response;
}
use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.
the class MergeResultMessageSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
MergeResultMessage mergeResultMessage = new MergeResultMessage();
final AbstractResultMessage[] msgs = new AbstractResultMessage[2];
final GlobalBeginResponse globalBeginResponse1 = buildGlobalBeginResponse("a1");
final GlobalBeginResponse globalBeginResponse2 = buildGlobalBeginResponse("a2");
msgs[0] = globalBeginResponse1;
msgs[1] = globalBeginResponse2;
mergeResultMessage.setMsgs(msgs);
byte[] body = seataSerializer.serialize(mergeResultMessage);
MergeResultMessage mergeResultMessage2 = seataSerializer.deserialize(body);
assertThat(mergeResultMessage2.msgs.length).isEqualTo(mergeResultMessage.msgs.length);
GlobalBeginResponse globalBeginResponse21 = (GlobalBeginResponse) mergeResultMessage2.msgs[0];
assertThat(globalBeginResponse21.getXid()).isEqualTo(globalBeginResponse1.getXid());
assertThat(globalBeginResponse21.getExtraData()).isEqualTo(globalBeginResponse1.getExtraData());
assertThat(globalBeginResponse21.getMsg()).isEqualTo(globalBeginResponse1.getMsg());
assertThat(globalBeginResponse21.getResultCode()).isEqualTo(globalBeginResponse1.getResultCode());
assertThat(globalBeginResponse21.getTransactionExceptionCode()).isEqualTo(globalBeginResponse1.getTransactionExceptionCode());
GlobalBeginResponse globalBeginResponse22 = (GlobalBeginResponse) mergeResultMessage2.msgs[1];
assertThat(globalBeginResponse22.getXid()).isEqualTo(globalBeginResponse2.getXid());
assertThat(globalBeginResponse22.getExtraData()).isEqualTo(globalBeginResponse2.getExtraData());
assertThat(globalBeginResponse22.getMsg()).isEqualTo(globalBeginResponse2.getMsg());
assertThat(globalBeginResponse22.getResultCode()).isEqualTo(globalBeginResponse2.getResultCode());
assertThat(globalBeginResponse22.getTransactionExceptionCode()).isEqualTo(globalBeginResponse2.getTransactionExceptionCode());
}
use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.
the class MergeResultMessageSerializerTest method buildGlobalBeginResponse.
private GlobalBeginResponse buildGlobalBeginResponse(String xid) {
final GlobalBeginResponse globalBeginResponse = new GlobalBeginResponse();
globalBeginResponse.setXid(xid);
globalBeginResponse.setExtraData("data");
globalBeginResponse.setMsg("success");
globalBeginResponse.setResultCode(ResultCode.Failed);
globalBeginResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
return globalBeginResponse;
}
use of io.seata.core.protocol.transaction.GlobalBeginResponse in project seata by seata.
the class MergeResultMessageTest method getAndSetMsgs.
@Test
public void getAndSetMsgs() {
MergeResultMessage mergeResultMessage = new MergeResultMessage();
final AbstractResultMessage[] msgs = new AbstractResultMessage[1];
final GlobalBeginResponse globalBeginResponse = buildGlobalBeginResponse();
msgs[0] = globalBeginResponse;
mergeResultMessage.setMsgs(msgs);
assertThat(globalBeginResponse).isEqualTo(mergeResultMessage.getMsgs()[0]);
}
Aggregations