Автор: Nicolas Ruflin (spam@ruflin.com)
Наследование: extends Param
Пример #1
0
 /**
  * @group unit
  */
 public function testToString()
 {
     $path = 'test';
     $method = Request::POST;
     $query = array('no' => 'params');
     $data = array('key' => 'value');
     $connection = new Connection();
     $connection->setHost($this->_getHost());
     $connection->setPort('9200');
     $request = new Request($path, $method, $data, $query, $connection);
     $data = $request->toArray();
     $this->assertInternalType('array', $data);
     $this->assertArrayHasKey('method', $data);
     $this->assertArrayHasKey('path', $data);
     $this->assertArrayHasKey('query', $data);
     $this->assertArrayHasKey('data', $data);
     $this->assertArrayHasKey('connection', $data);
     $this->assertEquals($request->getMethod(), $data['method']);
     $this->assertEquals($request->getPath(), $data['path']);
     $this->assertEquals($request->getQuery(), $data['query']);
     $this->assertEquals($request->getData(), $data['data']);
     $this->assertInternalType('array', $data['connection']);
     $this->assertArrayHasKey('host', $data['connection']);
     $this->assertArrayHasKey('port', $data['connection']);
     $this->assertEquals($request->getConnection()->getHost(), $data['connection']['host']);
     $this->assertEquals($request->getConnection()->getPort(), $data['connection']['port']);
     $string = $request->toString();
     $this->assertInternalType('string', $string);
     $string = (string) $request;
     $this->assertInternalType('string', $string);
 }
Пример #2
0
 /**
  * @expectedException \Elastica\Exception\ResponseException
  */
 public function testInvalidElasticRequest()
 {
     $connection = new Connection();
     $connection->setHost('localhost');
     $connection->setPort(9500);
     $connection->setTransport('Thrift');
     $client = new Client();
     $client->addConnection($connection);
     $index = new Index($client, 'missing_index');
     $index->getStatus();
 }
Пример #3
0
 /**
  * @group functional
  * @expectedException \Elastica\Exception\ResponseException
  */
 public function testInvalidElasticRequest()
 {
     $this->_checkPlugin();
     $connection = new Connection();
     $connection->setHost($this->_getHost());
     $connection->setPort(9500);
     $connection->setTransport('Thrift');
     $client = $this->_getClient();
     $client->addConnection($connection);
     $index = new Index($client, 'missing_index');
     $index->getStatus();
 }
 public function testConvertRequestToCurlCommand()
 {
     $path = 'test';
     $method = Request::POST;
     $query = array('no' => 'params');
     $data = array('key' => 'value');
     $connection = new Connection();
     $connection->setHost('localhost');
     $connection->setPort('9200');
     $request = new Request($path, $method, $data, $query, $connection);
     $curlCommand = Util::convertRequestToCurlCommand($request);
     $expected = 'curl -XPOST \'http://localhost:9200/test?no=params\' -d \'{"key":"value"}\'';
     $this->assertEquals($expected, $curlCommand);
 }
Пример #5
0
 /**
  * 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);
 }
Пример #6
0
 /**
  * @return array
  */
 public function toArray()
 {
     $data = $this->getParams();
     if ($this->_connection) {
         $data['connection'] = $this->_connection->getParams();
     }
     return $data;
 }
Пример #7
0
 /**
  * Inits the client connections
  */
 protected function _initConnections()
 {
     $connections = $this->getConfig('connections');
     foreach ($connections as $connection) {
         $this->_connections[] = Connection::create($connection);
     }
     if (isset($_config['servers'])) {
         $this->_connections[] = Connection::create($this->getConfig('servers'));
     }
     // If no connections set, create default connection
     if (empty($this->_connections)) {
         $this->_connections[] = Connection::create($this->_configureParams());
     }
 }
Пример #8
0
 /**
  * @group unit
  */
 public function testCompression()
 {
     $connection = new Connection();
     $this->assertFalse($connection->hasCompression());
     $connection->setCompression(true);
     $this->assertTrue($connection->hasCompression());
 }
Пример #9
0
 /**
  * @param \Elastica\Connection $connection
  * @param \Exception $e
  * @param Client $client
  */
 public function onFail(Connection $connection, Exception $e, Client $client)
 {
     $connection->setEnabled(false);
     if ($this->_callback) {
         call_user_func($this->_callback, $connection, $e, $client);
     }
 }
Пример #10
0
 /**
  * @param ElasticaRequest      $request
  * @param \Elastica\Connection $connection
  *
  * @return string
  */
 protected function _getUri(ElasticaRequest $request, Connection $connection)
 {
     $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
     if (!empty($url)) {
         $baseUri = $url;
     } else {
         $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath();
     }
     $baseUri .= $request->getPath();
     $query = $request->getQuery();
     if (!empty($query)) {
         $baseUri .= '?' . http_build_query($query);
     }
     return $baseUri;
 }
Пример #11
0
 private function getConfig(Connection $conn, $key, $default = null)
 {
     return $conn->hasConfig($key) ? $conn->getConfig($key) : $default;
 }
Пример #12
0
 /**
  * Builds the base url for the guzzle connection.
  *
  * @param \Elastica\Connection $connection
  *
  * @return string
  */
 protected function _getBaseUrl(Connection $connection)
 {
     // If url is set, url is taken. Otherwise port, host and path
     $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
     if (!empty($url)) {
         $baseUri = $url;
     } else {
         $baseUri = (string) Uri::fromParts(['scheme' => $this->_scheme, 'host' => $connection->getHost(), 'port' => $connection->getPort(), 'path' => ltrim('/', $connection->getPath())]);
     }
     return rtrim($baseUri, '/');
 }
Пример #13
0
 /**
  * Builds the base url for the guzzle connection.
  *
  * @param \Elastica\Connection $connection
  */
 protected function _getBaseUrl(Connection $connection)
 {
     // If url is set, url is taken. Otherwise port, host and path
     $url = $connection->hasConfig('url') ? $connection->getConfig('url') : '';
     if (!empty($url)) {
         $baseUri = $url;
     } else {
         $baseUri = $this->_scheme . '://' . $connection->getHost() . ':' . $connection->getPort() . '/' . $connection->getPath();
     }
     return rtrim($baseUri, '/');
 }
Пример #14
0
 /**
  * @group unit
  * @expectedException \Elastica\Exception\InvalidException
  */
 public function testGetConfigInvalidValue()
 {
     $connection = new Connection();
     $connection->getConfig('url');
 }