use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class BranchCommitRequestConvertor method convert2Model.
@Override
public BranchCommitRequest convert2Model(BranchCommitRequestProto branchCommitRequestProto) {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setApplicationData(branchCommitRequestProto.getAbstractBranchEndRequest().getApplicationData());
branchCommitRequest.setBranchId(branchCommitRequestProto.getAbstractBranchEndRequest().getBranchId());
branchCommitRequest.setResourceId(branchCommitRequestProto.getAbstractBranchEndRequest().getResourceId());
branchCommitRequest.setXid(branchCommitRequestProto.getAbstractBranchEndRequest().getXid());
branchCommitRequest.setBranchType(BranchType.valueOf(branchCommitRequestProto.getAbstractBranchEndRequest().getBranchType().name()));
return branchCommitRequest;
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class FstSerializerTest method testBranchCommitRequest.
@Test
public void testBranchCommitRequest() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setXid("xid");
branchCommitRequest.setResourceId("resourceId");
branchCommitRequest.setBranchId(20190809);
branchCommitRequest.setApplicationData("app");
byte[] bytes = fstSerializer.serialize(branchCommitRequest);
BranchCommitRequest t = fstSerializer.deserialize(bytes);
assertThat(t.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
assertThat(t.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(t.getXid()).isEqualTo(branchCommitRequest.getXid());
assertThat(t.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(t.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(t.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class KryoSerializerTest method testBranchCommitRequest.
@Test
public void testBranchCommitRequest() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setXid("xid");
branchCommitRequest.setResourceId("resourceId");
branchCommitRequest.setBranchId(20190809);
branchCommitRequest.setApplicationData("app");
byte[] bytes = kryoCodec.serialize(branchCommitRequest);
BranchCommitRequest t = kryoCodec.deserialize(bytes);
assertThat(t.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
assertThat(t.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(t.getXid()).isEqualTo(branchCommitRequest.getXid());
assertThat(t.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(t.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(t.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class BranchCommitRequestTest method toStringTest.
/**
* To string test.
*
* @throws Exception the exception
*/
@Test
public void toStringTest() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setXid("127.0.0.1:9999:39875642");
branchCommitRequest.setBranchId(1);
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setResourceId("resource1");
branchCommitRequest.setApplicationData("app1");
Assertions.assertEquals("xid=127.0.0.1:9999:39875642,branchId=1,branchType=AT," + "resourceId=resource1,applicationData=app1", branchCommitRequest.toString());
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class ProtocolV1SerializerTest method testAll.
@Test
public void testAll() {
ProtocolV1Server server = new ProtocolV1Server();
ProtocolV1Client client = new ProtocolV1Client();
try {
server.start();
client.connect("127.0.0.1", 8811, 500);
Assertions.assertTrue(client.channel.isActive());
Map<String, String> head = new HashMap<>();
head.put("tracerId", "xxadadadada");
head.put("token", "adadadad");
head.put("hello", null);
BranchCommitRequest body = new BranchCommitRequest();
body.setBranchId(12345L);
body.setApplicationData("application");
body.setBranchType(BranchType.AT);
body.setResourceId("resource-1234");
body.setXid("xid-1234");
// test run times
int runTimes = 100000;
final int threads = 50;
final CountDownLatch cnt = new CountDownLatch(runTimes);
final AtomicInteger tag = new AtomicInteger(0);
final AtomicInteger success = new AtomicInteger(0);
// no queue
final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<>(), new NamedThreadFactory("client-", false));
for (int i = 0; i < threads; i++) {
service1.execute(() -> {
while (tag.getAndIncrement() < runTimes) {
try {
Future future = client.sendRpc(head, body);
RpcMessage resp = (RpcMessage) future.get(10, TimeUnit.SECONDS);
if (resp != null) {
success.incrementAndGet();
}
} catch (Exception e) {
LOGGER.error("Client send error", e);
} finally {
cnt.countDown();
}
}
});
}
cnt.await();
LOGGER.info("success {}/{}", success.get(), runTimes);
Assertions.assertEquals(success.get(), runTimes);
} catch (InterruptedException e) {
LOGGER.error("Thread interrupted", e);
} finally {
client.close();
server.stop();
}
}
Aggregations