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());
}
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());
}
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);
}
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());
}
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;
}
Aggregations