summaryrefslogtreecommitdiff
path: root/vendor/ruflin/elastica/test/lib/Elastica/Test/NodeTest.php
blob: d70825d1133f9852b55c55e9617987797486329d (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
<?php

namespace Elastica\Test;

use Elastica\Client;
use Elastica\Node;
use Elastica\Test\Base as BaseTest;

class NodeTest extends BaseTest
{

    public function testCreateNode()
    {
        $client = $this->_getClient();
        $names = $client->getCluster()->getNodeNames();
        $name = reset($names);

        $node = new Node($name, $client);
        $this->assertInstanceOf('Elastica\Node', $node);
    }

    public function testGetInfo()
    {
        $client = $this->_getClient();
        $names = $client->getCluster()->getNodeNames();
        $name = reset($names);

        $node = new Node($name, $client);

        $info = $node->getInfo();

        $this->assertInstanceOf('Elastica\Node\Info', $info);
    }

    public function testGetStats()
    {
        $client = $this->_getClient();
        $names = $client->getCluster()->getNodeNames();
        $name = reset($names);

        $node = new Node($name, $client);

        $stats = $node->getStats();

        $this->assertInstanceOf('Elastica\Node\Stats', $stats);
    }

    /**
     * Shuts one of two nodes down (if two available)
     */
    public function testShutdown()
    {
        $this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
        $client = $this->_getClient();
        $nodes = $client->getCluster()->getNodes();

        $count = count($nodes);
        if ($count < 2) {
            $this->markTestSkipped('At least two nodes have to be running, because 1 node is shutdown');
        }

           // Store node info of node with port 9200 for later
        foreach ($nodes as $key => $node) {
            if ($node->getInfo()->getPort() == 9200) {
                $info = $node->getInfo();
                unset($nodes[$key]);
            }
        }

        // Select one of the not port 9200 nodes and shut it down
        $node = array_shift($nodes);
        $node->shutdown('2s');

        // Wait until node is shutdown
        sleep(5);

        // Use still existing node
        $client = new Client(array('host' => $info->getIp(), 'port' => $info->getPort()));
        $names = $client->getCluster()->getNodeNames();

        // One node less ...
        $this->assertEquals($count - 1, count($names));
    }
}