lib/watirgrid.rb in watirgrid-0.0.9 vs lib/watirgrid.rb in watirgrid-1.0.0

- old
+ new

@@ -2,70 +2,70 @@ require 'provider' module Watir ## - # Extend Watir with a Grid class which + # Extend Watir with a Grid class which # implements a grid of browsers by connecting to a tuplespace # and instatiating remote browser objects on nominated providers. class Grid attr_accessor :drb_server_uri, :ring_server, :browsers, :tuples - def initialize(params = {}) + def initialize(params = {}) @drb_server_host = params[:drb_server_host] || external_interface @drb_server_port = params[:drb_server_port] || 0 @ring_server_host = params[:ring_server_host] || external_interface @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT @renewer = params[:renewer] || Rinda::SimpleRenewer.new logfile = params[:logfile] || STDOUT @log = Logger.new(logfile, 'daily') @log.level = params[:loglevel] || Logger::ERROR - @log.datetime_format = "%Y-%m-%d %H:%M:%S " - + @log.datetime_format = "%Y-%m-%d %H:%M:%S " + @browsers = [] @tuples = [] end ## # Start required services - def start(params = {}) + def start(params = {}) start_drb_server find_ring_server get_tuples(params) end ## # Return the size (quantity) of browsers started on the grid def size @browsers.size end - + ## # Write tuple back to tuplespace when finished using it def release_tuples @tuples.each { |tuple| @ring_server.write(tuple) } end private ## - # Get the external facing interface for this server - def external_interface + # Get the external facing interface for this server + def external_interface begin - UDPSocket.open {|s| s.connect('watir.com', 1); s.addr.last } + UDPSocket.open {|s| s.connect('watir.com', 1); s.addr.last } rescue '127.0.0.1' end end ## # Start the DRb Server def start_drb_server drb_server = DRb.start_service( - "druby://#{@drb_server_host}:#{@drb_server_port}") + "druby://#{@drb_server_host}:#{@drb_server_port}") @drb_server_uri = drb_server.uri @log.info("DRb server started on : #{@drb_server_uri}") end ## @@ -78,32 +78,32 @@ end ## # Get all tuple spaces on ringserver def get_tuples(params = {}) - quantity = calculate_quantity(params[:quantity]) + quantity = calculate_quantity(params[:quantity]) read_tuples(params) @log.info("Found #{@tuples.size} tuples.") if @tuples.size > -1 then @tuples[0..quantity].each do |tuple| if params[:hostnames] filter_tuple_by_hostname(tuple, params) else add_tuple_to_browsers(tuple) take_tuple(tuple) if params[:take_all] == true - end + end end end end ## # Sets the quantity (upper limit of array) of tuples to retrieve # This is because some users prefer not to specify a zero based # index when asking for n browsers def calculate_quantity(quantity) if (quantity.nil? or quantity == 0) then - quantity = -1 + quantity = -1 else quantity -= 1 end end @@ -116,12 +116,11 @@ nil, # watir provider nil, # browser front object nil, # provider description nil, # hostname params[:architecture], - params[:browser_type], - params[:uuid] + params[:browser_type] ]) end ## # Filter tuple by hostnames @@ -154,12 +153,11 @@ tuple_hash[:object] = tuple[2] tuple_hash[:description] = tuple[3] tuple_hash[:hostname] = tuple[4] tuple_hash[:architecture] = tuple[5] tuple_hash[:browser_type] = tuple[6] - tuple_hash[:uuid] = tuple[7] tuple_hash end - + end end