update node-reading logic to match elasticsearch-py

This commit is contained in:
spalger
2017-02-08 16:58:27 -07:00
parent 684fbd77c8
commit 6309425951
10 changed files with 204 additions and 87 deletions

28
test/fixtures/short_node_list.0.90.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
"id1": {
"name": "name1",
"transport_address": "inet[/192.168.1.1:9300]",
"hostname": "spalger",
"version": "0.90.14-SNAPSHOT",
"http_address": "inet[/192.168.1.1:9400]",
"http": {
"bound_address": "inet[/192.168.1.1:9400]",
"publish_address": "inet[/192.168.1.1:9400]",
"max_content_length": "100mb",
"max_content_length_in_bytes": 104857600
}
},
"id2": {
"name": "name2",
"transport_address": "inet[localhost/127.0.0.1:9301]",
"hostname": "spalger",
"version": "0.90.14-SNAPSHOT",
"http_address": "inet[localhost/127.0.0.1:9440]",
"http": {
"bound_address": "inet[/127.0.0.1:9440]",
"publish_address": "inet[localhost/127.0.0.1:9440]",
"max_content_length": "100mb",
"max_content_length_in_bytes": 104857600
}
}
}

30
test/fixtures/short_node_list.1.0.json vendored Normal file
View File

@ -0,0 +1,30 @@
{
"id1": {
"name": "name1",
"transport_address": "inet[/10.10.10.100:9301]",
"host": "spalger",
"ip": "192.168.1.1",
"version": "1.0.4-SNAPSHOT",
"build": "311a60b",
"http_address": "inet[/10.10.10.100:9205]",
"http": {
"bound_address": "inet[/10.10.10.100:9205]",
"publish_address": "inet[/10.10.10.100:9205]",
"max_content_length_in_bytes": 104857600
}
},
"id2": {
"name": "name2",
"transport_address": "inet[published.hostname/10.10.10.101:9301]",
"host": "spalger",
"ip": "192.168.1.1",
"version": "1.0.4-SNAPSHOT",
"build": "311a60b",
"http_address": "inet[published.hostname/10.10.10.101:9205]",
"http": {
"bound_address": "inet[/10.10.10.101:9205]",
"publish_address": "inet[published.hostname/10.10.10.101:9205]",
"max_content_length_in_bytes": 104857600
}
}
}

View File

@ -1,16 +1,18 @@
{
"id1": {
"name": "Headknocker",
"transport_address": "10.10.10.100:9300",
"hostname": "Spencers-MacBook-Pro.local",
"version": "0.90.5",
"http_address": "10.10.10.100:9205"
"name": "name1",
"host": "Spencers-MacBook-Pro.local",
"version": "2.0.3-SNAPSHOT",
"http": {
"publish_address": "127.0.0.1:9400"
}
},
"id2": {
"name": "Buttknocker",
"transport_address": "10.10.10.101:9300",
"hostname": "Johns-MacBook-Pro.local",
"version": "0.90.5",
"http_address": "published.hostname/10.10.10.101:9205"
"name": "name2",
"host": "Johns-MacBook-Pro.local",
"version": "2.0.3-SNAPSHOT",
"http": {
"publish_address": "published.hostname/127.0.0.1:9400"
}
}
}
}

18
test/fixtures/short_node_list.5.0.json vendored Normal file
View File

@ -0,0 +1,18 @@
{
"id1": {
"name": "name1",
"host": "127.0.0.1",
"version": "5.0.3",
"http": {
"publish_address": "127.0.0.1:9400"
}
},
"id2": {
"name": "name2",
"host": "127.0.0.1",
"version": "5.0.3",
"http": {
"publish_address": "published.hostname:9440"
}
}
}

View File

@ -1,16 +0,0 @@
{
"id1": {
"name": "Headknocker",
"transport_address": "inet[/10.10.10.100:9300]",
"hostname": "Spencers-MacBook-Pro.local",
"version": "0.90.5",
"http_address": "inet[/10.10.10.100:9205]"
},
"id2": {
"name": "Buttknocker",
"transport_address": "inet[/10.10.10.101:9300]",
"hostname": "Johns-MacBook-Pro.local",
"version": "0.90.5",
"http_address": "inet[/10.10.10.101:9205]"
}
}

View File

@ -2,61 +2,108 @@ describe('Nodes to host callback', function () {
var callback = require('../../../src/lib/nodes_to_host');
var expect = require('expect.js');
// example node list that would come back from "GET _cluster/nodes"
var nodes = require('../../fixtures/short_node_list.json');
var nodes90 = require('../../fixtures/short_node_list.0.90.json');
var nodes10 = require('../../fixtures/short_node_list.1.0.json');
var nodes20 = require('../../fixtures/short_node_list.2.0.json');
var nodes50 = require('../../fixtures/short_node_list.5.0.json');
context('pre 2.0 nodes style', function () {
context('0.x style', function () {
it('properly creates host objects', function () {
var hosts = callback(nodes);
expect(hosts.length).to.be(2);
expect(hosts[0]).to.eql({
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'Headknocker',
hostname: 'Spencers-MacBook-Pro.local',
version: '0.90.5'
expect(callback(nodes90)).to.eql([
{
host: '192.168.1.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '0.90.14-SNAPSHOT'
}
},
{
host: 'localhost',
port: 9440,
_meta: {
id: 'id2',
name: 'name2',
version: '0.90.14-SNAPSHOT'
}
}
});
expect(hosts[1]).to.eql({
host: '10.10.10.101',
port: 9205,
_meta: {
id: 'id2',
name: 'Buttknocker',
hostname: 'Johns-MacBook-Pro.local',
version: '0.90.5'
]);
});
});
context('1.0 nodes style', function () {
it('properly creates host objects', function () {
expect(callback(nodes10)).to.eql([
{
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'name1',
version: '1.0.4-SNAPSHOT'
}
},
{
host: 'published.hostname',
port: 9205,
_meta: {
id: 'id2',
name: 'name2',
version: '1.0.4-SNAPSHOT'
}
}
});
]);
});
});
context('2.0 nodes style', function () {
it('properly creates host objects', function () {
var hosts = callback(nodes20);
expect(hosts.length).to.be(2);
expect(hosts[0]).to.eql({
host: '10.10.10.100',
port: 9205,
_meta: {
id: 'id1',
name: 'Headknocker',
hostname: 'Spencers-MacBook-Pro.local',
version: '0.90.5'
expect(callback(nodes20)).to.eql([
{
host: '127.0.0.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '2.0.3-SNAPSHOT'
}
},
{
host: 'published.hostname',
port: 9400,
_meta: {
id: 'id2',
name: 'name2',
version: '2.0.3-SNAPSHOT'
}
}
});
expect(hosts[1]).to.eql({
host: 'published.hostname',
port: 9205,
_meta: {
id: 'id2',
name: 'Buttknocker',
hostname: 'Johns-MacBook-Pro.local',
version: '0.90.5'
]);
});
});
context('5.0 nodes style', function () {
it('properly creates host objects', function () {
expect(callback(nodes50)).to.eql([
{
host: '127.0.0.1',
port: 9400,
_meta: {
id: 'id1',
name: 'name1',
version: '5.0.3'
}
},
{
host: 'published.hostname',
port: 9440,
_meta: {
id: 'id2',
name: 'name2',
version: '5.0.3'
}
}
});
]);
});
});
@ -75,10 +122,12 @@ describe('Nodes to host callback', function () {
expect(function () {
callback({
node_id: {
http_address: 'not actually an http host'
http: {
publish_address: 'not actually an http host'
}
}
});
}).to.throwException(/^Malformed http_address/);
}).to.throwException(/^Malformed http.publish_address/);
});
});

View File

@ -5,7 +5,7 @@ var errors = require('../../../src/lib/errors');
var sinon = require('sinon');
var expect = require('expect.js');
var _ = require('lodash');
var nodeList = require('../../fixtures/short_node_list.json');
var nodeList = require('../../fixtures/short_node_list.5.0.json');
var stub = require('../../utils/auto_release_stub').make();
/**
@ -371,12 +371,12 @@ describe('Transport Class', function () {
expect(hosts).to.have.length(2);
expect(hosts[0]).to.be.a(Host);
expect(hosts[0].host).to.eql('10.10.10.100');
expect(hosts[0].port).to.eql(9205);
expect(hosts[0].host).to.eql('127.0.0.1');
expect(hosts[0].port).to.eql(9400);
expect(hosts[0]).to.be.a(Host);
expect(hosts[1].host).to.eql('10.10.10.101');
expect(hosts[1].port).to.eql(9205);
expect(hosts[1].host).to.eql('published.hostname');
expect(hosts[1].port).to.eql(9440);
done();
});
});

View File

@ -8,7 +8,6 @@ var sinon = require('sinon');
var nock = require('../../mocks/server.js');
var through2 = require('through2');
var _ = require('lodash');
var nodeList = require('../../fixtures/short_node_list.json');
var stub = require('../../utils/auto_release_stub').make();
/**