Search in sources :

Example 31 with TestPinpointServerAcceptor

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

the class TcpDataSenderTest method connectAndSend.

@Test
public void connectAndSend() {
    TestServerMessageListenerFactory testServerMessageListenerFactory = new TestServerMessageListenerFactory(TestServerMessageListenerFactory.HandshakeType.DUPLEX, true);
    TestServerMessageListenerFactory.TestServerMessageListener serverMessageListener = testServerMessageListenerFactory.create();
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    PinpointClientFactory clientFactory = createPinpointClientFactory();
    TcpDataSender<Object> sender = new TcpDataSender<>(this.getClass().getName(), TestPinpointServerAcceptor.LOCALHOST, bindPort, clientFactory);
    try {
        sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
        sender.send(new TApiMetaData("test", System.currentTimeMillis(), 1, "TestApi"));
        serverMessageListener.awaitAssertExpectedSendCount(2, 1000);
    } finally {
        sender.stop();
        if (clientFactory != null) {
            clientFactory.release();
        }
        testPinpointServerAcceptor.close();
    }
}
Also used : TApiMetaData(com.navercorp.pinpoint.thrift.dto.TApiMetaData) TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) DefaultPinpointClientFactory(com.navercorp.pinpoint.rpc.client.DefaultPinpointClientFactory) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) TestServerMessageListenerFactory(com.navercorp.pinpoint.test.server.TestServerMessageListenerFactory) Test(org.junit.Test)

Example 32 with TestPinpointServerAcceptor

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

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

the class HandshakeTest method handshakeTest1.

// simple test
@Test
public void handshakeTest1() throws InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    TestPinpointClient testPinpointClient1 = new TestPinpointClient(testServerMessageListenerFactory.create(), PinpointRPCTestUtils.getParams());
    TestPinpointClient testPinpointClient2 = new TestPinpointClient(PinpointRPCTestUtils.getParams());
    try {
        testPinpointClient1.connect(bindPort);
        testPinpointClient2.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(2, 3000);
    } finally {
        testPinpointClient1.closeAll();
        testPinpointClient2.closeAll();
        testPinpointServerAcceptor.close();
    }
}
Also used : TestPinpointServerAcceptor(com.navercorp.pinpoint.test.server.TestPinpointServerAcceptor) TestPinpointClient(com.navercorp.pinpoint.test.client.TestPinpointClient) Test(org.junit.Test)

Example 34 with TestPinpointServerAcceptor

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

the class HandshakeTest method handshakeTest2.

@Test
public void handshakeTest2() throws InterruptedException {
    TestPinpointServerAcceptor testPinpointServerAcceptor = new TestPinpointServerAcceptor(testServerMessageListenerFactory);
    int bindPort = testPinpointServerAcceptor.bind();
    Map<String, Object> params = PinpointRPCTestUtils.getParams();
    TestPinpointClient testPinpointClient = new TestPinpointClient(testServerMessageListenerFactory.create(), params);
    try {
        testPinpointClient.connect(bindPort);
        testPinpointServerAcceptor.assertAwaitClientConnected(1, 3000);
        PinpointSocket writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()), testPinpointServerAcceptor.getConnectedPinpointSocketList());
        Assert.assertNotNull(writableServer);
        writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()) + 1, testPinpointServerAcceptor.getConnectedPinpointSocketList());
        Assert.assertNull(writableServer);
    } 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 35 with TestPinpointServerAcceptor

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

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