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
113
|
<?php
namespace Elastica\Test\Cluster;
use Elastica\Test\Base as BaseTest;
class HealthTest extends BaseTest
{
/**
* @var \Elastica\Cluster\Health
*/
protected $_health;
public function setUp()
{
$data = array(
'cluster_name' => 'test_cluster',
'status' => 'green',
'timed_out' => false,
'number_of_nodes' => 10,
'number_of_data_nodes' => 8,
'active_primary_shards' => 3,
'active_shards' => 4,
'relocating_shards' => 2,
'initializing_shards' => 7,
'unassigned_shards' => 5,
'indices' => array(
'index_one' => array(
),
'index_two' => array(
),
),
);
$health = $this
->getMockBuilder('Elastica\Cluster\Health')
->setConstructorArgs(array($this->_getClient()))
->setMethods(array('_retrieveHealthData'))
->getMock();
$health
->expects($this->any())
->method('_retrieveHealthData')
->will($this->returnValue($data));
// need to explicitly refresh because the mocking won't refresh the data in the constructor
$health->refresh();
$this->_health = $health;
}
public function testGetClusterName()
{
$this->assertEquals('test_cluster', $this->_health->getClusterName());
}
public function testGetStatus()
{
$this->assertEquals('green', $this->_health->getStatus());
}
public function testGetTimedOut()
{
$this->assertFalse($this->_health->getTimedOut());
}
public function testGetNumberOfNodes()
{
$this->assertEquals(10, $this->_health->getNumberOfNodes());
}
public function testGetNumberOfDataNodes()
{
$this->assertEquals(8, $this->_health->getNumberOfDataNodes());
}
public function testGetActivePrimaryShards()
{
$this->assertEquals(3, $this->_health->getActivePrimaryShards());
}
public function testGetActiveShards()
{
$this->assertEquals(4, $this->_health->getActiveShards());
}
public function testGetRelocatingShards()
{
$this->assertEquals(2, $this->_health->getRelocatingShards());
}
public function testGetInitializingShards()
{
$this->assertEquals(7, $this->_health->getInitializingShards());
}
public function testGetUnassignedShards()
{
$this->assertEquals(5, $this->_health->getUnassignedShards());
}
public function testGetIndices()
{
$indices = $this->_health->getIndices();
$this->assertInternalType('array', $indices);
$this->assertEquals(2, count($indices));
foreach ($indices as $index) {
$this->assertInstanceOf('Elastica\Cluster\Health\Index', $index);
}
}
}
|