|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Petrica |
|
5
|
|
|
* Date: 5/29/2016 |
|
6
|
|
|
* Time: 13:10 |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Petrica\StatsdSystem\Tests\Gauge; |
|
9
|
|
|
|
|
10
|
|
|
use Petrica\StatsdSystem\Collection\ValuesCollection; |
|
11
|
|
|
|
|
12
|
|
|
class ProcessesGaugeTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
public function testGetGauge() |
|
15
|
|
|
{ |
|
16
|
|
|
$gauge = $this->getMockBuilder('Petrica\StatsdSystem\Gauge\ProcessesGauge') |
|
17
|
|
|
->setMethods(array( |
|
18
|
|
|
'getCommand' |
|
19
|
|
|
)) |
|
20
|
|
|
->getMock(); |
|
21
|
|
|
|
|
22
|
|
|
$command = $this->getMockBuilder('Petrica\StatsdSystem\Model\TopCommand') |
|
23
|
|
|
->setMethods(array( |
|
24
|
|
|
'run' |
|
25
|
|
|
)) |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
|
|
28
|
|
|
$command->method('run') |
|
29
|
|
|
->willReturn(array( |
|
30
|
|
|
array(), |
|
31
|
|
|
array(), |
|
32
|
|
|
array(), |
|
33
|
|
|
array(), |
|
34
|
|
|
array(), |
|
35
|
|
|
array(), |
|
36
|
|
|
array(), |
|
37
|
|
|
array( |
|
38
|
|
|
'1', 'root', '0', '0', '0', '0', '0', '0', '10.5', '5.5', '0:0', 'process_name' |
|
39
|
|
|
), |
|
40
|
|
|
array( |
|
41
|
|
|
'2', 'root', '0', '0', '0', '0', '0', '0', '3.5', '1.5', '0:0', 'process_name' |
|
42
|
|
|
), |
|
43
|
|
|
array( |
|
44
|
|
|
'3', 'root', '0', '0', '0', '0', '0', '0', '2', '0.5', '0:0', 'process_name_exclude' |
|
45
|
|
|
), |
|
46
|
|
|
array( |
|
47
|
|
|
'4', 'root', '0', '0', '0', '0', '0', '0', '5', '2.5', '0:0', 'other_process' |
|
48
|
|
|
) |
|
49
|
|
|
)); |
|
50
|
|
|
|
|
51
|
|
|
$gauge->method('getCommand') |
|
52
|
|
|
->willReturn($command); |
|
53
|
|
|
|
|
54
|
|
|
$collection = $gauge->getCollection(); |
|
55
|
|
|
|
|
56
|
|
|
$expected = new ValuesCollection(); |
|
57
|
|
|
$expected->add('process_name.cpu.value', 14); |
|
58
|
|
|
$expected->add('other_process.cpu.value', 5); |
|
59
|
|
|
$expected->add('process_name.memory.value', 7); |
|
60
|
|
|
$expected->add('other_process.memory.value', 2.5); |
|
61
|
|
|
|
|
62
|
|
|
$this->assertEquals($expected, $collection); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|