Search in sources :

Example 1 with TestRawSocket

use of com.navercorp.pinpoint.test.client.TestRawSocket 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 2 with TestRawSocket

use of com.navercorp.pinpoint.test.client.TestRawSocket 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)

Example 3 with TestRawSocket

use of com.navercorp.pinpoint.test.client.TestRawSocket in project pinpoint by naver.

the class HealthCheckTest method healthCheckTest.

@Test
public void healthCheckTest() 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);
        // RUN_WITHOUT_HANDSHAKE
        sendPingAndReceivePongPacket(testRawSocket, new PingPayloadPacket(1, (byte) 1, (byte) 10));
    } finally {
        testRawSocket.close();
        testPinpointServerAcceptor.close();
    }
    Assert.assertTrue(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) PingPayloadPacket(com.navercorp.pinpoint.rpc.packet.PingPayloadPacket) Test(org.junit.Test)

Example 4 with TestRawSocket

use of com.navercorp.pinpoint.test.client.TestRawSocket in project pinpoint by naver.

the class EventHandlerTest method registerAgentSuccessTest.

// Test for being possible to send messages in case of failure of registering packet ( return code : 2, lack of parameter)
@Test
public void registerAgentSuccessTest() throws Exception {
    EventHandler eventHandler = new EventHandler();
    PinpointServerAcceptor serverAcceptor = new PinpointServerAcceptor();
    serverAcceptor.addStateChangeEventHandler(eventHandler);
    serverAcceptor.setMessageListenerFactory(testServerMessageListenerFactory);
    serverAcceptor.bind("127.0.0.1", bindPort);
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendAndReceiveSimplePacket(testRawSocket);
        Assert.assertEquals(eventHandler.getCode(), SocketStateCode.RUN_WITHOUT_HANDSHAKE);
        int code = sendAndReceiveRegisterPacket(testRawSocket, PinpointRPCTestUtils.getParams());
        Assert.assertEquals(eventHandler.getCode(), SocketStateCode.RUN_DUPLEX);
        sendAndReceiveSimplePacket(testRawSocket);
    } finally {
        testRawSocket.close();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) ServerStateChangeEventHandler(com.navercorp.pinpoint.rpc.server.handler.ServerStateChangeEventHandler) Test(org.junit.Test)

Example 5 with TestRawSocket

use of com.navercorp.pinpoint.test.client.TestRawSocket in project pinpoint by naver.

the class ControlPacketServerTest method registerAgentTest3.

// when failure of registering and retrying to register, confirm to return same code ( return code : 2
@Test
public void registerAgentTest3() throws Exception {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new HandshakeVerifyMessageListenerFactory());
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        int code = sendAndReceiveRegisterPacket(testRawSocket);
        Assert.assertEquals(2, code);
        code = sendAndReceiveRegisterPacket(testRawSocket);
        Assert.assertEquals(2, code);
        sendAndReceiveSimplePacket(testRawSocket);
    } finally {
        testRawSocket.close();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Test(org.junit.Test)

Aggregations

TestRawSocket (com.navercorp.pinpoint.test.client.TestRawSocket)13 Test (org.junit.Test)13 TestPinpointServerAcceptor (com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor)11 TestServerMessageListenerFactory (com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory)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 PingPacket (com.navercorp.pinpoint.rpc.packet.PingPacket)1 PingSimplePacket (com.navercorp.pinpoint.rpc.packet.PingSimplePacket)1 ServerStateChangeEventHandler (com.navercorp.pinpoint.rpc.server.handler.ServerStateChangeEventHandler)1 Ignore (org.junit.Ignore)1