blob: ee03587a1dd81bea049b9b55726307b0f9d89283 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
<?php
namespace Elastica\Test\Connection;
use Elastica\Connection;
use Elastica\Connection\ConnectionPool;
use Elastica\Connection\Strategy\StrategyFactory;
use Elastica\Test\Base as BaseTest;
/**
* @author chabior
*/
class ConnectionPoolTest extends BaseTest
{
/**
* @group unit
*/
public function testConstruct()
{
$pool = $this->createPool();
$this->assertEquals($this->getConnections(), $pool->getConnections());
}
/**
* @group unit
*/
public function testSetConnections()
{
$pool = $this->createPool();
$connections = $this->getConnections(5);
$pool->setConnections($connections);
$this->assertEquals($connections, $pool->getConnections());
$this->assertInstanceOf('Elastica\Connection\ConnectionPool', $pool->setConnections($connections));
}
/**
* @group unit
*/
public function testAddConnection()
{
$pool = $this->createPool();
$pool->setConnections(array());
$connections = $this->getConnections(5);
foreach ($connections as $connection) {
$pool->addConnection($connection);
}
$this->assertEquals($connections, $pool->getConnections());
$this->assertInstanceOf('Elastica\Connection\ConnectionPool', $pool->addConnection($connections[0]));
}
/**
* @group unit
*/
public function testHasConnection()
{
$pool = $this->createPool();
$this->assertTrue($pool->hasConnection());
}
/**
* @group unit
*/
public function testFailHasConnections()
{
$pool = $this->createPool();
$pool->setConnections(array());
$this->assertFalse($pool->hasConnection());
}
/**
* @group unit
*/
public function testGetConnection()
{
$pool = $this->createPool();
$this->assertInstanceOf('Elastica\Connection', $pool->getConnection());
}
protected function getConnections($quantity = 1)
{
$params = array();
$connections = array();
for ($i = 0; $i < $quantity; $i++) {
$connections[] = new Connection($params);
}
return $connections;
}
protected function createPool()
{
$connections = $this->getConnections();
$strategy = StrategyFactory::create('Simple');
$pool = new ConnectionPool($connections, $strategy);
return $pool;
}
}
|