Search in sources :

Example 1 with TestServerMessageListenerFactory

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

the class PinpointClientFactoryTest method pingInternal.

@Test
public void pingInternal() throws IOException, InterruptedException {
    TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true);
    final TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    try {
        PinpointClient client = clientFactory.connect("127.0.0.1", bindPort);
        Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS).timeout(3000, TimeUnit.MILLISECONDS).until(new Callable<Boolean>() {

            @Override
            public Boolean call() {
                return serverMessageListener.hasReceivedPing();
            }
        });
        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 2 with TestServerMessageListenerFactory

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

the class PinpointClientFactoryTest method pingAndRequestResponse.

@Test
public void pingAndRequestResponse() 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(10);
        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 3 with TestServerMessageListenerFactory

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

the class ClientMessageListenerTest method clientMessageListenerTest2.

@Test
public void clientMessageListenerTest2() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestServerMessageListenerFactory.TestServerMessageListener echoMessageListener1 = testServerMessageListenerFactory.create();
    TestPinpointClient testPinpointClient1 = new TestPinpointClient(echoMessageListener1, PinpointRPCTestUtils.getParams());
    TestServerMessageListenerFactory.TestServerMessageListener echoMessageListener2 = testServerMessageListenerFactory.create();
    TestPinpointClient testPinpointClient2 = new TestPinpointClient(echoMessageListener2, PinpointRPCTestUtils.getParams());
    try {
        testPinpointClient1.connect(bindPort);
        testPinpointClient2.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(2, 1000);
        PinpointSocket writableServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        assertRequestMessage(writableServer, "socket1", null);
        PinpointSocket writableServer2 = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(1);
        assertRequestMessage(writableServer2, "socket2", null);
        echoMessageListener1.awaitAssertExpectedRequestCount(1, 0);
        echoMessageListener2.awaitAssertExpectedRequestCount(1, 0);
    } finally {
        testPinpointClient1.closeAll();
        testPinpointClient2.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) Test(org.junit.Test)

Example 4 with TestServerMessageListenerFactory

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

the class HealthCheckTest method legacyHealthCheckTest1.

@Test
public void legacyHealthCheckTest1() throws Exception {
    TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true);
    TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendPingAndReceivePongPacket(testRawSocket, PingPacket.PING_PACKET);
    } finally {
        testRawSocket.close();
        testPinpointServerAcceptor.close();
    }
    Assert.assertFalse(serverMessageListener.hasReceivedPing());
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) Test(org.junit.Test)

Example 5 with TestServerMessageListenerFactory

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

the class HealthCheckTest method healthCheckSimplePingTest.

@Test
public void healthCheckSimplePingTest() throws Exception {
    TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true);
    TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendPingAndReceivePongPacket(testRawSocket, new PingSimplePacket());
        Assert.fail();
    } catch (Exception e) {
    } finally {
        testRawSocket.close();
        testPinpointServerAcceptor.close();
    }
    Assert.assertFalse(serverMessageListener.hasReceivedPing());
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) PingSimplePacket(com.navercorp.pinpoint.rpc.packet.PingSimplePacket) ProtocolException(com.navercorp.pinpoint.rpc.control.ProtocolException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)11 TestServerMessageListenerFactory (com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory)11 Test (org.junit.Test)11 TestRawSocket (com.navercorp.pinpoint.test.client.TestRawSocket)6 ProtocolException (com.navercorp.pinpoint.rpc.control.ProtocolException)3 PingPayloadPacket (com.navercorp.pinpoint.rpc.packet.PingPayloadPacket)3 IOException (java.io.IOException)3 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)1 DefaultPinpointClientFactory (com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory)1 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)1 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)1 PingSimplePacket (com.navercorp.pinpoint.rpc.packet.PingSimplePacket)1 TestPinpointClient (com.navercorp.pinpoint.test.client.TestPinpointClient)1 TApiMetaData (com.navercorp.pinpoint.thrift.dto.TApiMetaData)1 Ignore (org.junit.Ignore)1