Search in sources :

Example 1 with BranchRegisterResponse

use of io.seata.core.protocol.transaction.BranchRegisterResponse in project seata by seata.

the class TmNettyClientTest method testSendMsgWithResponse.

@Test
public void testSendMsgWithResponse() throws Exception {
    workingThreads.submit(new Runnable() {

        @Override
        public void run() {
            NettyRemotingServer nettyRemotingServer = new NettyRemotingServer(workingThreads);
            nettyRemotingServer.setHandler(new DefaultCoordinator(nettyRemotingServer));
            UUIDGenerator.init(1L);
            nettyRemotingServer.init();
        }
    });
    Thread.sleep(3000);
    String applicationId = "app 1";
    String transactionServiceGroup = "my_test_tx_group";
    TmNettyRemotingClient tmNettyRemotingClient = TmNettyRemotingClient.getInstance(applicationId, transactionServiceGroup);
    tmNettyRemotingClient.init();
    Method doConnectMethod = TmNettyRemotingClient.class.getDeclaredMethod("doConnect", String.class);
    doConnectMethod.setAccessible(true);
    String serverAddress = "0.0.0.0:8091";
    Channel channel = (Channel) doConnectMethod.invoke(tmNettyRemotingClient, serverAddress);
    Assertions.assertNotNull(channel);
    BranchRegisterRequest request = new BranchRegisterRequest();
    request.setXid("127.0.0.1:8091:1249853");
    request.setLockKey("lock key testSendMsgWithResponse");
    request.setResourceId("resoutceId1");
    BranchRegisterResponse branchRegisterResponse = (BranchRegisterResponse) tmNettyRemotingClient.sendSyncRequest(request);
    Assertions.assertNotNull(branchRegisterResponse);
    Assertions.assertEquals(ResultCode.Failed, branchRegisterResponse.getResultCode());
    Assertions.assertEquals("RuntimeException[SessionManager is NOT init!]", branchRegisterResponse.getMsg());
}
Also used : BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse) BranchRegisterRequest(io.seata.core.protocol.transaction.BranchRegisterRequest) Channel(io.netty.channel.Channel) DefaultCoordinator(io.seata.server.coordinator.DefaultCoordinator) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 2 with BranchRegisterResponse

use of io.seata.core.protocol.transaction.BranchRegisterResponse in project seata by seata.

the class BranchRegisterResponseConvertorTest method convert2Proto.

@Test
public void convert2Proto() {
    BranchRegisterResponse branchRegisterResponse = new BranchRegisterResponse();
    branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.GlobalTransactionNotActive);
    branchRegisterResponse.setResultCode(ResultCode.Failed);
    branchRegisterResponse.setMsg("msg");
    branchRegisterResponse.setBranchId(123);
    BranchRegisterResponseConvertor convertor = new BranchRegisterResponseConvertor();
    BranchRegisterResponseProto proto = convertor.convert2Proto(branchRegisterResponse);
    BranchRegisterResponse real = convertor.convert2Model(proto);
    assertThat(real.getTransactionExceptionCode()).isEqualTo(branchRegisterResponse.getTransactionExceptionCode());
    assertThat(real.getResultCode()).isEqualTo(branchRegisterResponse.getResultCode());
    assertThat(real.getMsg()).isEqualTo(branchRegisterResponse.getMsg());
    assertThat(real.getBranchId()).isEqualTo(branchRegisterResponse.getBranchId());
}
Also used : BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse) BranchRegisterResponseProto(io.seata.serializer.protobuf.generated.BranchRegisterResponseProto) Test(org.junit.jupiter.api.Test)

Example 3 with BranchRegisterResponse

use of io.seata.core.protocol.transaction.BranchRegisterResponse in project seata by seata.

the class BranchRegisterResponseCodec method encode.

@Override
public <T> void encode(T t, ByteBuf out) {
    super.encode(t, out);
    BranchRegisterResponse branchRegisterResponse = (BranchRegisterResponse) t;
    long branchId = branchRegisterResponse.getBranchId();
    out.writeLong(branchId);
}
Also used : BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse)

Example 4 with BranchRegisterResponse

use of io.seata.core.protocol.transaction.BranchRegisterResponse in project seata by seata.

the class BranchRegisterResponseCodec method decode.

@Override
public <T> void decode(T t, ByteBuffer in) {
    super.decode(t, in);
    BranchRegisterResponse branchRegisterResponse = (BranchRegisterResponse) t;
    branchRegisterResponse.setBranchId(in.getLong());
}
Also used : BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse)

Example 5 with BranchRegisterResponse

use of io.seata.core.protocol.transaction.BranchRegisterResponse in project seata by seata.

the class AbstractTCInboundHandler method handle.

@Override
public BranchRegisterResponse handle(BranchRegisterRequest request, final RpcContext rpcContext) {
    BranchRegisterResponse response = new BranchRegisterResponse();
    exceptionHandleTemplate(new AbstractCallback<BranchRegisterRequest, BranchRegisterResponse>() {

        @Override
        public void execute(BranchRegisterRequest request, BranchRegisterResponse response) throws TransactionException {
            try {
                doBranchRegister(request, response, rpcContext);
            } catch (StoreException e) {
                throw new TransactionException(TransactionExceptionCode.FailedStore, String.format("branch register request failed. xid=%s, msg=%s", request.getXid(), e.getMessage()), e);
            }
        }
    }, request, response);
    return response;
}
Also used : TransactionException(io.seata.core.exception.TransactionException) BranchRegisterResponse(io.seata.core.protocol.transaction.BranchRegisterResponse) BranchRegisterRequest(io.seata.core.protocol.transaction.BranchRegisterRequest) StoreException(io.seata.common.exception.StoreException)

Aggregations

BranchRegisterResponse (io.seata.core.protocol.transaction.BranchRegisterResponse)9 Test (org.junit.jupiter.api.Test)4 BranchRegisterRequest (io.seata.core.protocol.transaction.BranchRegisterRequest)3 Channel (io.netty.channel.Channel)1 StoreException (io.seata.common.exception.StoreException)1 RmTransactionException (io.seata.core.exception.RmTransactionException)1 TransactionException (io.seata.core.exception.TransactionException)1 AbstractResultMessageProto (io.seata.serializer.protobuf.generated.AbstractResultMessageProto)1 BranchRegisterResponseProto (io.seata.serializer.protobuf.generated.BranchRegisterResponseProto)1 DefaultCoordinator (io.seata.server.coordinator.DefaultCoordinator)1 Method (java.lang.reflect.Method)1 TimeoutException (java.util.concurrent.TimeoutException)1