use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class AbstractCore method branchCommit.
@Override
public BranchStatus branchCommit(GlobalSession globalSession, BranchSession branchSession) throws TransactionException {
try {
BranchCommitRequest request = new BranchCommitRequest();
request.setXid(branchSession.getXid());
request.setBranchId(branchSession.getBranchId());
request.setResourceId(branchSession.getResourceId());
request.setApplicationData(branchSession.getApplicationData());
request.setBranchType(branchSession.getBranchType());
return branchCommitSend(request, globalSession, branchSession);
} catch (IOException | TimeoutException e) {
throw new BranchTransactionException(FailedToSendBranchCommitRequest, String.format("Send branch commit failed, xid = %s branchId = %s", branchSession.getXid(), branchSession.getBranchId()), e);
}
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class BranchCommitRequestSerializerTest method test_codec.
/**
* Test codec.
*/
@Test
public void test_codec() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setApplicationData("abc");
branchCommitRequest.setBranchId(123);
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setResourceId("t");
branchCommitRequest.setXid("a3");
byte[] bytes = seataSerializer.serialize(branchCommitRequest);
BranchCommitRequest branchCommitReques2 = seataSerializer.deserialize(bytes);
assertThat(branchCommitReques2.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
assertThat(branchCommitReques2.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(branchCommitReques2.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(branchCommitReques2.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(branchCommitReques2.getXid()).isEqualTo(branchCommitRequest.getXid());
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class ProtocolV1Client method main.
// can test tps
public static void main(String[] args) {
ProtocolV1Client client = new ProtocolV1Client();
client.connect("127.0.0.1", 8811, 500);
Map<String, String> head = new HashMap<>();
head.put("tracerId", "xxadadadada");
head.put("token", "adadadad");
BranchCommitRequest body = new BranchCommitRequest();
body.setBranchId(12345L);
body.setApplicationData("application");
body.setBranchType(BranchType.AT);
body.setResourceId("resource-1234");
body.setXid("xid-1234");
final int threads = 50;
final AtomicLong cnt = new AtomicLong(0);
// no queue
final ThreadPoolExecutor service1 = new ThreadPoolExecutor(threads, threads, 0L, TimeUnit.MILLISECONDS, new SynchronousQueue<Runnable>(), new NamedThreadFactory("client-", false));
for (int i = 0; i < threads; i++) {
service1.execute(() -> {
while (true) {
try {
Future future = client.sendRpc(head, body);
RpcMessage resp = (RpcMessage) future.get(200, TimeUnit.MILLISECONDS);
if (resp != null) {
cnt.incrementAndGet();
}
} catch (Exception e) {
// ignore
}
}
});
}
Thread thread = new Thread(new Runnable() {
private long last = 0;
@Override
public void run() {
while (true) {
long count = cnt.get();
long tps = count - last;
LOGGER.error("last 1s invoke: {}, queue: {}", tps, service1.getQueue().size());
last = count;
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
}
}
}, "Print-tps-THREAD");
thread.start();
}
use of io.seata.core.protocol.transaction.BranchCommitRequest in project seata by seata.
the class HessianSerializerTest 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 = hessianCodec.serialize(branchCommitRequest);
BranchCommitRequest t = hessianCodec.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 BranchCommitRequestConvertorTest method convert2Proto.
@Test
public void convert2Proto() {
BranchCommitRequest branchCommitRequest = new BranchCommitRequest();
branchCommitRequest.setBranchType(BranchType.AT);
branchCommitRequest.setXid("xid");
branchCommitRequest.setResourceId("resourceId");
branchCommitRequest.setBranchId(123);
branchCommitRequest.setApplicationData("app");
BranchCommitRequestConvertor branchCommitRequestConvertor = new BranchCommitRequestConvertor();
BranchCommitRequestProto proto = branchCommitRequestConvertor.convert2Proto(branchCommitRequest);
BranchCommitRequest realRequest = branchCommitRequestConvertor.convert2Model(proto);
assertThat(realRequest.getTypeCode()).isEqualTo(branchCommitRequest.getTypeCode());
assertThat(realRequest.getBranchType()).isEqualTo(branchCommitRequest.getBranchType());
assertThat(realRequest.getXid()).isEqualTo(branchCommitRequest.getXid());
assertThat(realRequest.getResourceId()).isEqualTo(branchCommitRequest.getResourceId());
assertThat(realRequest.getBranchId()).isEqualTo(branchCommitRequest.getBranchId());
assertThat(realRequest.getApplicationData()).isEqualTo(branchCommitRequest.getApplicationData());
}
Aggregations