forked from ruflin/Elastica
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealthTest.php
199 lines (172 loc) · 4.52 KB
/
HealthTest.php
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
namespace Elastica\Test\Cluster;
use Elastica\Cluster\Health;
use Elastica\Cluster\Health\Index;
use Elastica\Test\Base as BaseTest;
/**
* @internal
*/
class HealthTest extends BaseTest
{
/**
* @var Health
*/
protected $_health;
protected function setUp(): void
{
parent::setUp();
$data = [
'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,
'delayed_unassigned_shards' => 4,
'number_of_pending_tasks' => 1,
'number_of_in_flight_fetch' => 2,
'task_max_waiting_in_queue_millis' => 634,
'active_shards_percent_as_number' => 50.0,
'indices' => [
'index_one' => [
],
'index_two' => [
],
],
];
$health = $this
->getMockBuilder(Health::class)
->setConstructorArgs([$this->_getClient()])
->setMethods(['_retrieveHealthData'])
->getMock()
;
$health
->method('_retrieveHealthData')
->willReturn($data)
;
// need to explicitly refresh because the mocking won't refresh the data in the constructor
$health->refresh();
$this->_health = $health;
}
/**
* @group unit
*/
public function testGetClusterName(): void
{
$this->assertEquals('test_cluster', $this->_health->getClusterName());
}
/**
* @group unit
*/
public function testGetStatus(): void
{
$this->assertEquals('green', $this->_health->getStatus());
}
/**
* @group unit
*/
public function testGetTimedOut(): void
{
$this->assertFalse($this->_health->getTimedOut());
}
/**
* @group unit
*/
public function testGetNumberOfNodes(): void
{
$this->assertEquals(10, $this->_health->getNumberOfNodes());
}
/**
* @group unit
*/
public function testGetNumberOfDataNodes(): void
{
$this->assertEquals(8, $this->_health->getNumberOfDataNodes());
}
/**
* @group unit
*/
public function testGetActivePrimaryShards(): void
{
$this->assertEquals(3, $this->_health->getActivePrimaryShards());
}
/**
* @group unit
*/
public function testGetActiveShards(): void
{
$this->assertEquals(4, $this->_health->getActiveShards());
}
/**
* @group unit
*/
public function testGetRelocatingShards(): void
{
$this->assertEquals(2, $this->_health->getRelocatingShards());
}
/**
* @group unit
*/
public function testGetInitializingShards(): void
{
$this->assertEquals(7, $this->_health->getInitializingShards());
}
/**
* @group unit
*/
public function testGetUnassignedShards(): void
{
$this->assertEquals(5, $this->_health->getUnassignedShards());
}
/**
* @group unit
*/
public function testGetDelayedUnassignedShards(): void
{
$this->assertEquals(4, $this->_health->getDelayedUnassignedShards());
}
/**
* @group unit
*/
public function testNumberOfPendingTasks(): void
{
$this->assertEquals(1, $this->_health->getNumberOfPendingTasks());
}
/**
* @group unit
*/
public function testNumberOfInFlightFetch(): void
{
$this->assertEquals(2, $this->_health->getNumberOfInFlightFetch());
}
/**
* @group unit
*/
public function testTaskMaxWaitingInQueueMillis(): void
{
$this->assertEquals(634, $this->_health->getTaskMaxWaitingInQueueMillis());
}
/**
* @group unit
*/
public function testActiveShardsPercentAsNumber(): void
{
$this->assertEquals(50.0, $this->_health->getActiveShardsPercentAsNumber());
}
/**
* @group unit
*/
public function testGetIndices(): void
{
$indices = $this->_health->getIndices();
$this->assertIsArray($indices);
$this->assertCount(2, $indices);
$this->assertArrayHasKey('index_one', $indices);
$this->assertArrayHasKey('index_two', $indices);
$this->assertContainsOnlyInstancesOf(Index::class, $indices);
}
}