Search in sources :

Example 16 with TestPinpointServerAcceptor

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

the class PinpointClientStateTest method closeStateTest.

@Test
public void closeStateTest() throws InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    DefaultPinpointClientFactory clientSocketFactory = null;
    DefaultPinpointClientHandler handler = null;
    try {
        clientSocketFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), testServerMessageListenerFactory.create());
        handler = connect(clientSocketFactory, bindPort);
        assertHandlerState(SocketStateCode.RUN_DUPLEX, handler);
        handler.close();
        assertHandlerState(SocketStateCode.CLOSED_BY_CLIENT, handler);
    } finally {
        closeHandler(handler);
        closeSocketFactory(clientSocketFactory);
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) Test(org.junit.Test)

Example 17 with TestPinpointServerAcceptor

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

the class PinpointClientStateTest method unexpectedCloseByPeerStateTest.

@Test
public void unexpectedCloseByPeerStateTest() throws InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    DefaultPinpointClientFactory clientFactory = null;
    DefaultPinpointClientHandler handler = null;
    try {
        clientFactory = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), testServerMessageListenerFactory.create());
        handler = connect(clientFactory, bindPort);
        assertHandlerState(SocketStateCode.RUN_DUPLEX, handler);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        ((DefaultPinpointServer) pinpointServer).stop(true);
        assertHandlerState(SocketStateCode.UNEXPECTED_CLOSE_BY_SERVER, handler);
    } finally {
        closeHandler(handler);
        closeSocketFactory(clientFactory);
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) DefaultPinpointServer(com.navercorp.pinpoint.rpc.server.DefaultPinpointServer) Test(org.junit.Test)

Example 18 with TestPinpointServerAcceptor

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

the class PinpointServerSocketTest method testBind.

@Test
public void testBind() throws Exception {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(new DiscardServerHandler());
    int bindPort = testPinpointServerAcceptor.bind();
    Socket socket = new Socket("127.0.0.1", bindPort);
    socket.getOutputStream().write(new byte[0]);
    socket.getOutputStream().flush();
    socket.close();
    Thread.sleep(1000);
    testPinpointServerAcceptor.close();
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) DiscardServerHandler(com.navercorp.pinpoint.rpc.DiscardServerHandler) Socket(java.net.Socket) Test(org.junit.Test)

Example 19 with TestPinpointServerAcceptor

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

Example 20 with TestPinpointServerAcceptor

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

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