use of io.seata.core.protocol.transaction.BranchCommitResponse in project seata by seata.
the class BranchCommitResponseSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
branchCommitResponse.setBranchId(123);
branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
branchCommitResponse.setMsg("abc");
branchCommitResponse.setXid("a3");
branchCommitResponse.setResultCode(ResultCode.Failed);
byte[] bytes = seataSerializer.serialize(branchCommitResponse);
BranchCommitResponse branchCommitResponse2 = seataSerializer.deserialize(bytes);
assertThat(branchCommitResponse2.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus());
assertThat(branchCommitResponse2.getBranchId()).isEqualTo(branchCommitResponse.getBranchId());
assertThat(branchCommitResponse2.getMsg()).isEqualTo(branchCommitResponse.getMsg());
assertThat(branchCommitResponse2.getXid()).isEqualTo(branchCommitResponse.getXid());
assertThat(branchCommitResponse2.getResultCode()).isEqualTo(branchCommitResponse.getResultCode());
}
use of io.seata.core.protocol.transaction.BranchCommitResponse in project seata by seata.
the class SagaCore method branchCommitSend.
@Override
public BranchStatus branchCommitSend(BranchCommitRequest request, GlobalSession globalSession, BranchSession branchSession) throws IOException, TimeoutException {
Map<String, Channel> channels = ChannelManager.getRmChannels();
if (CollectionUtils.isEmpty(channels)) {
LOGGER.error("Failed to commit SAGA global[" + globalSession.getXid() + ", RM channels is empty.");
return BranchStatus.PhaseTwo_CommitFailed_Retryable;
}
String sagaResourceId = getSagaResourceId(globalSession);
Channel sagaChannel = channels.get(sagaResourceId);
if (sagaChannel == null) {
LOGGER.error("Failed to commit SAGA global[" + globalSession.getXid() + ", cannot find channel by resourceId[" + sagaResourceId + "]");
return BranchStatus.PhaseTwo_CommitFailed_Retryable;
}
BranchCommitResponse response = (BranchCommitResponse) remotingServer.sendSyncRequest(sagaChannel, request);
return response.getBranchStatus();
}
use of io.seata.core.protocol.transaction.BranchCommitResponse in project seata by seata.
the class BranchCommitResponseConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
branchCommitResponse.setResultCode(ResultCode.Success);
branchCommitResponse.setMsg("xx");
branchCommitResponse.setXid("xid");
branchCommitResponse.setBranchStatus(BranchStatus.PhaseTwo_Rollbacked);
branchCommitResponse.setBranchId(123);
BranchCommitResponseConvertor convertor = new BranchCommitResponseConvertor();
BranchCommitResponseProto proto = convertor.convert2Proto(branchCommitResponse);
BranchCommitResponse real = convertor.convert2Model(proto);
assertThat(real.getTypeCode()).isEqualTo(branchCommitResponse.getTypeCode());
assertThat(real.getMsg()).isEqualTo(branchCommitResponse.getMsg());
assertThat(real.getXid()).isEqualTo(branchCommitResponse.getXid());
assertThat(real.getTransactionExceptionCode()).isEqualTo(branchCommitResponse.getTransactionExceptionCode());
assertThat(real.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus());
assertThat(real.getResultCode()).isEqualTo(branchCommitResponse.getResultCode());
}
use of io.seata.core.protocol.transaction.BranchCommitResponse in project seata by seata.
the class BranchCommitResponseConvertor method convert2Model.
@Override
public BranchCommitResponse convert2Model(BranchCommitResponseProto branchCommitResponseProto) {
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setBranchId(branchCommitResponseProto.getAbstractBranchEndResponse().getBranchId());
branchCommitResponse.setBranchStatus(BranchStatus.get(branchCommitResponseProto.getAbstractBranchEndResponse().getBranchStatusValue()));
branchCommitResponse.setXid(branchCommitResponseProto.getAbstractBranchEndResponse().getXid());
branchCommitResponse.setMsg(branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getAbstractResultMessage().getMsg());
branchCommitResponse.setResultCode(ResultCode.valueOf(branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getAbstractResultMessage().getResultCode().name()));
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf(branchCommitResponseProto.getAbstractBranchEndResponse().getAbstractTransactionResponse().getTransactionExceptionCode().name()));
return branchCommitResponse;
}
use of io.seata.core.protocol.transaction.BranchCommitResponse in project seata by seata.
the class FstSerializerTest method testBranchCommitResponse.
@Test
public void testBranchCommitResponse() {
BranchCommitResponse branchCommitResponse = new BranchCommitResponse();
branchCommitResponse.setTransactionExceptionCode(TransactionExceptionCode.BranchTransactionNotExist);
branchCommitResponse.setBranchId(20190809);
branchCommitResponse.setBranchStatus(BranchStatus.PhaseOne_Done);
branchCommitResponse.setMsg("20190809");
branchCommitResponse.setXid("20190809");
branchCommitResponse.setResultCode(ResultCode.Failed);
byte[] bytes = fstSerializer.serialize(branchCommitResponse);
BranchCommitResponse t = fstSerializer.deserialize(bytes);
assertThat(t.getTransactionExceptionCode()).isEqualTo(branchCommitResponse.getTransactionExceptionCode());
assertThat(t.getBranchId()).isEqualTo(branchCommitResponse.getBranchId());
assertThat(t.getBranchStatus()).isEqualTo(branchCommitResponse.getBranchStatus());
assertThat(t.getMsg()).isEqualTo(branchCommitResponse.getMsg());
assertThat(t.getResultCode()).isEqualTo(branchCommitResponse.getResultCode());
}
Aggregations