protected function setUp()
 {
     parent::setUp();
     $this->inifile = __DIR__ . '/ini/myfox.ini';
     $config = new Config($this->inifile);
     $logurl = parse_url($config->get('log/default', ''));
     $this->prefix = rtrim($config->get('url.prefix', ''), '/');
     $this->logfile = $logurl['path'];
     @unlink($this->logfile);
     ob_start();
 }
Ejemplo n.º 2
0
 protected function setUp()
 {
     parent::setUp();
     $config = new Config(__DIR__ . '/ini/mysql_test.ini');
     $logurl = parse_url($config->get('logurl', ''));
     $this->logfile = $logurl['path'];
     Mysql::removeAllNames();
     self::$mysql = new Mysql(__DIR__ . '/ini/mysql.ini');
     self::$mysql->query('DROP TABLE IF EXISTS only_for_test');
     self::$mysql->query('CREATE TABLE `only_for_test` (
         `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
         `content` varchar(32) DEFAULT NULL,
         PRIMARY KEY (`id`)
     ) ENGINE=InnoDB DEFAULT CHARSET=utf8');
     @unlink($this->logfile);
 }
Ejemplo n.º 3
0
 /**
  * 各个对象初始化 
  *
  * @access public static
  * @return void
  */
 public static function init($ini)
 {
     self::setAutoLoad();
     /**
      * @配置文件
      */
     \Myfox\Lib\Config::register('default', $ini);
     $config = \Myfox\Lib\Config::instance('default');
     /**
      * @数据库
      */
     foreach ((array) $config->get('mysql') as $name => $file) {
         \Myfox\Lib\Mysql::register($name, $file);
     }
     /**
      * @日志对象
      */
     foreach ((array) $config->get('log') as $name => $url) {
         \Myfox\Lib\Factory::registerLog($name, $url);
     }
     /**
      * @告警提醒
      */
     \Myfox\Lib\Alert::init(__DIR__ . '/../etc/alert.ini');
 }
Ejemplo n.º 4
0
 protected function setUp()
 {
     parent::setUp();
     \Myfox\Lib\Mysql::register('default', __DIR__ . '/ini/mysql.ini');
     self::$mysql = \Myfox\Lib\Mysql::instance('default');
     self::cleanTable('default', 'task_queque');
     \Myfox\Lib\Config::register('default', __DIR__ . '/ini/myfox.ini');
 }
Ejemplo n.º 5
0
 public function test_should_config_with_ini_works_fine()
 {
     $config = new Config(__DIR__ . '/ini/config_test.ini', 'unittest');
     $this->assertEquals('abc', $config->get('key1'));
     $this->assertEquals(array('a' => 1.23456789, 'b' => 9.876543209999999), $config->get('key2'));
     $this->assertEquals('null', $config->get('key3', 'null'));
     $config = Config::instance('unittest');
     $this->assertEquals('', $config->get('key2/a'));
     $this->assertEquals(9.876543209999999, $config->get('key2/b'));
 }
    /**
     * 测试表及信息创建
     */
    protected function setUp()
    {
        parent::setUp();
        \Myfox\Lib\Mysql::removeAllNames();
        \Myfox\Lib\Mysql::register('default', __DIR__ . '/ini/mysql.ini');
        $this->mysql = \Myfox\Lib\Mysql::instance('default');
        $config = new \Myfox\Lib\Config(__DIR__ . '/ini/mysql.ini');
        foreach ($config->get('master') as $host) {
            $urlRes = parse_url($host);
            $this->infos['host'] = $urlRes['host'];
            $this->infos['port'] = array_key_exists('port', $urlRes) ? $urlRes['port'] : 3306;
            $this->infos['user'] = array_key_exists('user', $urlRes) ? $urlRes['user'] : '******';
            $this->infos['pass'] = array_key_exists('pass', $urlRes) ? $urlRes['pass'] : '';
        }
        self::cleanTable('default', 'route_info');
        $this->table_bak('table_list');
        $this->table_bak('host_list');
        $this->table_bak('settings');
        //插入测试分片表1
        $this->mysql->query('CREATE TABLE `test_table_real1` (
			`id` int(10) unsigned NOT NULL auto_increment,
			`key1` varchar(64) NOT NULL default "",
			`key2` int(10) NOT NULL default 0,
			PRIMARY KEY (`id`)
		)');
        //插入测试分片表2
        $this->mysql->query('CREATE TABLE `test_table_real2` (
			`id` int(10) unsigned NOT NULL auto_increment,
			`key1` varchar(64) NOT NULL default "",
			`key2` int(10) NOT NULL default 0,
			PRIMARY KEY (`id`)
		)');
        //插入测试分片表3
        $this->mysql->query('CREATE TABLE `test_table_real3` (
			`id` int(10) unsigned NOT NULL auto_increment,
			`key1` varchar(64) NOT NULL default "",
			`key2` int(10) NOT NULL default 0,
			PRIMARY KEY (`id`)
		)');
    }
Ejemplo n.º 7
0
 /**
  * 构造函数
  *
  * @access public
  * @param String $ini
  * @return void
  */
 private function __construct($ini)
 {
     require_once __DIR__ . '/application.php';
     Application::init($ini);
     $this->config = \Myfox\Lib\Config::instance('default');
     $this->prefix = rtrim($this->config->get('url.prefix', ''), '/');
     $logurl = $this->config->get('log/default');
     if (empty($logurl)) {
         $this->log = new \Myfox\Lib\BlackHole();
     } else {
         $this->log = new \Myfox\Lib\Log($logurl);
     }
 }
Ejemplo n.º 8
0
 public function execute()
 {
     /**
      * OPTIONS:
      * ----------------------------------------------------------------------
      * @file    : complete file url, such as "ftp://*****:*****@hostname/path"
      * @table   : name of the logic table
      * @route   : route value of the file, ex: thedate=20111001,cid=210
      * @bucket  :
      * @hosts   :
      * ---------------------------------------------------------------------
      */
     $this->pools = array();
     if (!$this->isReady('table', 'route', 'file', 'bucket', 'hosts')) {
         return self::IGNO;
     }
     $table = Table::instance($this->option('table'));
     if (!$table->get('autokid')) {
         $this->setError(sprintf('Undefined table named as "%s".', $this->option('table')));
         return self::IGNO;
     }
     $fname = null;
     $this->route = Router::parse($this->option('route'));
     $this->result = array_flip(explode(',', $this->status));
     foreach (array_unique(explode(',', trim($this->option('hosts'), '{}$'))) as $host) {
         if (isset($this->result[$host])) {
             continue;
         }
         empty($fname) && ($fname = Fileset::getfile($this->option['file']));
         if (empty($fname)) {
             $this->setError(Fileset::lastError());
             return self::FAIL;
         }
         $config = \Myfox\Lib\Config::instance('default');
         $ibservers = array_unique(explode(',', trim($config->get('ib/servers'))));
         $ibtables = array_unique(explode(',', trim($config->get('ib/tables'))));
         if (in_array($host, $ibservers) && in_array($this->option('table'), $ibtables)) {
             $this->onehost($host, $fname, 'BRIGHTHOUSE');
         } else {
             $this->onehost($host, $fname, 'MYISAM');
         }
     }
     return empty($this->pools) ? self::FAIL : self::WAIT;
 }
Ejemplo n.º 9
0
 /**
  * OPTIONS:
  * ----------------------------------------------------------------------
  * @file    : complete file url, such as "ftp://*****:*****@hostname/path"
  * @table   : name of the logic table
  * @route   : route value of the file, ex: thedate=20111001,cid=210
  * @lines   :
  * ---------------------------------------------------------------------
  */
 public function execute()
 {
     if (!$this->isReady('table', 'route', 'lines', 'file', 'priority')) {
         return self::IGNO;
     }
     $table = Table::instance($this->option('table'));
     if (!$table->get('autokid')) {
         $this->setError(sprintf('Undefined table named as "%s".', $this->option('table')));
         return self::IGNO;
     }
     try {
         $routes = Router::set($this->option('table'), array(array('field' => Router::parse($this->option('route'), $this->option('table')), 'count' => (int) $this->option('lines'))));
         if (!is_array($routes)) {
             $this->setError('route failed.');
             return self::FAIL;
         }
         $config = Config::instance('default');
         $fname = Fileset::getfile($this->option('file'), $config->get('path/download'));
         if (empty($fname)) {
             $this->setError(sprintf('getfile:%s', Fileset::lastError()));
             return self::FAIL;
         }
         $splits = array();
         foreach ($routes as $key => $bucket) {
             foreach ($bucket as $item) {
                 $splits[] = $item['rows'];
             }
         }
         $fsplit = new Fsplit($fname, "\n", 16777216);
         $chunks = $fsplit->split($splits, $config->get('path/filesplit'));
         if (empty($chunks)) {
             $this->setError(sprintf('fsplit failed,%s', $fsplit->lastError()));
             return self::FAIL;
         }
         if (preg_match('/^\\w+:/i', $this->option('file'))) {
             @unlink($fname);
         }
         $result = array();
         $queque = Queque::instance();
         foreach ($routes as $key => $bucket) {
             foreach ($bucket as $item) {
                 $fname = array_shift($chunks);
                 if (empty($fname)) {
                     break 2;
                 }
                 $info = array('table' => $this->option('table'), 'route' => $key, 'file' => $fname, 'bucket' => $item['table'], 'hosts' => $item['hosts']);
                 $option = array('openrace' => 0, 'priority' => (int) $this->option('priority'), 'trytimes' => 3, 'task_flag' => Queque::FLAG_WAIT, 'adduser' => 'rsplit');
                 if (!$queque->insert('import', $info, -1, $option)) {
                     $this->setError(sprintf('queque: %s', $queque->lastError()));
                     return self::FAIL;
                 }
                 $result[] = $queque->lastId();
             }
         }
         $this->result = implode(',', $result);
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return self::FAIL;
     }
     return self::SUCC;
 }
Ejemplo n.º 10
0
 /**
  * 构造函数
  *
  * @access public
  * @return void
  */
 public function __construct($config = null, $name = null)
 {
     if (is_scalar($config) && !empty($config)) {
         try {
             $config = \Myfox\Lib\Config::instance($config);
         } catch (\Exception $e) {
             $config = new \Myfox\Lib\Config($config);
         }
         $config = $config->get('');
     }
     $config = (array) $config;
     foreach ($config as $key => $val) {
         if (isset($this->option[$key])) {
             $this->option[$key] = $val;
         }
     }
     $prefix = empty($name) ? md5(json_encode($config)) : strtolower(trim($name));
     $this->master = new LiveBox('#MYSQL#' . $prefix . '/master', 10);
     if (!empty($config['master'])) {
         $this->init('addMaster', $config['master']);
     }
     $this->slave = new LiveBox('#MYSQL#' . $prefix . '/slave', 300);
     if (!empty($config['slave'])) {
         $this->init('addSlave', $config['slave']);
     }
     if (empty($this->option['logurl'])) {
         $this->log = new \Myfox\Lib\BlackHole();
     } else {
         $this->log = new \Myfox\Lib\Log($this->option['logurl']);
     }
     $name = self::normalize($name);
     if (!empty($name) && !isset(self::$objects[$name])) {
         self::$objects[$name] =& $this;
     }
 }