/** * 测试refresh接口及_subscribe过程 */ public function testRefresh() { $subject = new BigpipeQueueClient(); // 测试1 uninit下调用接口 $this->assertFalse($subject->refresh()); $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true)); // 使程序进入call _disconnect分支 $this->assertTrue(TestUtilities::set_private_var($subject, '_subscribed', true)); // 定义connection的行为 $this->stub_conn->expects($this->any())->method('close')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('set_destinations')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('create_connection')->will($this->returnValue(true)); $this->stub_conn->expects($this->any())->method('send')->will($this->onConsecutiveCalls(false, true)); $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn)); // 定义meta的行为 $this->stub_meta->expects($this->any())->method('update')->will($this->onConsecutiveCalls(false, true, true)); $address = array('socket_address' => '127.0.0.1', 'socket_port' => 803); $this->assertTrue(TestUtilities::set_private_var($subject, '_rw_timeo', 5000)); $this->stub_meta->expects($this->any())->method('queue_address')->will($this->onConsecutiveCalls(false, $address, $address)); $this->stub_meta->expects($this->any())->method('queue_name')->will($this->returnValue($this->que_name)); $this->stub_meta->expects($this->any())->method('token')->will($this->returnValue($this->token)); $this->assertTrue(TestUtilities::set_private_var($subject, '_meta', $this->stub_meta)); // 测试2: // 1 进入_disconnect分支 // 2 _connect失败 $this->assertFalse($subject->refresh()); // 测试3: 测试_connect // 测试3.1: 取queue_address失败 $this->assertFalse($subject->refresh()); // 测试3.2: _connect成功, 订阅失败 $this->assertFalse($subject->refresh()); // 测试3.2: _connect成功,订阅成功 $this->assertTrue($subject->refresh()); }
echo sprintf("[Failure][ack][cnt:%u]\n", $count); $msg = false; } else { // 我们以成功发送ack作为数据订阅成功的标志 // 如果ack发送失败, queue server会将数据重新放回发布队列, // 因此我们必须在ack成功后才将数据落地. // 否则会导致数据被重复订阅. $success++; $msg_str = sprintf("[Success][begin msg]\n[pipe:%s]\n[pipelet:%u]\n[id:%u]\n[seq:%u]\n[msg][%s]\n[Success][end msg]===\n", $msg->pipe_name, $msg->pipelet_id, $msg->pipelet_msg_id, $msg->seq_id, $msg->message_body); fwrite($file, $msg_str); $ack++; } } if (false == $msg) { // 订阅过程中出现错无,刷新订阅连接 if (false === $cli->refresh()) { echo sprintf("[Failure][refresh][cnt:%u]\n", $count); break; } } } else { if (BigpipeErrorCode::UNREADABLE == $pret) { $peek++; } else { echo sprintf("[Failure][peek][cnt:%u][ret:%u]\n", $count, $pret); $failure++; if (false == $cli->refresh()) { echo sprintf("[Failure][refresh][cnt:%u]\n", $count); break; } }