Search in sources :

Example 6 with TestAwaitTaskUtils

use of com.navercorp.pinpoint.rpc.TestAwaitTaskUtils in project pinpoint by naver.

the class ClientMessageListenerTest method assertAvaiableWritableSocket.

private void assertAvaiableWritableSocket(final PinpointServerAcceptor serverAcceptor, final int expectedWritableSocketSize) {
    boolean pass = awaitUtils.await(new TestAwaitTaskUtils() {

        @Override
        public boolean checkCompleted() {
            return serverAcceptor.getWritableSocketList().size() == expectedWritableSocketSize;
        }
    });
    Assert.assertTrue(pass);
}
Also used : TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)

Example 7 with TestAwaitTaskUtils

use of com.navercorp.pinpoint.rpc.TestAwaitTaskUtils in project pinpoint by naver.

the class HandshakeTest method handshakeTest2.

@Test
public void handshakeTest2() throws InterruptedException {
    final PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_INSTANCE);
    Map<String, Object> params = PinpointRPCTestUtils.getParams();
    PinpointClientFactory clientFactory1 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
    try {
        PinpointClient client = clientFactory1.connect("127.0.0.1", bindPort);
        awaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
                return writableServerList.size() == 1;
            }
        });
        PinpointSocket writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()), serverAcceptor.getWritableSocketList());
        Assert.assertNotNull(writableServer);
        writableServer = getWritableServer("application", "agent", (Long) params.get(HandshakePropertyType.START_TIMESTAMP.getName()) + 1, serverAcceptor.getWritableSocketList());
        Assert.assertNull(writableServer);
        PinpointRPCTestUtils.close(client);
    } finally {
        clientFactory1.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 8 with TestAwaitTaskUtils

use of com.navercorp.pinpoint.rpc.TestAwaitTaskUtils in project pinpoint by naver.

the class HandshakeTest method handshakeTest1.

// simple test
@Test
public void handshakeTest1() throws InterruptedException {
    final PinpointServerAcceptor serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, SimpleServerMessageListener.DUPLEX_INSTANCE);
    PinpointClientFactory clientFactory1 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), PinpointRPCTestUtils.createEchoClientListener());
    PinpointClientFactory clientFactory2 = PinpointRPCTestUtils.createClientFactory(PinpointRPCTestUtils.getParams(), null);
    try {
        PinpointClient client = clientFactory1.connect("127.0.0.1", bindPort);
        PinpointClient client2 = clientFactory2.connect("127.0.0.1", bindPort);
        awaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
                return writableServerList.size() == 2;
            }
        });
        List<PinpointSocket> writableServerList = serverAcceptor.getWritableSocketList();
        if (writableServerList.size() != 2) {
            Assert.fail();
        }
        PinpointRPCTestUtils.close(client, client2);
    } finally {
        clientFactory1.release();
        clientFactory2.release();
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointClient(com.navercorp.pinpoint.rpc.client.PinpointClient) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with TestAwaitTaskUtils

use of com.navercorp.pinpoint.rpc.TestAwaitTaskUtils in project pinpoint by naver.

the class PinpointServerStateTest method unexpectedCloseByPeerTest.

@Test
public void unexpectedCloseByPeerTest() throws InterruptedException, IOException, ProtocolException {
    PinpointServerAcceptor serverAcceptor = null;
    try {
        serverAcceptor = PinpointRPCTestUtils.createPinpointServerFactory(bindPort, PinpointRPCTestUtils.createEchoServerListener());
        Socket socket = new Socket("127.0.0.1", bindPort);
        socket.getOutputStream().write(createHandshakePayload(PinpointRPCTestUtils.getParams()));
        socket.getOutputStream().flush();
        final PinpointServerAcceptor ImmutableServerAcceptor = serverAcceptor;
        awaitUtils.await(new TestAwaitTaskUtils() {

            @Override
            public boolean checkCompleted() {
                return ImmutableServerAcceptor.getWritableSocketList().size() == 1;
            }
        });
        List<PinpointSocket> pinpointServerList = serverAcceptor.getWritableSocketList();
        PinpointSocket pinpointServer = pinpointServerList.get(0);
        if (!(pinpointServer instanceof PinpointServer)) {
            socket.close();
            Assert.fail();
        }
        Assert.assertEquals(SocketStateCode.RUN_DUPLEX, ((PinpointServer) pinpointServer).getCurrentStateCode());
        socket.close();
        assertPinpointServerState(SocketStateCode.UNEXPECTED_CLOSE_BY_CLIENT, (PinpointServer) pinpointServer);
    } finally {
        PinpointRPCTestUtils.close(serverAcceptor);
    }
}
Also used : PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils) Socket(java.net.Socket) PinpointSocket(com.navercorp.pinpoint.rpc.PinpointSocket) Test(org.junit.Test)

Example 10 with TestAwaitTaskUtils

use of com.navercorp.pinpoint.rpc.TestAwaitTaskUtils in project pinpoint by naver.

the class PinpointServerStateTest method assertPinpointServerState.

private void assertPinpointServerState(final SocketStateCode stateCode, final PinpointServer pinpointServer) {
    boolean passed = awaitUtils.await(new TestAwaitTaskUtils() {

        @Override
        public boolean checkCompleted() {
            return pinpointServer.getCurrentStateCode() == stateCode;
        }
    });
    Assert.assertTrue(passed);
}
Also used : TestAwaitTaskUtils(com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)

Aggregations

TestAwaitTaskUtils (com.navercorp.pinpoint.rpc.TestAwaitTaskUtils)10 Test (org.junit.Test)4 PinpointSocket (com.navercorp.pinpoint.rpc.PinpointSocket)3 PinpointClient (com.navercorp.pinpoint.rpc.client.PinpointClient)2 PinpointClientFactory (com.navercorp.pinpoint.rpc.client.PinpointClientFactory)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 DefaultFuture (com.navercorp.pinpoint.rpc.DefaultFuture)1 Future (com.navercorp.pinpoint.rpc.Future)1 RequestPacket (com.navercorp.pinpoint.rpc.packet.RequestPacket)1 Socket (java.net.Socket)1 HashedWheelTimer (org.jboss.netty.util.HashedWheelTimer)1