Class: Flare::Test::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/flare/test/node.rb

Overview

Description

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hostname_port, pid) ⇒ Node

Returns a new instance of Node.



16
17
18
19
20
21
# File 'lib/flare/test/node.rb', line 16

def initialize(hostname_port, pid)
  @hostname_port = hostname_port
  @hostname, @port = hostname_port.split(':')
  @pid = pid
  @alive = true
end

Instance Attribute Details

#hostnameObject (readonly)

Returns the value of attribute hostname.



59
60
61
# File 'lib/flare/test/node.rb', line 59

def hostname
  @hostname
end

#hostname_portObject (readonly)

Returns the value of attribute hostname_port.



59
60
61
# File 'lib/flare/test/node.rb', line 59

def hostname_port
  @hostname_port
end

#pidObject (readonly)

Returns the value of attribute pid.



59
60
61
# File 'lib/flare/test/node.rb', line 59

def pid
  @pid
end

#portObject (readonly)

Returns the value of attribute port.



59
60
61
# File 'lib/flare/test/node.rb', line 59

def port
  @port
end

Instance Method Details

#contObject



41
42
43
# File 'lib/flare/test/node.rb', line 41

def cont
  Process.kill :CONT, @pid
end

#open(&block) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/flare/test/node.rb', line 23

def open(&block)
  return nil unless @alive
  node = Flare::Tools::Node.open(@hostname, @port)
  return node if block.nil?
  ret = nil
  begin
    ret = block.call(node)
  rescue => e
    node.close
    raise e
  end
  ret
end

#stopObject



37
38
39
# File 'lib/flare/test/node.rb', line 37

def stop
  Process.kill :STOP, @pid
end

#terminateObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/flare/test/node.rb', line 45

def terminate
  puts "killing... #{@pid}"
  begin
    Timeout.timeout(10) do
      Process.kill :TERM, @pid
      Process.waitpid @pid
    end
  rescue TimeoutError => e
    Process.kill :KILL, @pid
    Process.waitpid @pid
  end
  @alive = false
end