Search in sources :

Example 41 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class StreamChannelManagerTest method streamSuccessTest2.

// Client to Server Stream
@Test
public void streamSuccessTest2() throws IOException, InterruptedException, StreamException {
    SimpleStreamBO bo = new SimpleStreamBO();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory, new ServerListener(bo));
    int bindPort = testPinpointServerAcceptor.bind();
    TestPinpointClient testPinpointClient = new TestPinpointClient();
    try {
        testPinpointClient.connect(bindPort);
        RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
        ClientStreamChannel clientStreamChannel = testPinpointClient.openStream(new byte[0], clientListener);
        RecordedStreamChannelMessageListener clientListener2 = new RecordedStreamChannelMessageListener(8);
        ClientStreamChannel clientStreamChannel2 = testPinpointClient.openStream(new byte[0], clientListener2);
        int sendCount = 4;
        for (int i = 0; i < sendCount; i++) {
            sendRandomBytes(bo);
        }
        clientListener.getLatch().await();
        Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
        clientStreamChannel.close();
        sendCount = 4;
        for (int i = 0; i < sendCount; i++) {
            sendRandomBytes(bo);
        }
        clientListener2.getLatch().await();
        Assert.assertEquals(sendCount, clientListener.getReceivedMessage().size());
        Assert.assertEquals(8, clientListener2.getReceivedMessage().size());
        clientStreamChannel2.close();
    } finally {
        testPinpointClient.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) RecordedStreamChannelMessageListener(com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener) Test(org.junit.Test)

Example 42 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class PinpointClientFactoryTest method requestAndResponse.

@Test
public void requestAndResponse() throws IOException, InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX));
    int bindPort = testPinpointServerAcceptor.bind();
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        byte[] randomByte = TestByteUtils.createRandomByte(20);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
        PinpointRPCTestUtils.close(client);
    } finally {
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) Test(org.junit.Test)

Example 43 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class PinpointClientFactoryTest method sendSync.

@Test
public void sendSync() throws IOException, InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
    int bindPort = testPinpointServerAcceptor.bind();
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        logger.debug("send1");
        client.send(new byte[20]);
        logger.debug("send2");
        client.sendSync(new byte[20]);
        PinpointRPCTestUtils.close(client);
    } finally {
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Test(org.junit.Test)

Example 44 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class ReconnectTest method scheduledConnect.

@Test
public void scheduledConnect() throws IOException, InterruptedException {
    final PinpointClientFactory clientFactory = new DefaultPinpointClientFactory();
    clientFactory.setReconnectDelay(200);
    PinpointClient client = null;
    TestPinpointServerAcceptor testPinpointServerAcceptor = null;
    try {
        int availableTcpPort = SocketUtils.findAvailableTcpPort(47000);
        client = clientFactory.scheduledConnect("localhost", availableTcpPort);
        testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
        testPinpointServerAcceptor.bind(availableTcpPort);
        assertClientConnected(client);
        logger.debug("request server");
        byte[] randomByte = TestByteUtils.createRandomByte(10);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
    } finally {
        PinpointRPCTestUtils.close(client);
        clientFactory.release();
        TestPinpointServerAcceptor.staticClose(testPinpointServerAcceptor);
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Test(org.junit.Test)

Example 45 with TestPinpointServerAcceptor

use of com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor in project pinpoint by naver.

the class ReconnectTest method reconnectStressTest.

// it takes very long time.
// @Test
@Ignore
public void reconnectStressTest() throws IOException, InterruptedException {
    int count = 3;
    ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
    int threadCount = tbean.getThreadCount();
    for (int i = 0; i < count; i++) {
        logger.debug((i + 1) + "th's start.");
        TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor();
        int bindPort = testPinpointServerAcceptor.bind();
        PinpointClient client = clientFactory.connect("localhost", bindPort);
        testPinpointServerAcceptor.close();
        logger.debug("server.close");
        assertClientDisconnected(client);
        testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
        logger.debug("bind server");
        assertClientConnected(client);
        logger.debug("request server");
        byte[] randomByte = TestByteUtils.createRandomByte(10);
        byte[] response = PinpointRPCTestUtils.request(client, randomByte);
        Assert.assertArrayEquals(randomByte, response);
        PinpointRPCTestUtils.close(client);
        testPinpointServerAcceptor.close();
    }
    Thread.sleep(10000);
    Assert.assertEquals(threadCount, tbean.getThreadCount());
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Ignore(org.junit.Ignore)

Aggregations

TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)52 Test (org.junit.Test)50 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)13 TestRawSocket (com.navercorp.pinpoint.test.client.TestRawSocket)11 TestServerMessageListenerFactory (com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory)11 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)10 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)10 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)10 MetaDataType (com.navercorp.pinpoint.profiler.metadata.MetaDataType)8 RecordedStreamChannelMessageListener (com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener)6 IOException (java.io.IOException)6 PinpointSocketException (com.navercorp.pinpoint.rpc.PinpointSocketException)3 ResponseMessage (com.navercorp.pinpoint.rpc.ResponseMessage)3 ProtocolException (com.navercorp.pinpoint.rpc.control.ProtocolException)3 PingPayloadPacket (com.navercorp.pinpoint.rpc.packet.PingPayloadPacket)3 Ignore (org.junit.Ignore)3 ServerMetaDataRegistryService (com.navercorp.pinpoint.profiler.context.ServerMetaDataRegistryService)2 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientReconnectEventListener (com.navercorp.pinpoint.rpc.client.PinpointClientReconnectEventListener)2 PinpointServer (com.navercorp.pinpoint.rpc.server.PinpointServer)2