summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/Cluster/Health/IndexTest.php
blob: 00a121fc391b5d0c74456d0c4d6c075fe665d689 (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
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
<?php
namespace Elastica\Test\Cluster\Health;

use Elastica\Cluster\Health\Index as HealthIndex;
use Elastica\Test\Base as BaseTest;

class IndexTest extends BaseTest
{
    /**
     * @var \Elastica\Cluster\Health\Index
     */
    protected $_index;

    public function setUp()
    {
        parent::setUp();

        $data = array(
            'status' => 'yellow',
            'number_of_shards' => 1,
            'number_of_replicas' => 2,
            'active_primary_shards' => 3,
            'active_shards' => 4,
            'relocating_shards' => 5,
            'initializing_shards' => 6,
            'unassigned_shards' => 7,
            'shards' => array(
                '0' => array(
                    'status' => 'yellow',
                    'primary_active' => false,
                    'active_shards' => 0,
                    'relocating_shards' => 1,
                    'initializing_shards' => 0,
                    'unassigned_shards' => 1,
                ),
                '1' => array(
                    'status' => 'yellow',
                    'primary_active' => true,
                    'active_shards' => 1,
                    'relocating_shards' => 0,
                    'initializing_shards' => 0,
                    'unassigned_shards' => 1,
                ),
                '2' => array(
                    'status' => 'green',
                    'primary_active' => true,
                    'active_shards' => 1,
                    'relocating_shards' => 0,
                    'initializing_shards' => 0,
                    'unassigned_shards' => 0,
                ),
            ),
        );

        $this->_index = new HealthIndex('test', $data);
    }

    /**
     * @group unit
     */
    public function testGetName()
    {
        $this->assertEquals('test', $this->_index->getName());
    }

    /**
     * @group unit
     */
    public function testGetStatus()
    {
        $this->assertEquals('yellow', $this->_index->getStatus());
    }

    /**
     * @group unit
     */
    public function testGetNumberOfShards()
    {
        $this->assertEquals(1, $this->_index->getNumberOfShards());
    }

    /**
     * @group unit
     */
    public function testGetNumberOfReplicas()
    {
        $this->assertEquals(2, $this->_index->getNumberOfReplicas());
    }

    /**
     * @group unit
     */
    public function testGetActivePrimaryShards()
    {
        $this->assertEquals(3, $this->_index->getActivePrimaryShards());
    }

    /**
     * @group unit
     */
    public function testGetActiveShards()
    {
        $this->assertEquals(4, $this->_index->getActiveShards());
    }

    /**
     * @group unit
     */
    public function testGetRelocatingShards()
    {
        $this->assertEquals(5, $this->_index->getRelocatingShards());
    }

    /**
     * @group unit
     */
    public function testGetInitializingShards()
    {
        $this->assertEquals(6, $this->_index->getInitializingShards());
    }

    /**
     * @group unit
     */
    public function testGetUnassignedShards()
    {
        $this->assertEquals(7, $this->_index->getUnassignedShards());
    }

    /**
     * @group unit
     */
    public function testGetShards()
    {
        $shards = $this->_index->getShards();

        $this->assertInternalType('array', $shards);
        $this->assertEquals(3, count($shards));

        foreach ($shards as $shard) {
            $this->assertInstanceOf('Elastica\Cluster\Health\Shard', $shard);
        }
    }
}