/** * Inits the client connections */ protected function _initConnections() { $connections = array(); foreach ($this->getConfig('connections') as $connection) { $connections[] = Connection::create($this->_prepareConnectionParams($connection)); } if (isset($this->_config['servers'])) { foreach ($this->getConfig('servers') as $server) { $connections[] = Connection::create($this->_prepareConnectionParams($server)); } } // If no connections set, create default connection if (empty($connections)) { $connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig())); } if (!isset($this->_config['connectionStrategy'])) { if ($this->getConfig('roundRobin') === true) { $this->setConfigValue('connectionStrategy', 'RoundRobin'); } else { $this->setConfigValue('connectionStrategy', 'Simple'); } } $strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy')); $this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback); }
protected function createPool() { $connections = $this->getConnections(); $strategy = StrategyFactory::create('Simple'); $pool = new ConnectionPool($connections, $strategy); return $pool; }
/** * @group unit */ public function testNoCollisionWithGlobalNamespace() { // create collision if (!class_exists('Simple')) { class_alias('Elastica\\Util', 'Simple'); } $strategy = StrategyFactory::create('Simple'); $this->assertInstanceOf('Elastica\\Connection\\Strategy\\Simple', $strategy); }
/** * @expectedException \InvalidArgumentException */ public function testFailCreate() { $strategy = new \stdClass(); StrategyFactory::create($strategy); }