Search in sources :

Example 1 with MemoryPrinter

use of com.ctrip.xpipe.testutils.MemoryPrinter in project x-pipe by ctripcorp.

the class ByteArrayOutputStreamPayloadTest method testNewHeap.

@Test
public void testNewHeap() throws Exception {
    final MemoryPrinter memoryPrinter = new MemoryPrinter(scheduled);
    memoryPrinter.printMemory();
    final int length = 1 << 10;
    int concurrentCount = 10;
    final CountDownLatch latch = new CountDownLatch(concurrentCount);
    final ByteBuf byteBuf = directByteBuf(length);
    byteBuf.writeBytes(randomString(length).getBytes());
    byte[] dst = new byte[length];
    byteBuf.readBytes(dst);
    memoryPrinter.printMemory();
    for (int i = 0; i < concurrentCount; i++) {
        Thread current = new Thread(new AbstractExceptionLogTask() {

            @Override
            protected void doRun() throws Exception {
                try {
                    byteBuf.readerIndex(0);
                    ByteArrayOutputStream baous = new ByteArrayOutputStream();
                    byteBuf.readBytes(baous, length);
                } finally {
                    latch.countDown();
                }
            }
        });
        current.start();
        memoryPrinter.printMemory();
    }
    latch.await();
}
Also used : AbstractExceptionLogTask(com.ctrip.xpipe.concurrent.AbstractExceptionLogTask) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MemoryPrinter(com.ctrip.xpipe.testutils.MemoryPrinter) CountDownLatch(java.util.concurrent.CountDownLatch) ByteBuf(io.netty.buffer.ByteBuf) IOException(java.io.IOException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 2 with MemoryPrinter

use of com.ctrip.xpipe.testutils.MemoryPrinter in project x-pipe by ctripcorp.

the class AbstractMetaServerTest method beforeAbstractMetaServerTest.

@Before
public void beforeAbstractMetaServerTest() throws Exception {
    memoryPrinter = new MemoryPrinter(scheduled, 500);
    memoryPrinter.start();
}
Also used : MemoryPrinter(com.ctrip.xpipe.testutils.MemoryPrinter) Before(org.junit.Before)

Aggregations

MemoryPrinter (com.ctrip.xpipe.testutils.MemoryPrinter)2 AbstractTest (com.ctrip.xpipe.AbstractTest)1 AbstractExceptionLogTask (com.ctrip.xpipe.concurrent.AbstractExceptionLogTask)1 ByteBuf (io.netty.buffer.ByteBuf)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Before (org.junit.Before)1 Test (org.junit.Test)1