-
Notifications
You must be signed in to change notification settings - Fork 733
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
chabior
committed
Aug 6, 2014
1 parent
ddcdbf4
commit 384e930
Showing
12 changed files
with
314 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
namespace Elastica\Test\Connection; | ||
|
||
use Elastica\Test\Base as BaseTest; | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
/** | ||
* Description of ConnectionPollTest | ||
* | ||
* @author chabior | ||
*/ | ||
class ConnectionPollTest extends BaseTest | ||
{ | ||
public function testConstruct() | ||
{ | ||
$pool = $this->createPool(); | ||
|
||
$this->assertEquals($this->getConnections(), $pool->getConnections()); | ||
} | ||
|
||
public function testSetConnections() | ||
{ | ||
$pool = $this->createPool(); | ||
|
||
$connections = $this->getConnections(5); | ||
|
||
$pool->setConnections($connections); | ||
|
||
$this->assertEquals($connections, $pool->getConnections()); | ||
} | ||
|
||
public function testHasConnection() | ||
{ | ||
$pool = $this->createPool(); | ||
|
||
$this->assertTrue($pool->hasConnection()); | ||
} | ||
|
||
public function testFailHasConnections() | ||
{ | ||
$pool = $this->createPool(); | ||
|
||
$pool->setConnections(array()); | ||
|
||
$this->assertFalse($pool->hasConnection()); | ||
} | ||
|
||
public function testGetConnection() | ||
{ | ||
$pool = $this->createPool(); | ||
|
||
$this->assertTrue($pool->getConnection() instanceof \Elastica\Connection); | ||
} | ||
|
||
protected function getConnections($quantity = 1) | ||
{ | ||
$params = array(); | ||
$connections = array(); | ||
|
||
for ($i = 0; $i<$quantity; $i++) { | ||
$connections[] = new \Elastica\Connection($params); | ||
} | ||
|
||
return $connections; | ||
} | ||
|
||
protected function createPool() | ||
{ | ||
$connections = $this->getConnections(); | ||
$strategy = \Elastica\Connection\Strategy\StrategyFactory::getSimpleStrategy(); | ||
|
||
$pool = new \Elastica\Connection\ConnectionPool($connections, $strategy); | ||
$pool->getConnections(); | ||
|
||
return $pool; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
test/lib/Elastica/Test/Connection/Strategy/CallbackStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace Elastica\Test\Connection\Strategy; | ||
|
||
use Elastica\Connection\Strategy\CallbackStrategy; | ||
use Elastica\Test\Base; | ||
|
||
/** | ||
* Description of CallbackStrategyTest | ||
* | ||
* @author chabior | ||
*/ | ||
class CallbackStrategyTest extends Base | ||
{ | ||
public function testInvoke() | ||
{ | ||
$count = 0; | ||
|
||
$callback = function ($connections) use(&$count) { | ||
$count++; | ||
}; | ||
|
||
$strategy = new CallbackStrategy($callback); | ||
$strategy->getConnection(array()); | ||
|
||
$this->assertEquals(1, $count); | ||
} | ||
|
||
public function testIsValid() | ||
{ | ||
$callback = function(){}; | ||
|
||
$isValid = CallbackStrategy::isValid($callback); | ||
|
||
$this->assertTrue($isValid); | ||
} | ||
|
||
public function testFailIsValid() | ||
{ | ||
$callback = new \stdClass(); | ||
|
||
$isValid = CallbackStrategy::isValid($callback); | ||
|
||
$this->assertFalse($isValid); | ||
} | ||
|
||
public function testConnection() | ||
{ | ||
$count = 0; | ||
|
||
$config = array('connectionStrategy' => function ($connections) use(&$count) { | ||
++$count; | ||
return current($connections); | ||
}); | ||
|
||
$client = new \Elastica\Client($config); | ||
$client->request('/_aliases'); | ||
|
||
$this->assertEquals(1, $count); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/lib/Elastica/Test/Connection/Strategy/EmptyStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Elastica\Test\Connection\Strategy; | ||
|
||
use Elastica\Connection\Strategy\StrategyInterface; | ||
|
||
/** | ||
* Description of EmptyStrategy | ||
* | ||
* @author chabior | ||
*/ | ||
class EmptyStrategy implements StrategyInterface | ||
{ | ||
public function getConnection($connections) | ||
{ | ||
return null; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
test/lib/Elastica/Test/Connection/Strategy/RoundRobinTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Elastica\Test\Connection\Strategy; | ||
|
||
use Elastica\Test\Base; | ||
|
||
/** | ||
* Description of RoundRobinTest | ||
* | ||
* @author chabior | ||
*/ | ||
class RoundRobinTest extends Base | ||
{ | ||
public function testConnection() | ||
{ | ||
$config = array('connectionStrategy' => 'RoundRobin'); | ||
$client = new \Elastica\Client($config); | ||
$client->request('/_aliases'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Elastica\Test\Connection\Strategy; | ||
|
||
use Elastica\Test\Base; | ||
|
||
/** | ||
* Description of SimplyTest | ||
* | ||
* @author chabior | ||
*/ | ||
class SimplyTest extends Base | ||
{ | ||
public function testConnection() | ||
{ | ||
$client = new \Elastica\Client(); | ||
$client->request('/_aliases'); | ||
} | ||
} |
Oops, something went wrong.