Search in sources :

Example 6 with BranchCommitRequest

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;
}
Also used : BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest)

Example 7 with 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());
}
Also used : BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) Test(org.junit.jupiter.api.Test)

Example 8 with BranchCommitRequest

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());
}
Also used : BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) Test(org.junit.jupiter.api.Test)

Example 9 with BranchCommitRequest

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());
}
Also used : BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) Test(org.junit.jupiter.api.Test)

Example 10 with BranchCommitRequest

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();
    }
}
Also used : HashMap(java.util.HashMap) NamedThreadFactory(io.seata.common.thread.NamedThreadFactory) BranchCommitRequest(io.seata.core.protocol.transaction.BranchCommitRequest) CountDownLatch(java.util.concurrent.CountDownLatch) RpcMessage(io.seata.core.protocol.RpcMessage) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Future(java.util.concurrent.Future) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.jupiter.api.Test)

Aggregations

BranchCommitRequest (io.seata.core.protocol.transaction.BranchCommitRequest)12 Test (org.junit.jupiter.api.Test)7 NamedThreadFactory (io.seata.common.thread.NamedThreadFactory)2 BranchTransactionException (io.seata.core.exception.BranchTransactionException)2 RpcMessage (io.seata.core.protocol.RpcMessage)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Future (java.util.concurrent.Future)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 TimeoutException (java.util.concurrent.TimeoutException)2 ChannelFuture (io.netty.channel.ChannelFuture)1 TransactionException (io.seata.core.exception.TransactionException)1 FailedToSendBranchCommitRequest (io.seata.core.exception.TransactionExceptionCode.FailedToSendBranchCommitRequest)1 BranchCommitResponse (io.seata.core.protocol.transaction.BranchCommitResponse)1 BranchCommitRequestProto (io.seata.serializer.protobuf.generated.BranchCommitRequestProto)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1