Ejemplo n.º 1
0
 public function test_should_mirror_table_router_set_and_get_works_fine()
 {
     try {
         Router::set('i am not exists');
         $this->assertTrue(false);
     } catch (\Exception $e) {
         $this->assertTrue($e instanceof \Myfox\Lib\Exception);
         $this->assertContains('Undefined table named as "i am not exists"', $e->getMessage());
     }
     $mirror = \Myfox\App\Model\Table::instance('mirror');
     foreach (array(0, 1, 2, 0) as $key => $id) {
         Setting::set('last_assign_host', 0);
         $this->assertEquals(array('' => array(array('rows' => 1300, 'hosts' => '3,4,1,2', 'table' => 'mirror_0.t_' . $mirror->get('autokid') . '_' . $id))), Router::set('mirror', array(array('count' => 1300))));
         if ($key == 0) {
             $this->assertEquals(array(), Router::get('mirror'));
         }
     }
     $this->assertEquals(1, Setting::get('last_assign_host'));
     $this->assertEquals(4, Setting::get('table_route_count', 'mirror'));
     $this->assertEquals(0, (int) Setting::get('table_real_count', 'mirror'));
     $where = Router::instance('mirror')->where(null);
     $route = self::$mysql->getRow(self::$mysql->query(sprintf("SELECT autokid,route_flag,real_table,hittime,hosts_list FROM %s WHERE table_name='mirror' AND route_flag=%d LIMIT 1", $where['table'], Router::FLAG_PRE_IMPORT)));
     $this->assertEquals(0, $route['hittime']);
     $this->assertEquals('$', $route['hosts_list']);
     $real_table = $route['real_table'];
     // XXX: 数据装完
     $this->assertEquals(1, Router::effect('mirror', null, $route['real_table'], '1,2'));
     $this->assertEquals(array('hosts_list' => '1,2,$', 'route_flag' => Router::FLAG_IMPORT_END), self::$mysql->getRow(self::$mysql->query(sprintf("SELECT hosts_list,route_flag FROM %s WHERE table_name='mirror' AND real_table='%s' AND autokid = %u", $where['table'], $route['real_table'], $route['autokid']))));
     $this->assertEquals(array(), Router::get('mirror'));
     // xxx: 模拟路由生效
     Router::flush();
     $route = Router::get('mirror', null, true);
     $this->assertEquals(1, count($route));
     $route = reset($route);
     $this->assertTrue(0 < $route['mtime']);
     $this->assertEquals('1,2', $route['hosts']);
     $this->assertEquals($real_table, $route['table']);
     Router::removeAllCache();
     $query = sprintf('SELECT hittime FROM %s WHERE %s AND route_flag=%d ORDER BY autokid DESC LIMIT 1', $where['table'], $where['where'], Router::FLAG_NORMAL_USE);
     $this->assertEquals(intval(time() / 2), intval(self::$mysql->getOne(self::$mysql->query($query)) / 2));
 }
Ejemplo n.º 2
0
 public function test_should_the_secret_hello_function_works_fine()
 {
     $hello = Router::instance('mirror_v2')->hello(null, $table);
     $this->assertContains('route_info', $table);
     $this->assertEquals(array('route_sign' => 1550635837, 'table_name' => 'mirror_v2', 'route_text' => ''), $hello);
 }
Ejemplo n.º 3
0
 public function test_should_import_mirror_to_ib_works_fine()
 {
     self::cleanTable('default', 'route_info');
     $route = \Myfox\App\Model\Router::set('mirror_v2', array());
     $route = reset($route);
     $route = reset($route);
     $task = new \Myfox\App\Task\Import(10, array('table' => 'mirror_v2', 'route' => '', 'file' => realpath(__DIR__ . '/resource/mirror_import_data_file.txt'), 'bucket' => $route['table'], 'hosts' => '4,5', 'engine' => 'BRIGHTHOUSE'), '999999,-98');
     $this->assertEquals(Task::WAIT, $task->execute());
     $this->assertEquals(Task::SUCC, $task->wait());
     $where = \Myfox\App\Model\Router::instance('mirror_v2')->where(null);
     $route = self::$mysql->getOne(self::$mysql->query(sprintf("SELECT hosts_list FROM %s WHERE table_name='mirror_v2' AND real_table='%s' AND route_flag = %d", $where['table'], $route['table'], \Myfox\App\Model\Router::FLAG_IMPORT_END)));
     $route = array_filter(explode(',', trim($route, '{}$')));
     sort($route);
     $this->assertEquals(array(4, 5), $route);
     $this->assertEquals(true, self::check_table_exists('ibtest_1', 'mirror_v2_0.t_1_0'));
     $this->assertEquals(true, self::check_table_exists('ibtest_1', 'mirror_v2_0.t_1_1'));
     $this->assertEquals(true, self::check_table_exists('ibtest_1', 'mirror_v2_0.t_1_2'));
     $this->assertEquals(true, self::check_table_exists('ibtest_2', 'mirror_v2_0.t_1_0'));
     $this->assertEquals(true, self::check_table_exists('ibtest_2', 'mirror_v2_0.t_1_1'));
     $this->assertEquals(true, self::check_table_exists('ibtest_2', 'mirror_v2_0.t_1_2'));
 }