lib/watirgrid.rb in watirgrid-0.0.4 vs lib/watirgrid.rb in watirgrid-0.0.5

- old
+ new

@@ -8,11 +8,11 @@ # 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 + attr_accessor :drb_server_uri, :ring_server, :browsers, :tuples 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 @@ -39,10 +39,16 @@ ## # 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 @@ -74,11 +80,11 @@ ## # Get all tuple spaces on ringserver def get_tuples(params = {}) quantity = calculate_quantity(params[:quantity]) - read_tuples(params[:architecture], params[:browser_type]) + 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) @@ -103,19 +109,21 @@ end ## # Read all tuples filtered by architecture and browser type # then populate the tuples accessor - def read_tuples(architecture, browser_type) + def read_tuples(params={}) @tuples = @ring_server.read_all([ - :name, + :WatirGrid, nil, # watir provider nil, # browser front object nil, # provider description nil, # hostname - architecture, - browser_type]) + params[:architecture], + params[:browser_type], + params[:uuid] + ]) end ## # Filter tuple by hostnames def filter_tuple_by_hostname(tuple, params={}) @@ -147,9 +155,10 @@ 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