use of io.seata.core.protocol.RpcMessage 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