Class: Riak::TestServer

Inherits:
Node show all
Defined in:
lib/riak/test_server.rb

Overview

The TestServer is a special Node that uses in-memory storage engines that are easily cleared. This is helpful when running test suites that store and retrieve objects from Riak and expect a clean-slate at the beginning of each test. Like Node, creation is idempotent, so you can keep the server around between runs of your test suite.

Constant Summary

Constants inherited from Node

Node::ENV_DEFAULTS, Node::LAGER_LEVELS, Node::NODE_DIRECTORIES, Node::STATS_REGEXP, Node::VM_DEFAULTS

Instance Attribute Summary

Attributes inherited from Node

#configuration, #env, #root, #source, #vm

Instance Method Summary collapse

Methods inherited from Node

#admin_script, #attach, #base_dir, #control_script, #control_script_name, #cookie, create, #create, #destroy, #erlang_sources, #exist?, #expand_log_level, #handoff_port, #http_ip, #http_port, #javascript_source, #join, #js_reload, #kv_backend, #leave, #manifest, #member_status, #name, #pb_ip, #pb_port, #peers, #ping, #read_console_log, #recreate, #remove, #restart, #ring_size, #ringready?, #search_backend, #services, #status, #stopped?, #version, #with_console

Methods included from Util::Translation

#i18n_scope, #t

Constructor Details

#initialize(configuration = {}) ⇒ TestServer

Creates a TestServer node, using in-memory backends for KV and Search.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/riak/test_server.rb', line 16

def initialize(configuration = {})
  configuration[:env] ||= {}
  configuration[:env][:riak_kv] ||= {}
  (configuration[:env][:riak_kv][:add_paths] ||= []) << File.expand_path("../../../erl_src", __FILE__)
  configuration[:env][:riak_kv][:test] = true
  configuration[:env][:memory_backend] ||={}
  configuration[:env][:memory_backend][:test] = true
  configuration[:env][:riak_search] ||= {}
  configuration[:env][:riak_search][:search_backend] = :riak_search_test_backend
  super configuration
end

Instance Method Details

#dropObject

Overrides the default Node#drop to simply clear the in-memory backends.



54
55
56
57
58
59
60
61
62
# File 'lib/riak/test_server.rb', line 54

def drop
  begin
    maybe_attach
    @console.command "#{kv_backend}:reset()."
    @console.command "riak_search_test_backend:reset()."
  rescue IOError
    retry
  end
end

#startObject

Overrides the default Node#start to return early if the console is still attached. Otherwise, starts and immediately attaches the console.



37
38
39
40
41
42
# File 'lib/riak/test_server.rb', line 37

def start
  unless open?
    super
    maybe_attach
  end
end

#started?Boolean

Overrides the default Node#started? to simply return true if the console is still attached.

Returns:

  • (Boolean)


30
31
32
# File 'lib/riak/test_server.rb', line 30

def started?
  open? || super
end

#stopObject

Overrides the default Node#stop to close the console before stopping the node.



46
47
48
49
50
# File 'lib/riak/test_server.rb', line 46

def stop
  @console.close if @console && !@console.frozen?
  @console = nil
  super
end