class ContainedMr::Mock::Runner

@see {ContainedMr::Runner}

Attributes

_container_options[R]

@return {Hash<String, Object>} the options passed to the constructor

_output_path[R]

@return {Hash<String, Object>} the output path passed to the constructor

_time_limit[R]

@return {Hash<String, Object>} the time limit passed to the constructor

Public Class Methods

new(container_options, time_limit, output_path) click to toggle source

@see {ContainedMr::Runner#initialize}

# File lib/contained_mr/mock/runner.rb, line 23
def initialize(container_options, time_limit, output_path)
  @_container_options = container_options
  @_time_limit = time_limit
  @_output_path = output_path

  @container_id = nil
  @started_at = @ended_at = nil
  @status_code = nil
  @timed_out = nil
  @stdout = @stderr = nil
  @output = nil

  @performed = false
  @destroyed = false
end

Public Instance Methods

_logs() click to toggle source

Convenience method for looking up the log size limit in container options.

@return {Number} the container’s log limit, in megabytes

# File lib/contained_mr/mock/runner.rb, line 122
def _logs
  return nil unless host_config = @_container_options['HostConfig']
  return nil unless log_config = host_config['LogConfig']
  return nil unless config = log_config['Config']
  return nil unless max_size = config['max-size']

  max_size.to_i / (1024 * 1024).to_f
end
_mock_set(attributes) click to toggle source

Sets the container execution data returned by the mock.

@param {Hash<Symbol, Object>} attributes values describing the result of

running the job

@return {ContainedMr::Runner} self

# File lib/contained_mr/mock/runner.rb, line 56
def _mock_set(attributes)
  @started_at = attributes[:started_at]
  @ended_at = attributes[:ended_at]
  @status_code = attributes[:status_code]
  @timed_out = attributes[:timed_out]
  @stdout = attributes[:stdout]
  @stderr = attributes[:stderr]
  @output = attributes[:output]
  self
end
_ram_limit() click to toggle source

Convenience method for looking up the RAM limit in the container options.

@return {Number} the container’s RAM limit, in megabytes

# File lib/contained_mr/mock/runner.rb, line 90
def _ram_limit
  return nil unless host_config = @_container_options['HostConfig']
  return nil unless memory = host_config['Memory']
  memory / (1024 * 1024).to_f
end
_swap_limit() click to toggle source

Convenience method for looking up the swap limit in the container options.

@return {Number} the container’s swap limit, in megabytes

# File lib/contained_mr/mock/runner.rb, line 99
def _swap_limit
  return nil unless host_config = @_container_options['HostConfig']
  return nil unless memory = host_config['Memory']
  return nil unless memory_swap = host_config['MemorySwap']

  (memory_swap - memory) / (1024 * 1024).to_f
end
_ulimit(name) click to toggle source

Convenience method for looking up an ulimit in the container options.

@param {String} name the ulimit’s name, such as ‘cpu’ or ‘rss’ @return {Number} the ulimit’s hard and soft value, or nil if the ulimit was

not found

@raise {RuntimeError} if the ulimit’s hard and soft values don’t match

# File lib/contained_mr/mock/runner.rb, line 73
def _ulimit(name)
  return nil unless ulimits = @_container_options['Ulimits']

  ulimits.each do |ulimit|
    if ulimit['Name'] == name
      if ulimit['Hard'] != ulimit['Soft']
        raise RuntimeError, "Hard/soft ulimit mismatch for #{name}"
      end
      return ulimit['Hard']
    end
  end
  nil
end
_vcpus() click to toggle source

Convenience method for looking up CPU allocation in the container options.

@return {Number} the number of CPU cores allocated to the container; this

can be a fraction
# File lib/contained_mr/mock/runner.rb, line 111
def _vcpus
  return nil unless host_config = @_container_options['HostConfig']
  return nil unless period = host_config['CpuPeriod']
  return nil unless quota = host_config['CpuQuota']

  quota / period.to_f
end
destroy!() click to toggle source

@see {ContainedMr::Runner#destroy!}

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

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

# File lib/contained_mr/mock/runner.rb, line 16
def destroyed?
  @destroyed
end
perform() click to toggle source

@see {ContainedMr::Runner#perform}

# File lib/contained_mr/mock/runner.rb, line 40
def perform
  @performed = true
  self
end
performed?() click to toggle source

@return {Boolean} true if {#perform} was called

# File lib/contained_mr/mock/runner.rb, line 11
def performed?
  @performed
end