Search in sources :

Example 1 with BranchCommitResponse

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

Example 2 with BranchCommitResponse

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();
}
Also used : BranchCommitResponse(io.seata.core.protocol.transaction.BranchCommitResponse) Channel(io.netty.channel.Channel)

Example 3 with BranchCommitResponse

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

Example 4 with BranchCommitResponse

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;
}
Also used : BranchCommitResponse(io.seata.core.protocol.transaction.BranchCommitResponse)

Example 5 with 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());
}
Also used : BranchCommitResponse(io.seata.core.protocol.transaction.BranchCommitResponse) Test(org.junit.jupiter.api.Test)

Aggregations

BranchCommitResponse (io.seata.core.protocol.transaction.BranchCommitResponse)11 Test (org.junit.jupiter.api.Test)6 Channel (io.netty.channel.Channel)2 TransactionException (io.seata.core.exception.TransactionException)1 BranchCommitRequest (io.seata.core.protocol.transaction.BranchCommitRequest)1 BranchCommitResponseProto (io.seata.serializer.protobuf.generated.BranchCommitResponseProto)1