Skip to content

Commit

Permalink
Elastica_Node_Info updated to new behaviour in ES 0.19.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ruflin committed Mar 4, 2012
1 parent 13114fd commit dd13e77
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
3 changes: 3 additions & 0 deletions changes.txt
@@ -1,5 +1,8 @@
CHANGES

2012-03-04
- Node info call update. The receive os info and more, param is needed. By default, only basics are returned

2012-02-21
- Allow percolate queries in bulk requests
- Fix memory leak in curl requests
Expand Down
16 changes: 13 additions & 3 deletions lib/Elastica/Node/Info.php
Expand Up @@ -17,10 +17,11 @@ class Elastica_Node_Info

/**
* @param Elastica_Node $node Node object
* @param array $params List of params to return. Can be: settings, os, process, jvm, thread_pool, network, transport, http
*/
public function __construct(Elastica_Node $node) {
public function __construct(Elastica_Node $node, array $params = array()) {
$this->_node = $node;
$this->refresh();
$this->refresh($params);
}

/**
Expand Down Expand Up @@ -100,10 +101,19 @@ public function getResponse() {
/**
* Reloads all nodes information. Has to be called if informations changed
*
* @param array $params Params to return (default none). Possible options: settings, os, process, jvm, thread_pool, network, transport, http
* @return Elastica_Response Response object
*/
public function refresh() {
public function refresh(array $params = array()) {
$path = '_cluster/nodes/' . $this->getNode()->getName();

if (!empty($params)) {
$path .= '?';
foreach ($params as $param) {
$path .= $param . '=true&';
}
}

$this->_response = $this->getNode()->getClient()->request($path, Elastica_Request::GET);
$data = $this->getResponse()->getData();
$this->_data = reset($data['nodes']);
Expand Down
8 changes: 7 additions & 1 deletion test/lib/Elastica/Node/InfoTest.php
@@ -1,7 +1,8 @@
<?php

require_once dirname(__FILE__) . '/../../../bootstrap.php';

class Elastica_Node_InfoTest extends PHPUnit_Framework_TestCase
class Elastica_Node_InfoTest extends Elastica_Test
{
public function setUp() { }

Expand All @@ -15,6 +16,11 @@ public function testGet() {
$node = new Elastica_Node($name, $client);
$info = new Elastica_Node_Info($node);

$this->assertNull($info->get('os', 'mem', 'total'));

// Load os infos
$info = new Elastica_Node_Info($node, array('os'));

$this->assertInternalType('string', $info->get('os', 'mem', 'total'));
$this->assertInternalType('array', $info->get('os', 'mem'));
$this->assertNull($info->get('test', 'notest', 'notexist'));
Expand Down
6 changes: 3 additions & 3 deletions test/lib/Elastica/Type/MappingTest.php
Expand Up @@ -105,13 +105,13 @@ public function testNestedMapping() {
),
));

print_r($type->getMapping());
exit();
//print_r($type->getMapping());
//exit();
$type->addDocument($doc);

$index->refresh();
$resultSet = $type->search('ruflin');
print_r($resultSet);
//print_r($resultSet);
}

public function testParentMapping() {
Expand Down

0 comments on commit dd13e77

Please sign in to comment.