Search in sources :

Example 21 with TestPinpointServerAcceptor

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

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

the class PinpointServerStateTest method closeByPeerTest.

@Test
public void closeByPeerTest() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    TestPinpointClient testPinpointClient = new TestPinpointClient(testServerMessageListenerFactory.create(), PinpointRPCTestUtils.getParams());
    try {
        int bindPort = testPinpointServerAcceptor.bind();
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        if (pinpointServer instanceof PinpointServer) {
            Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
            testPinpointClient.disconnect();
            assertPinpointServerState(SocketStateCode.CLOSED_BY_CLIENT, (PinpointServer) pinpointServer);
        } else {
            Assert.fail();
        }
    } finally {
        testPinpointClient.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) Test(org.junit.Test)

Example 23 with TestPinpointServerAcceptor

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

the class PinpointServerStateTest method closeTest.

@Test
public void closeTest() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    TestPinpointClient testPinpointClient = new TestPinpointClient(testServerMessageListenerFactory.create(), PinpointRPCTestUtils.getParams());
    try {
        int bindPort = testPinpointServerAcceptor.bind();
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
        testPinpointServerAcceptor.close();
        assertPinpointServerState(SocketStateCode.CLOSED_BY_SERVER, (PinpointServer) pinpointServer);
    } finally {
        testPinpointClient.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) Test(org.junit.Test)

Example 24 with TestPinpointServerAcceptor

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

the class PinpointServerStateTest method unexpectedCloseTest.

@Test
public void unexpectedCloseTest() {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    TestPinpointClient testPinpointClient = new TestPinpointClient(testServerMessageListenerFactory.create(), PinpointRPCTestUtils.getParams());
    try {
        int bindPort = testPinpointServerAcceptor.bind();
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        PinpointSocket pinpointServer = testPinpointServerAcceptor.getConnectedPinpointSocketList().get(0);
        Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
        ((DefaultPinpointServer) pinpointServer).stop(true);
        assertPinpointServerState(SocketStateCode.UNEXPECTED_CLOSE_BY_SERVER, (PinpointServer) pinpointServer);
    } finally {
        testPinpointClient.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) Test(org.junit.Test)

Example 25 with TestPinpointServerAcceptor

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

the class StreamChannelManagerTest method streamClosedTest3.

// ServerSocket to Client Stream
// ServerStreamChannel first close.
@Test(expected = PinpointSocketException.class)
public void streamClosedTest3() throws IOException, InterruptedException, StreamException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    SimpleStreamBO bo = new SimpleStreamBO();
    ServerListener serverStreamChannelMessageHandler = new ServerListener(bo);
    TestPinpointClient testPinpointClient = new TestPinpointClient(SimpleMessageListener.INSTANCE, serverStreamChannelMessageHandler);
    testPinpointClient.connect(bindPort);
    try {
        testPinpointServerAcceptor.assertAwaitClientConnected(1000);
        List<PinpointSocket> writableServerList = testPinpointServerAcceptor.getConnectedPinpointSocketList();
        Assert.assertEquals(1, writableServerList.size());
        PinpointSocket writableServer = writableServerList.get(0);
        if (writableServer instanceof PinpointServer) {
            RecordedStreamChannelMessageListener clientListener = new RecordedStreamChannelMessageListener(4);
            ClientStreamChannel clientStreamChannel = ((PinpointServer) writableServer).openStreamAndAwait(new byte[0], clientListener, 3000);
            StreamChannel streamChannel = serverStreamChannelMessageHandler.bo.serverStreamChannelList.get(0);
            streamChannel.close();
            sendRandomBytes(bo);
            Thread.sleep(100);
            clientStreamChannel.close();
        } else {
            Assert.fail();
        }
    } finally {
        testPinpointClient.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) RecordedStreamChannelMessageListener(com.navercorp.pinpoint.rpc.RecordedStreamChannelMessageListener) PinpointServer(com.navercorp.pinpoint.rpc.server.PinpointServer) 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