    @Test
    public void testPeerAndConnections() throws Exception {


        InetAddress host = InetAddress.getByName(null);

        // create server
        final TChannel server = new TChannel.Builder("server")
            .setServerHost(host)
            .build();
        final SubChannel subServer = server.makeSubChannel("server")
            .register("echo", new EchoHandler());
        server.listen();

        int port = server.getListeningPort();

        // create client
        final TChannel client = new TChannel.Builder("client")
                .setServerHost(host)
                .build();
        final SubChannel subClient = client.makeSubChannel("server");
        client.listen();

        RawRequest req = new RawRequest.Builder("server", "echo")
            .setHeader("title")
            .setBody("hello")
            .setTimeout(2000)
            .build();

        TFuture<RawResponse> future = subClient.send(
            req,
            host,
            port
        );

        try (RawResponse res = future.get()) {
            assertEquals("title", res.getHeader());
            assertEquals("hello", res.getBody());
        }

        // checking the connections
        assertStats("client", client, 0, 1);
        assertStats("server", server, 1, 0);

        client.shutdown();
        server.shutdown();

        assertStats("client", client, 0, 0);
        assertStats("server", server, 0, 0);

    }