lib/elasticsearch/extensions/test/cluster.rb in elasticsearch-extensions-0.0.8 vs lib/elasticsearch/extensions/test/cluster.rb in elasticsearch-extensions-0.0.9
- old
+ new
@@ -28,11 +28,11 @@
#
# @see Cluster#start Cluster.start
# @see Cluster#stop Cluster.stop
#
module Cluster
- @@number_of_nodes = 0
+ @@number_of_nodes = (ENV['TEST_CLUSTER_NODES'] || 2).to_i
# Starts a cluster
#
# Launches the specified number of nodes in test-suitable configuration by default
# and prints information about the cluster -- unless this specific cluster is running already.
@@ -86,15 +86,17 @@
print "Starting ".ansi(:faint) +
@@number_of_nodes.to_s.ansi(:bold, :faint) +
" Elasticsearch nodes..".ansi(:faint)
+ pids = []
+
@@number_of_nodes.times do |n|
n += 1
pid = Process.spawn <<-COMMAND
#{arguments[:command]} \
- -D es.foreground=no \
+ -D es.foreground=yes \
-D es.cluster.name=#{arguments[:cluster_name]} \
-D es.node.name=#{arguments[:node_name]}-#{n} \
-D es.http.port=#{arguments[:port].to_i + (n-1)} \
-D es.gateway.type=#{arguments[:gateway_type]} \
-D es.index.store.type=#{arguments[:index_store]} \
@@ -102,15 +104,22 @@
-D es.path.work=#{arguments[:path_work]} \
-D es.network.host=0.0.0.0 \
-D es.discovery.zen.ping.multicast.enabled=true \
-D es.node.test=true \
#{arguments[:es_params]} \
- > /dev/null 2>&1
+ > /dev/null
COMMAND
Process.detach pid
+ pids << pid
end
+ # Check for proceses running
+ if `ps -p #{pids.join(' ')}`.split("\n").size < @@number_of_nodes+1
+ STDERR.puts "", "[!!!] Process failed to start (see output above)".ansi(:red)
+ exit(1)
+ end
+
wait_for_green(arguments[:port], arguments[:timeout])
return true
end
# Stop the cluster.
@@ -204,9 +213,11 @@
JSON.parse(Net::HTTP.get(uri))
rescue Exception => e
puts e.inspect if ENV['DEBUG']
nil
end
+
+ puts response.inspect if ENV['DEBUG']
if response && response['status'] == status && ( @@number_of_nodes.nil? || @@number_of_nodes == response['number_of_nodes'].to_i )
__print_cluster_info(port) and break
end