Files
elasticsearch-js/test/integration/yaml_suite/client_manager.js
Spencer Alger 96b44ebf8b Merging spenceralger:travis_and_coveralls. Summary of changes:
- removed several unneeded devDeps
- removed old get_spec.js script
- the client's ping method will now send back true as the body when the ping
  succceeds, and false when it does not. When the ping fails, the error will
  still be sent back and the connection's status will still be set to "dead".
- All of the client's methods now have a spec property, which will provide the
  JSON spec used to run that method.
- The yaml test runner will only camelCase param names that are documented, uses
  the client's method's new spec property
- Trace log events will now have their proper original query string parameters
- The "tracer" logger will now write to elasticsearch-tracer.log by default, and
  will truncate the file if it already exists.
- When running the integration tests, the client will now use a tracer logger which
  writes to stderr. The default level is "warning", but with the VERBOSE environment
  var it becomes "trace" and the logger will write to it's default file
- Added .idea to the .gitignore, it was being published to NPM
- Cleanup of the grunt tasks. Consilidated several tiny files into seperate moderately sized ones.
2013-12-18 13:21:40 -07:00

94 lines
2.0 KiB
JavaScript

var BROWSER = process.env.browser;
var VERBOSE = process.env.VERBOSE;
if (BROWSER) {
/* jshint browser: true */
var es = window.elasticsearch;
} else {
var es = require('../../../src/elasticsearch');
}
var argv = require('./argv');
var server = require('./server');
// var path = require('path');
// var fs = require('fs');
var _ = require('../../../src/lib/utils');
// current client
var client = null;
// when set to a boolean, hold the test of a ping
var externalExists;
// a reference to a personal instance of ES Server
var esServer = null;
module.exports = {
create: function create(cb) {
if (argv.createServer || externalExists === false) {
if (!esServer) {
server.start(function (err, _server) {
esServer = _server;
if (err) {
done(err);
} else {
doCreateClient(done);
}
});
} else {
doCreateClient(done);
}
} else if (externalExists === void 0) {
doCreateClient(function () {
client.ping({
requestTimeout: 1000
}, function (err) {
if (err instanceof es.errors.ConnectionFault) {
externalExists = false;
create(done);
} else {
done(err);
}
});
});
} else {
doCreateClient(done);
}
function done(err) {
cb(err, client);
}
function doCreateClient(cb) {
// close existing client
if (client) {
client.close();
}
client = new es.Client({
hosts: [
{
host: esServer ? esServer.__hostname : argv.host,
port: esServer ? esServer.__port : argv.port
}
],
log: {
type: BROWSER
? 'console'
: VERBOSE
? 'tracer'
: 'stdio',
level: VERBOSE
? 'trace'
: 'warning',
path: VERBOSE ? undefined : false
}
});
_.nextTick(cb);
}
},
get: function () {
return client;
}
};