/**
  * 测试receive和_receive接口
  */
 public function testReceive()
 {
     $subject = new BigpipeQueueClient();
     // 测试1 uninit下调用接口
     $this->assertFalse($subject->receive());
     $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true));
     // 定义meta行为
     $this->stub_meta->expects($this->once())->method('queue_name')->will($this->returnValue('queue_client'));
     $this->assertTrue(TestUtilities::set_private_var($subject, '_meta', $this->stub_meta));
     // 测试2 未订阅时调用receive
     $this->assertFalse($subject->receive());
     $this->assertTrue(TestUtilities::set_private_var($subject, '_subscribed', true));
     // 测试3 测试_receive函数
     // 定义connection行为
     $idl_arr = $this->_gen_idl_pack();
     $this->stub_conn->expects($this->any())->method('receive')->will($this->onConsecutiveCalls(null, ' ', $idl_arr['req'], $idl_arr['res_err'], $idl_arr['res']));
     $this->stub_conn->expects($this->any())->method('close')->will($this->returnValue(true));
     $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn));
     // 测试3.1 none响应
     $this->assertFalse($subject->receive());
     // 测试3.2 mc_pack error
     $this->assertFalse($subject->receive());
     // 测试3.3 wrong package
     $this->assertFalse($subject->receive());
     // 测试3.4 print error message in package
     $this->assertFalse($subject->receive());
     // 测试4 成功接收
     $msg = $subject->receive();
     $this->assertTrue(false != $msg);
     $expected = new BigpipeQueueMessage();
     $expected->pipe_name = 'pipe';
     $expected->pipelet_id = 2;
     $expected->pipelet_msg_id = 65535;
     $expected->seq_id = 9527;
     $expected->message_body = 'Testing Queue Client';
     $this->assertEquals($expected, $msg);
 }
// 每次peek最多等待100ms
$file = fopen('./queue-client.txt', 'w+');
$cli = new BigpipeQueueClient();
// 测试中,我们希望能取完所有窗口的数据
$max_count = 50000;
if ($cli->init($queue_name, $token, $conf)) {
    echo "[Success][init queue server client]\n";
    $count = 0;
    $success = 0;
    $failure = 0;
    $peek = 0;
    $ack = 0;
    while ($count < $max_count) {
        $pret = $cli->peek($peek_time_ms);
        if (BigpipeErrorCode::READABLE == $pret) {
            $msg = $cli->receive();
            if (false === $msg) {
                echo sprintf("[Failure][receive msg][cnt:%u]\n", $count);
                $failure++;
            } else {
                // 回复ack
                //if (false === $cli->ack($msg,true))  慢速客户端请调用此接口!!!同时设置滑动窗口为1
                if (false === $cli->ack($msg)) {
                    // ack失败常由于msg处理超时引起,这时queuesvr中waiting队列中对应msg会被归还send队列。
                    // 用户不应该继续使用这条message。
                    // 这时多次重试ack也没有必要,因为一旦超时,socket就会被queuesvr主动关闭。
                    echo sprintf("[Failure][ack][cnt:%u]\n", $count);
                    $msg = false;
                } else {
                    // 我们以成功发送ack作为数据订阅成功的标志
                    // 如果ack发送失败, queue server会将数据重新放回发布队列,