@Test
    public void testRuntimeCloseAndEnableHeartbeat() throws InterruptedException {
        // Register heart beat processor
        server.getRpcServer().registerProcessor(RpcProtocol.PROTOCOL_CODE,
            CommonCommandCode.HEARTBEAT, heartBeatProcessor);

        // Establish connection
        try {
            client.getConnection(addr, 1000);
        } catch (RemotingException e) {
            logger.error("Failed to establish connection", e);
        }

        // Phase 1: Verify heartbeats are being sent
        await().atMost(3, TimeUnit.SECONDS)
               .pollInterval(100, TimeUnit.MILLISECONDS)
               .until(() -> heartBeatProcessor.getHeartBeatTimes() > 0);

        logger.warn("before disable: {}", heartBeatProcessor.getHeartBeatTimes());

        // Phase 2: Disable heartbeats
        client.disableConnHeartbeat(addr);

        // Wait a bit to make sure any in-flight heartbeats are processed
        Thread.sleep(200);

        // Reset counter
        heartBeatProcessor.reset();

        // Verify no new heartbeats arrive after disabling
        await().pollDelay(500, TimeUnit.MILLISECONDS)
               .during(1, TimeUnit.SECONDS)
               .atMost(2, TimeUnit.SECONDS)
               .pollInterval(100, TimeUnit.MILLISECONDS)
               .until(() -> heartBeatProcessor.getHeartBeatTimes() == 0);

        logger.warn("after disable: {}", heartBeatProcessor.getHeartBeatTimes());

        // Phase 3: Re-enable heartbeats
        client.enableConnHeartbeat(addr);
        heartBeatProcessor.reset();

        // Verify heartbeats resume
        await().atMost(3, TimeUnit.SECONDS)
               .pollInterval(100, TimeUnit.MILLISECONDS)
               .until(() -> heartBeatProcessor.getHeartBeatTimes() > 0);

        logger.warn("after enable: {}", heartBeatProcessor.getHeartBeatTimes());
    }
Runtime operation connection heart beat test

@author xiaomin.cxm
@version $Id: ClientHeartBeatTest.java, v 0.1 Apr 12, 2016 11:13:10 AM xiaomin.cxm Exp $
src/test/java/com/alipay/remoting/rpc/heartbeat/RuntimeClientHeartBeatTest.java