Class: RSMP::Validator::Tester

Inherits:
Object
  • Object
show all
Includes:
Log
Defined in:
lib/rsmp/validator/tester.rb

Overview

Base class for testing either a site or a supervisor. Handles running the corresponding local site/supervisor inside an Async reactor.

Direct Known Subclasses

SiteTester, SupervisorTester

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Log

#log

Class Method Details

.sentinel_errorsObject



11
12
13
# File 'lib/rsmp/validator/tester.rb', line 11

def self.sentinel_errors
  @sentinel_errors ||= []
end

Instance Method Details

#configObject



15
16
17
# File 'lib/rsmp/validator/tester.rb', line 15

def config
  RSMP::Validator.config
end

#connected(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Ensures that the site is connected. If the site is already connected, the block will be called immediately. Otherwise waits until the site is connected before calling the block.

Yields:

  • (Async::Task.current, @node, @proxy)


22
23
24
25
26
# File 'lib/rsmp/validator/tester.rb', line 22

def connected(options = {})
  start options, 'Connecting'
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
end

#disconnected {|Async::Task.current| ... } ⇒ Object

Disconnects the site if connected before calling the block.

Yields:

  • (Async::Task.current)


47
48
49
50
# File 'lib/rsmp/validator/tester.rb', line 47

def disconnected
  stop 'Disconnecting'
  yield Async::Task.current
end

#isolated(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Like connected, except that the connection is closed after the test.

Yields:

  • (Async::Task.current, @node, @proxy)


38
39
40
41
42
43
44
# File 'lib/rsmp/validator/tester.rb', line 38

def isolated(options = {})
  stop 'Isolating'
  start options, 'Connecting'
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
  stop 'Isolating'
end

#reconnected(options = {}) {|Async::Task.current, @node, @proxy| ... } ⇒ Object

Disconnects the site if connected, then waits until the site is connected before calling the block.

Yields:

  • (Async::Task.current, @node, @proxy)


30
31
32
33
34
35
# File 'lib/rsmp/validator/tester.rb', line 30

def reconnected(options = {})
  stop 'Reconnecting'
  start options
  wait_for_proxy
  yield Async::Task.current, @node, @proxy
end

#stop(why = nil) ⇒ Object

Stop the rsmp supervisor



53
54
55
56
57
58
59
60
61
62
# File 'lib/rsmp/validator/tester.rb', line 53

def stop(why = nil)
  if @node
    log why if why
    @node.ignore_errors RSMP::DisconnectError do
      @node.stop
    end
  end
  @node = nil
  @proxy = nil
end