class ContainedMr::Mock::Job

@see {ContainedMr::Job}

Attributes

_json_options[R]

@return {Hash} the options provided to the Job constructor

_mapper_input[R]

@return {String} the input data provided to {#build_mapper_image}

id[R]

@see {ContainedMr::Job}

item_count[R]

@see {ContainedMr::Job}

name_prefix[R]

@see {ContainedMr::Job}

template[R]

@see {ContainedMr::Job}

Public Class Methods

new(template, id, json_options) click to toggle source

@see {ContainedMr::Job#initialize}

# File lib/contained_mr/mock/job.rb, line 20
def initialize(template, id, json_options)
  @template = template
  @id = id
  @name_prefix = template.name_prefix
  @item_count = template.item_count

  @mapper_image_id = nil
  @reducer_image_id = nil

  @mappers = Array.new @item_count
  @reducer = nil
  @mapper_options = nil
  @reducer_options = nil
  @_mapper_input = nil

  @destroyed = false
  @_json_options = json_options
  parse_options json_options

  @mock_mappers = (1..@item_count).map do |i|
    ContainedMr::Mock::Runner.new mapper_container_options(i),
      @mapper_options[:wait_time], @template.mapper_output_path
  end
  @mock_reducer = ContainedMr::Mock::Runner.new reducer_container_options,
      @reducer_options[:wait_time], @template.reducer_output_path
end

Public Instance Methods

_mock_mapper_runner(i) click to toggle source

Returns the mock pretending to be the runner used for a mapper.

@param {Number} i the mapper number @return {ContainedMr::Mock::Runner} the runner that will be returned

by {ContainedMr::Mock::Job#mapper_runner} after
{ContainedMr::Mock::Job#run_mapper} completes.
# File lib/contained_mr/mock/job.rb, line 96
def _mock_mapper_runner(i)
  if i < 1 || i > @item_count
    raise ArgumentError, "Invalid mapper number #{i}"
  end
  @mock_mappers[i - 1]
end
_mock_reducer_runner() click to toggle source

Returns the mock pretending to be the runner used for the reducer.

@return {ContainedMr::Mock::Runner} the mock runner that will be returned

by {ContainedMr::Mock::Job#reducer_runner} after
{ContainedMr::Mock::Job#run_reducer} completes.
# File lib/contained_mr/mock/job.rb, line 108
def _mock_reducer_runner
  @mock_reducer
end
build_mapper_image(mapper_input) click to toggle source

@see {ContainedMr::Job#build_mapper_image}

# File lib/contained_mr/mock/job.rb, line 54
def build_mapper_image(mapper_input)
  unless @mapper_image_id.nil?
    raise RuntimeError, 'Mapper image already exists'
  end
  @_mapper_input = mapper_input
  @mapper_image_id = 'mock-job-mapper-image-id'
end
build_reducer_image() click to toggle source

@see {ContainedMr::Job#build_reducer_image}

# File lib/contained_mr/mock/job.rb, line 63
def build_reducer_image
  unless @reducer_image_id.nil?
    raise RuntimeError, 'Reducer image already exists'
  end
  1.upto @item_count do |i|
    raise RuntimeError, 'Not all mappers ran' if mapper_runner(i).nil?
  end
  @reducer_image_id = 'mock-job-reducer-image-id'
end
destroy!() click to toggle source

@see {ContainedMr::Job#destroy}

# File lib/contained_mr/mock/job.rb, line 48
def destroy!
  @destroyed = true
  self
end
destroyed?() click to toggle source

@return {Boolean} true if {#destroy!} was called

# File lib/contained_mr/mock/job.rb, line 15
def destroyed?
  @destroyed
end
run_mapper(i) click to toggle source

@see {ContainedMr::Job#run_mapper}

# File lib/contained_mr/mock/job.rb, line 74
def run_mapper(i)
  if i < 1 || i > @item_count
    raise ArgumentError, "Invalid mapper number #{i}"
  end
  raise RuntimeError, 'Mapper image does not exist' if @mapper_image_id.nil?
  @mappers[i - 1] = @mock_mappers[i - 1]
end
run_reducer() click to toggle source

@see {ContainedMr::Job#run_reducer}

# File lib/contained_mr/mock/job.rb, line 83
def run_reducer
  if @reducer_image_id.nil?
    raise RuntimeError, 'Reducer image does not exist'
  end
  @reducer = @mock_reducer
end