Search in sources :

Example 6 with TestRawSocket

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

the class ControlPacketServerTest method registerAgentTest4.

// after success of registering, when success message are sent repeatedly.
// test 1) confirm to return success code, 2) confirm to return already success code.
@Test
public void registerAgentTest4() throws Exception {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new HandshakeVerifyMessageListenerFactory());
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendAndReceiveSimplePacket(testRawSocket);
        int code = sendAndReceiveRegisterPacket(testRawSocket, PinpointRPCTestUtils.getParams());
        Assert.assertEquals(0, code);
        sendAndReceiveSimplePacket(testRawSocket);
        code = sendAndReceiveRegisterPacket(testRawSocket, PinpointRPCTestUtils.getParams());
        Assert.assertEquals(1, 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)

Example 7 with TestRawSocket

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

the class ControlPacketServerTest method registerAgentTest1.

// Test for being possible to send messages in case of failure of registering packet ( return code : 2, lack of parameter)
@Test
public void registerAgentTest1() throws Exception {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new HandshakeVerifyMessageListenerFactory());
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendAndReceiveSimplePacket(testRawSocket);
        int 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)

Example 8 with TestRawSocket

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

the class ControlPacketServerTest method registerAgentTest2.

// Test for being possible to send messages in case of success of registering packet ( return code : 0)
@Test
public void registerAgentTest2() throws Exception {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new HandshakeVerifyMessageListenerFactory());
    int bindPort = testPinpointServerAcceptor.bind();
    TestRawSocket testRawSocket = new TestRawSocket();
    try {
        testRawSocket.connect(bindPort);
        sendAndReceiveSimplePacket(testRawSocket);
        int code = sendAndReceiveRegisterPacket(testRawSocket, PinpointRPCTestUtils.getParams());
        Assert.assertEquals(0, 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)

Example 9 with TestRawSocket

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

the class PinpointServerStateTest method unexpectedCloseByPeerTest.

@Test
public void unexpectedCloseByPeerTest() throws IOException, ProtocolException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    try {
        int bindPort = testPinpointServerAcceptor.bind();
        TestRawSocket testRawSocket = new TestRawSocket();
        testRawSocket.connect(bindPort);
        testRawSocket.sendHandshakePacket(PinpointRPCTestUtils.getParams());
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 1000);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        if (!(pinpointServer instanceof PinpointServer)) {
            testRawSocket.close();
            Assert.fail();
        }
        Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
        testRawSocket.close();
        assertPinpointServerState(SocketStateCode.UNEXPECTED_CLOSE_BY_CLIENT, (PinpointServer) pinpointServer);
    } finally {
        testPinpointServerAcceptor.close();
    }
}
Also used : TestRawSocket(com.navercorp.pinpoint.test.client.TestRawSocket) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Test(org.junit.Test)

Example 10 with TestRawSocket

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

the class HealthCheckTest method expiredHealthCheckTest.

@Ignore
@Test
public void expiredHealthCheckTest() 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);
        Thread.sleep(35 * 60 * 1000);
        sendPingAndReceivePongPacket(testRawSocket, new PingPayloadPacket(1, (byte) 1, (byte) 1));
        Assert.fail();
    } catch (Exception ignore) {
    } 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) PingPayloadPacket(com.navercorp.pinpoint.rpc.packet.PingPayloadPacket) ProtocolException(com.navercorp.pinpoint.rpc.control.ProtocolException) IOException(java.io.IOException) Ignore(org.junit.Ignore) 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