public function testAck() { $subject = new BigpipeQueueClient(); // 测试1 uninit下调用接口 $this->assertFalse($subject->ack(null)); $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true)); // 测试2 参数检查失败 $ack_msg = new BigpipeQueueMessage(); $this->assertFalse($subject->ack($ack_msg)); $ack_msg->pipe_name = 'pipe'; // 定义connection的行为 $this->stub_conn->expects($this->once())->method('send')->will($this->returnValue(true)); $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn)); // 定义meta的行为 // todo 无法控制只抛出一次异常,异常接收分支会被跳过 $e = new ErrorException('php unit test'); $this->stub_meta->expects($this->any())->method('queue_name')->will($this->returnValue($this->que_name)); $this->assertTrue(TestUtilities::set_private_var($subject, '_meta', $this->stub_meta)); $this->assertTrue($subject->ack($ack_msg)); }
if (BigpipeLog::init($log_conf)) { echo "[Success] [open queue client log]\n"; print_r($log_conf); echo "\n"; } else { echo "[Failure] [open queue client log]\n"; print_r($log_conf); echo "\n"; } // 订阅参数 $queue_name = 'loop_queue_10_0_1'; $token = 'token'; $peek_time_ms = 100; // 每次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);