echo '\\n'; } else { echo '[Failure] [open meta agent log]\\n'; print_r($log_conf); echo '\\n'; } // 准备configuration $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"; } // 取得可发布broker $pipe_name = 'pipe1'; $pipelet_id = 2; // 加1在哪里做好呢? $broker = $adapter->get_pub_broker($pipe_name, $pipelet_id); if (!$broker) { echo "[Failure][get pub info]\n";
echo '\\n'; } else { echo '[Failure] [open meta agent log]\\n'; print_r($log_conf); 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;
public function testAuthorize() { $subject = new MetaAgentAdapter(); $pipe_name = 'pipe'; $token = 'token'; $role = BStompRoleType::PUBLISHER; // 测试1 从还未被初始化的对象调用接口 $this->assertFalse($subject->authorize($pipe_name, $token, $role)); // 测试2 meta name为空 $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', true)); $this->assertFalse($subject->authorize(null, $token, $role)); // 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_authorize_ack(); $this->stub_conn->expects($this->any())->method('receive')->will($this->onConsecutiveCalls(null, $ack_pkgs['bad'], $ack_pkgs['failed'], $ack_pkgs['passed'])); $this->assertTrue(TestUtilities::set_private_var($subject, '_connection', $this->stub_conn)); // 测试2.2 request null $subject->meta_name = 'meta'; $this->assertFalse($subject->authorize($pipe_name, $token, $role)); // 测试2.3 ack wrong pakcage $this->assertFalse($subject->authorize($pipe_name, $token, $role)); // 测试2.4 认证不通过 $auth_ret = $subject->authorize($pipe_name, $token, $role); $this->assertTrue(false != $auth_ret); $this->assertFalse($auth_ret['authorized']); // 测试2.5 认证通过 $auth_ret = $subject->authorize($pipe_name, $token, $role); $this->assertTrue(false != $auth_ret); $this->assertTrue($auth_ret['authorized']); $this->assertTrue(TestUtilities::set_private_var($subject, '_inited', false)); }