/** * 测试connect接口 * 测试init_meta过程 */ public function testConnect() { $subject = new MetaAgentAdapter(); // 测试1 connect还未被初始化的对象 $this->assertFalse($subject->connect()); // 测试2 init meta $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true)); // 测试2.1 package init meta 包失败 $this->assertTrue(TestUtilities::set_private_var($subject, '_conf', $this->conf)); $this->assertFalse($subject->connect()); // 补全conf $this->conf->meta['meta_host'] = '0.0.0.0:0'; $this->conf->meta['root_path'] = '/root'; $this->assertTrue(TestUtilities::set_private_var($subject, '_conf', $this->conf)); // mock connection 行为 // 定义connection行为 $this->stub_conn->expects($this->any())->method('is_connected')->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->returnValue(true)); $this->stub_conn->expects($this->any())->method('close'); $ack_pkgs = $this->_gen_init_meta_ack(); $this->stub_conn->expects($this->any())->method('receive')->will($this->onConsecutiveCalls(null, $ack_pkgs['bad'], $ack_pkgs['good'])); $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn)); // 测试2.2 request null $this->assertFalse($subject->connect()); // 测试2.3 ack wrong pakcage $this->assertFalse($subject->connect()); // 测试2.4 成功 $this->assertTrue($subject->connect()); $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', false)); }
echo '\\n'; } // 准备meta agent $meta_conf = new BigpipeMetaConf(); $meta_conf->meta_host = '10.218.32.11:2181,10.218.32.20:2181,10.218.32.21:2181,10.218.32.22:2181,10.218.32.23:2181'; $meta_conf->root_path = '/bigpipe_pvt_cluster3'; $agent_conf = new MetaAgentConf(); $agent_conf->meta = $meta_conf->to_array(); $agent_conf->agents = array(array("socket_address" => "10.46.46.54", "socket_port" => 8021, "socket_timeout" => 300)); $agent_conf->conn_conf->try_time = 1; // 调试方便 $adapter = new MetaAgentAdapter(); if (false === $adapter->init($agent_conf)) { die; } if ($adapter->connect()) { echo "[Success] [connect to meta] [{$adapter->meta_name}]\n"; } else { echo "[Failure] [{$adapter->last_error_message}]\n"; } // 准备bigpipe stomp $stomp_conf = new BigpipeStompConf(); $stomp_conf->conn_conf->try_time = 1; $stomp = new BigpipeStompAdapter($stomp_conf); // 发布/订阅参数 $pipe_name = 'pipe1'; $pipelet_id = 2; // 加1在哪里做好呢? $start_point = -1; // 取得可发布broker $broker = $adapter->get_pub_broker($pipe_name, $pipelet_id);