diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:15:42 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2015-12-17 09:44:51 +0100 |
commit | a1789ddde42033f1b05cc4929491214ee6e79383 (patch) | |
tree | 63615735c4ddffaaabf2428946bb26f90899f7bf /vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php | |
parent | 9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff) |
Update to MediaWiki 1.26.0
Diffstat (limited to 'vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php')
-rw-r--r-- | vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php b/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php new file mode 100644 index 00000000..0dedbc22 --- /dev/null +++ b/vendor/ruflin/elastica/test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php @@ -0,0 +1,128 @@ +<?php +namespace Elastica\Test\Connection\Strategy; + +use Elastica\Connection; +use Elastica\Connection\Strategy\RoundRobin; +use Elastica\Exception\ConnectionException; +use Elastica\Response; +use Elastica\Test\Base; + +/** + * Description of RoundRobinTest. + * + * @author chabior + */ +class RoundRobinTest extends Base +{ + /** + * @var int Number of seconds to wait before timeout is called. Is set low for tests to have fast tests. + */ + protected $_timeout = 1; + + /** + * @group functional + */ + public function testConnection() + { + $config = array('connectionStrategy' => 'RoundRobin'); + $client = $this->_getClient($config); + $response = $client->request('/_aliases'); + /* @var $response Response */ + + $this->_checkResponse($response); + + $this->_checkStrategy($client); + } + + /** + * @group unit + */ + public function testOldStrategySetted() + { + $config = array('roundRobin' => true); + $client = $this->_getClient($config); + + $this->_checkStrategy($client); + } + + /** + * @group functional + * @expectedException \Elastica\Exception\ConnectionException + */ + public function testFailConnection() + { + $config = array('connectionStrategy' => 'RoundRobin', 'host' => '255.255.255.0', 'timeout' => $this->_timeout); + $client = $this->_getClient($config); + + $this->_checkStrategy($client); + + $client->request('/_aliases'); + } + + /** + * @group functional + */ + public function testWithOneFailConnection() + { + $connections = array( + new Connection(array('host' => '255.255.255.0', 'timeout' => $this->_timeout)), + new Connection(array('host' => $this->_getHost(), 'timeout' => $this->_timeout)), + ); + + $count = 0; + $callback = function ($connection, $exception, $client) use (&$count) { + ++$count; + }; + + $client = $this->_getClient(array('connectionStrategy' => 'RoundRobin'), $callback); + $client->setConnections($connections); + + $response = $client->request('/_aliases'); + /* @var $response Response */ + + $this->_checkResponse($response); + + $this->_checkStrategy($client); + + $this->assertLessThan(count($connections), $count); + } + + /** + * @group functional + */ + public function testWithNoValidConnection() + { + $connections = array( + new Connection(array('host' => '255.255.255.0', 'timeout' => $this->_timeout)), + new Connection(array('host' => '45.45.45.45', 'port' => '80', 'timeout' => $this->_timeout)), + new Connection(array('host' => '10.123.213.123', 'timeout' => $this->_timeout)), + ); + + $count = 0; + $client = $this->_getClient(array('roundRobin' => true), function () use (&$count) { + ++$count; + }); + + $client->setConnections($connections); + + try { + $client->request('/_aliases'); + $this->fail('Should throw exception as no connection valid'); + } catch (ConnectionException $e) { + $this->assertEquals(count($connections), $count); + $this->_checkStrategy($client); + } + } + + protected function _checkStrategy($client) + { + $strategy = $client->getConnectionStrategy(); + + $this->assertInstanceOf('Elastica\Connection\Strategy\RoundRobin', $strategy); + } + + protected function _checkResponse($response) + { + $this->assertTrue($response->isOk()); + } +} |