roma 0.8.2 → 0.8.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/CHANG +326 -0
  2. data/CHANGELOG +132 -0
  3. data/{README.rdoc → FETCH_HEAD} +0 -0
  4. data/{LICENSE.rdoc → LICENSE} +0 -1
  5. data/README +17 -0
  6. data/Rakefile +33 -18
  7. data/ruby/server/bin/chg_redundancy +10 -0
  8. data/ruby/server/bin/key_access +7 -0
  9. data/ruby/server/bin/key_list +7 -0
  10. data/ruby/server/bin/mkconfig +19 -0
  11. data/{bin → ruby/server/bin}/mkrecent +0 -1
  12. data/{bin → ruby/server/bin}/mkroute +0 -1
  13. data/ruby/server/bin/multi_commander +19 -0
  14. data/ruby/server/bin/recoverlost +10 -0
  15. data/ruby/server/bin/recoverlost_alist +10 -0
  16. data/ruby/server/bin/recoverlost_alist_all +10 -0
  17. data/ruby/server/bin/recoverlost_alist_keys +10 -0
  18. data/{bin/recoverlost → ruby/server/bin/roma_watcher} +1 -2
  19. data/ruby/server/bin/romad +36 -0
  20. data/{bin → ruby/server/bin}/sample_watcher +0 -1
  21. data/{bin → ruby/server/bin}/sample_watcher2 +0 -1
  22. data/{bin/simple_bench → ruby/server/bin/sample_watcher3} +1 -2
  23. data/ruby/server/bin/simple_bench +26 -0
  24. data/{bin → ruby/server/bin}/ssroute +0 -1
  25. data/ruby/server/bin/test-scenario +11 -0
  26. data/{bin → ruby/server/bin}/tribunus +0 -1
  27. data/{lib → ruby/server/lib}/roma/async_process.rb +67 -15
  28. data/{lib → ruby/server/lib}/roma/command/bg_command_receiver.rb +1 -1
  29. data/ruby/server/lib/roma/command/command_definition.rb +422 -0
  30. data/ruby/server/lib/roma/command/mh_command_receiver.rb +127 -0
  31. data/ruby/server/lib/roma/command/receiver.rb +64 -0
  32. data/{lib → ruby/server/lib}/roma/command/rt_command_receiver.rb +6 -1
  33. data/ruby/server/lib/roma/command/sys_command_receiver.rb +609 -0
  34. data/{lib → ruby/server/lib}/roma/command/util_command_receiver.rb +15 -5
  35. data/{lib → ruby/server/lib}/roma/command/vn_command_receiver.rb +12 -4
  36. data/{lib → ruby/server/lib}/roma/command_plugin.rb +0 -0
  37. data/ruby/server/lib/roma/config.rb +84 -0
  38. data/{lib → ruby/server/lib}/roma/event/con_pool.rb +12 -1
  39. data/ruby/server/lib/roma/event/handler.rb +256 -0
  40. data/ruby/server/lib/roma/live_patch-20120302-001.rb +107 -0
  41. data/ruby/server/lib/roma/logging/rlogger.rb +163 -0
  42. data/ruby/server/lib/roma/messaging/con_pool.rb +92 -0
  43. data/{lib → ruby/server/lib}/roma/plugin/plugin_alist.rb +118 -240
  44. data/ruby/server/lib/roma/plugin/plugin_debug.rb +31 -0
  45. data/ruby/server/lib/roma/plugin/plugin_map.rb +177 -0
  46. data/ruby/server/lib/roma/plugin/plugin_mapcount.rb +185 -0
  47. data/{lib/roma/command/st_command_receiver.rb → ruby/server/lib/roma/plugin/plugin_storage.rb} +170 -146
  48. data/ruby/server/lib/roma/plugin/plugin_stub.rb +283 -0
  49. data/{lib → ruby/server/lib}/roma/plugin/plugin_test.rb +0 -0
  50. data/{lib → ruby/server/lib}/roma/romad.rb +221 -94
  51. data/{lib → ruby/server/lib}/roma/routing/cb_rttable.rb +4 -6
  52. data/{lib → ruby/server/lib}/roma/routing/merkle_tree.rb +0 -0
  53. data/ruby/server/lib/roma/routing/routing_data.rb +307 -0
  54. data/{lib → ruby/server/lib}/roma/routing/rttable.rb +4 -0
  55. data/{lib → ruby/server/lib}/roma/stats.rb +19 -3
  56. data/{lib → ruby/server/lib}/roma/storage/basic_storage.rb +25 -26
  57. data/{lib → ruby/server/lib}/roma/storage/dbm_storage.rb +1 -23
  58. data/{lib → ruby/server/lib}/roma/storage/dummy_storage.rb +0 -0
  59. data/{lib → ruby/server/lib}/roma/storage/rh_storage.rb +0 -0
  60. data/{lib → ruby/server/lib}/roma/storage/sqlite3_storage.rb +0 -0
  61. data/{lib → ruby/server/lib}/roma/storage/tc_storage.rb +62 -2
  62. data/ruby/server/lib/roma/tools/chg_redundancy.rb +36 -0
  63. data/ruby/server/lib/roma/tools/key_access.rb +105 -0
  64. data/ruby/server/lib/roma/tools/key_list.rb +94 -0
  65. data/ruby/server/lib/roma/tools/mkconfig.rb +535 -0
  66. data/{lib → ruby/server/lib}/roma/tools/mkrecent.rb +0 -0
  67. data/{lib → ruby/server/lib}/roma/tools/mkroute.rb +0 -0
  68. data/ruby/server/lib/roma/tools/multi_commander.rb +45 -0
  69. data/{lib → ruby/server/lib}/roma/tools/recoverlost.rb +0 -0
  70. data/{lib → ruby/server/lib}/roma/tools/recoverlost_alist.rb +0 -0
  71. data/ruby/server/lib/roma/tools/recoverlost_alist_all.rb +8 -0
  72. data/ruby/server/lib/roma/tools/recoverlost_alist_keys.rb +16 -0
  73. data/ruby/server/lib/roma/tools/recoverlost_lib.rb +349 -0
  74. data/ruby/server/lib/roma/tools/roma_watcher.rb +150 -0
  75. data/ruby/server/lib/roma/tools/roma_watcher_config.yml.example +20 -0
  76. data/{lib → ruby/server/lib}/roma/tools/sample_watcher.rb +3 -1
  77. data/{lib → ruby/server/lib}/roma/tools/sample_watcher2.rb +3 -1
  78. data/ruby/server/lib/roma/tools/sample_watcher3.rb +49 -0
  79. data/{lib → ruby/server/lib}/roma/tools/simple_bench.rb +2 -0
  80. data/ruby/server/lib/roma/tools/simple_bench2.rb +78 -0
  81. data/{lib → ruby/server/lib}/roma/tools/ssroute.rb +0 -0
  82. data/ruby/server/lib/roma/tools/test-scenario.rb +327 -0
  83. data/{lib → ruby/server/lib}/roma/tools/tribunus.rb +0 -0
  84. data/ruby/server/lib/roma/version.rb +4 -0
  85. data/{lib → ruby/server/lib}/roma/write_behind.rb +1 -0
  86. data/ruby/server/test/config4mhash.rb +68 -0
  87. data/ruby/server/test/config4storage_error.rb +69 -0
  88. data/{lib/roma/config.rb → ruby/server/test/config4test.rb} +6 -3
  89. data/{test → ruby/server/test}/rcirb.rb +0 -1
  90. data/{test → ruby/server/test}/roma-test-utils.rb +21 -8
  91. data/{test → ruby/server/test}/run-test.rb +3 -2
  92. data/ruby/server/test/storage_error_storage.rb +37 -0
  93. data/ruby/server/test/t_command_definition.rb +326 -0
  94. data/{test → ruby/server/test}/t_cpdata.rb +9 -3
  95. data/{test → ruby/server/test}/t_listplugin.rb +48 -12
  96. data/ruby/server/test/t_mapcountplugin.rb +231 -0
  97. data/ruby/server/test/t_mapplugin.rb +131 -0
  98. data/ruby/server/test/t_mhash.rb +222 -0
  99. data/ruby/server/test/t_rclient.rb +199 -0
  100. data/{test → ruby/server/test}/t_routing_data.rb +56 -0
  101. data/{test → ruby/server/test}/t_storage.rb +107 -111
  102. data/ruby/server/test/t_storage_error.rb +61 -0
  103. data/ruby/server/test/t_writebehind.rb +374 -0
  104. metadata +150 -82
  105. data/bin/recoverlost_alist +0 -8
  106. data/bin/romad +0 -7
  107. data/lib/roma/command/mh_command_receiver.rb +0 -117
  108. data/lib/roma/command/receiver.rb +0 -287
  109. data/lib/roma/event/handler.rb +0 -159
  110. data/lib/roma/plugin/plugin_debug.rb +0 -19
  111. data/lib/roma/tools/recoverlost_lib.rb +0 -217
  112. data/lib/roma/version.rb +0 -4
  113. data/test/t_rclient.rb +0 -318
  114. data/test/t_writebehind.rb +0 -200
File without changes
@@ -0,0 +1,4 @@
1
+
2
+ module Roma
3
+ VERSION = "0.8.10"
4
+ end
@@ -134,6 +134,7 @@ module Roma
134
134
  @wb_thread = Thread.new{
135
135
  wb_process_loop
136
136
  }
137
+ @wb_thread[:name] = 'write_behind'
137
138
  rescue =>e
138
139
  @log.error("#{e}\n#{$@}")
139
140
  end
@@ -0,0 +1,68 @@
1
+ require 'roma/storage/rh_storage'
2
+ require 'roma/storage/tc_storage'
3
+
4
+ module Roma
5
+
6
+ module Config
7
+ DEFAULT_PORT = 12000
8
+ DEFAULT_NAME = 'ROMA'
9
+
10
+ # :no_action | :auto_assign | :shutdown
11
+ DEFAULT_LOST_ACTION = :auto_assign
12
+
13
+ # log setting
14
+ LOG_SHIFT_AGE = 10
15
+ LOG_SHIFT_SIZE = 1024 * 1024 * 10
16
+ LOG_PATH = '.'
17
+ # :debug | :info | :warn | :error
18
+ LOG_LEVEL = :debug
19
+
20
+ # routing setting
21
+ RTTABLE_PATH = '.'
22
+
23
+ # connection setting
24
+ # like a MaxStartups spec in the sshd_config
25
+ # 'start:rate:full'
26
+ CONNECTION_CONTINUOUS_LIMIT = '200:30:300'
27
+
28
+ # storage setting
29
+ STORAGE_CLASS = Storage::TCStorage
30
+ STORAGE_DIVNUM = 10
31
+ STORAGE_PATH = '.'
32
+ STORAGE_DUMP_PATH = '/tmp'
33
+ STORAGE_OPTION = ''
34
+
35
+ # 5 days ago
36
+ STORAGE_DELMARK_EXPTIME = 60 * 60 * 24 * 5
37
+
38
+ # data copy setting
39
+ DATACOPY_STREAM_COPY_WAIT_PARAM = 0.0001
40
+
41
+ # plugin setting
42
+ PLUGIN_FILES = ['plugin_storage.rb','plugin_alist.rb']
43
+
44
+ # write-behind setting
45
+ WRITEBEHIND_PATH = './wb'
46
+ WRITEBEHIND_SHIFT_SIZE = 1024 * 1024 * 10
47
+
48
+ # redundant setting
49
+ REDUNDANT_ZREDUNDANT_SIZE = 0
50
+
51
+ def self.get_stat
52
+ ret = {}
53
+ ret['config.DEFAULT_LOST_ACTION'] = DEFAULT_LOST_ACTION
54
+ ret['config.LOG_SHIFT_AGE'] = LOG_SHIFT_AGE
55
+ ret['config.LOG_SHIFT_SIZE'] = LOG_SHIFT_SIZE
56
+ ret['config.LOG_PATH'] = File.expand_path(LOG_PATH)
57
+ ret['config.RTTABLE_PATH'] = File.expand_path(RTTABLE_PATH)
58
+ ret['config.STORAGE_DELMARK_EXPTIME'] = STORAGE_DELMARK_EXPTIME
59
+ ret['config.DATACOPY_STREAM_COPY_WAIT_PARAM'] = DATACOPY_STREAM_COPY_WAIT_PARAM
60
+ ret['config.PLUGIN_FILES'] = PLUGIN_FILES.inspect
61
+ ret['config.WRITEBEHIND_PATH'] = File.expand_path(WRITEBEHIND_PATH)
62
+ ret['config.WRITEBEHIND_SHIFT_SIZE'] = WRITEBEHIND_SHIFT_SIZE
63
+ ret
64
+ end
65
+
66
+ end
67
+
68
+ end
@@ -0,0 +1,69 @@
1
+ require 'roma/storage/rh_storage'
2
+ require 'roma/storage/storage_error_storage'
3
+
4
+ module Roma
5
+
6
+ module Config
7
+ DEFAULT_PORT = 12000
8
+ DEFAULT_NAME = 'ROMA'
9
+
10
+ # :no_action | :auto_assign | :shutdown
11
+ DEFAULT_LOST_ACTION = :auto_assign
12
+
13
+ # log setting
14
+ LOG_SHIFT_AGE = 10
15
+ LOG_SHIFT_SIZE = 1024 * 1024 * 10
16
+ LOG_PATH = '.'
17
+ # :debug | :info | :warn | :error
18
+ LOG_LEVEL = :debug
19
+
20
+ # routing setting
21
+ RTTABLE_PATH = '.'
22
+
23
+ # connection setting
24
+ # like a MaxStartups spec in the sshd_config
25
+ # 'start:rate:full'
26
+ CONNECTION_CONTINUOUS_LIMIT = '200:30:300'
27
+
28
+ # storage setting
29
+ # STORAGE_CLASS = Roma::Storage::RubyHashStorage
30
+ STORAGE_CLASS = Storage::StorageErrorStorage
31
+ STORAGE_DIVNUM = 10
32
+ STORAGE_PATH = '.'
33
+ STORAGE_DUMP_PATH = '/tmp'
34
+ STORAGE_OPTION = ''
35
+
36
+ # 5 days ago
37
+ STORAGE_DELMARK_EXPTIME = 60 * 60 * 24 * 5
38
+
39
+ # data copy setting
40
+ DATACOPY_STREAM_COPY_WAIT_PARAM = 0.0001
41
+
42
+ # plugin setting
43
+ PLUGIN_FILES = ['plugin_storage.rb','plugin_alist.rb','plugin_map.rb']
44
+
45
+ # write-behind setting
46
+ WRITEBEHIND_PATH = './wb'
47
+ WRITEBEHIND_SHIFT_SIZE = 1024 * 1024 * 10
48
+
49
+ # redundant setting
50
+ REDUNDANT_ZREDUNDANT_SIZE = 0
51
+
52
+ def self.get_stat
53
+ ret = {}
54
+ ret['config.DEFAULT_LOST_ACTION'] = DEFAULT_LOST_ACTION
55
+ ret['config.LOG_SHIFT_AGE'] = LOG_SHIFT_AGE
56
+ ret['config.LOG_SHIFT_SIZE'] = LOG_SHIFT_SIZE
57
+ ret['config.LOG_PATH'] = File.expand_path(LOG_PATH)
58
+ ret['config.RTTABLE_PATH'] = File.expand_path(RTTABLE_PATH)
59
+ ret['config.STORAGE_DELMARK_EXPTIME'] = STORAGE_DELMARK_EXPTIME
60
+ ret['config.DATACOPY_STREAM_COPY_WAIT_PARAM'] = DATACOPY_STREAM_COPY_WAIT_PARAM
61
+ ret['config.PLUGIN_FILES'] = PLUGIN_FILES.inspect
62
+ ret['config.WRITEBEHIND_PATH'] = File.expand_path(WRITEBEHIND_PATH)
63
+ ret['config.WRITEBEHIND_SHIFT_SIZE'] = WRITEBEHIND_SHIFT_SIZE
64
+ ret
65
+ end
66
+
67
+ end
68
+
69
+ end
@@ -1,5 +1,3 @@
1
- require 'roma/routing/rttable'
2
- require 'roma/routing/cb_rttable'
3
1
  require 'roma/storage/rh_storage'
4
2
 
5
3
  module Roma
@@ -21,6 +19,11 @@ module Roma
21
19
  # routing setting
22
20
  RTTABLE_PATH = '.'
23
21
 
22
+ # connection setting
23
+ # like a MaxStartups spec in the sshd_config
24
+ # 'start:rate:full'
25
+ CONNECTION_CONTINUOUS_LIMIT = '200:30:300'
26
+
24
27
  # storage setting
25
28
  STORAGE_CLASS = Roma::Storage::RubyHashStorage
26
29
  STORAGE_DIVNUM = 10
@@ -35,7 +38,7 @@ module Roma
35
38
  DATACOPY_STREAM_COPY_WAIT_PARAM = 0.0001
36
39
 
37
40
  # plugin setting
38
- PLUGIN_FILES = []
41
+ PLUGIN_FILES = ['plugin_storage.rb','plugin_alist.rb','plugin_map.rb','plugin_mapcount.rb']
39
42
 
40
43
  # write-behind setting
41
44
  WRITEBEHIND_PATH = './wb'
@@ -6,7 +6,6 @@ require 'irb'
6
6
 
7
7
  path = File.dirname(File.expand_path($PROGRAM_NAME))
8
8
  $LOAD_PATH << path + "/../lib"
9
- $LOAD_PATH << path + "/../../commons/lib"
10
9
  $LOAD_PATH << path + "/../../client/lib"
11
10
 
12
11
  require 'roma/client/rclient'
@@ -1,8 +1,9 @@
1
1
  require 'shell'
2
-
3
2
  require 'pathname'
4
3
  require 'fileutils'
5
4
  require 'rbconfig'
5
+ require 'roma/config'
6
+ require 'roma/messaging/con_pool'
6
7
 
7
8
  module RomaTestUtils
8
9
  module_function
@@ -18,6 +19,10 @@ module RomaTestUtils
18
19
  server_base_dir + "bin"
19
20
  end
20
21
 
22
+ def server_test_dir
23
+ server_base_dir + "test"
24
+ end
25
+
21
26
  def mkroute_path
22
27
  (server_bin_dir + "mkroute").to_s
23
28
  end
@@ -31,23 +36,30 @@ module RomaTestUtils
31
36
  RbConfig::CONFIG["ruby_install_name"])
32
37
  end
33
38
 
34
- def start_roma
39
+ def start_roma conf='config4test.rb'
35
40
  sh = Shell.new
36
41
  sh.transact do
37
42
  Dir.glob("localhost_1121?.*").each{|f| rm f }
38
43
  end
39
- FileUtils.rm_rf("localhost_11211")
40
- FileUtils.rm_rf("localhost_11212")
44
+ FileUtils.rm_rf("#{Roma::Config::STORAGE_PATH}/localhost_11211")
45
+ FileUtils.rm_rf("#{Roma::Config::STORAGE_PATH}/localhost_11212")
41
46
  sleep 0.1
42
47
 
43
48
  sh.system(ruby_path, mkroute_path,
44
49
  "localhost_11211","localhost_11212",
45
50
  "-d","3",
46
51
  "--enabled_repeathost")
47
- sleep 0.1
48
- sh.system(ruby_path,romad_path,"localhost","-p","11211","-d","--verbose")
49
- sh.system(ruby_path,romad_path,"localhost","-p","11212","-d","--verbose")
50
- sleep 0.5
52
+ sleep 0.2
53
+ do_command_romad conf
54
+ sleep 1
55
+ end
56
+
57
+ def do_command_romad conf
58
+ sh = Shell.new
59
+ sh.system(ruby_path,romad_path,"localhost","-p","11211","-d","--verbose",
60
+ "--disabled_cmd_protect","--config","#{server_test_dir}/#{conf}")
61
+ sh.system(ruby_path,romad_path,"localhost","-p","11212","-d","--verbose",
62
+ "--disabled_cmd_protect","--config","#{server_test_dir}/#{conf}")
51
63
  end
52
64
 
53
65
  def stop_roma
@@ -59,6 +71,7 @@ module RomaTestUtils
59
71
  conn.gets
60
72
  conn.close
61
73
  end
74
+ Roma::Client::ConPool.instance.close_all
62
75
  rescue =>e
63
76
  puts "#{e} #{$@}"
64
77
  end
@@ -5,10 +5,11 @@ require 'pathname'
5
5
 
6
6
  base_path = Pathname(__FILE__).dirname.parent.parent.expand_path
7
7
  $LOAD_PATH.unshift("#{base_path}/server/lib")
8
- $LOAD_PATH.unshift("#{base_path}/client/lib")
9
- $LOAD_PATH.unshift("#{base_path}/commons/lib")
10
8
  $LOAD_PATH.unshift("#{base_path}/server/test")
11
9
 
10
+ client_base_path = Pathname(__FILE__).dirname.parent.parent.parent.parent.expand_path
11
+ $LOAD_PATH.unshift("#{client_base_path}/roma-ruby-client/lib")
12
+
12
13
  require 'roma-test-utils'
13
14
 
14
15
  Dir["#{base_path}/server/test/t_*.rb"].each do |test_file|
@@ -0,0 +1,37 @@
1
+ require 'roma/storage/basic_storage'
2
+
3
+ module Roma
4
+ module Storage
5
+
6
+ class Dummy
7
+ def put(k,v)
8
+ raise StorageException, "error:get"
9
+ end
10
+ def get(k)
11
+ raise StorageException, "error:get"
12
+ end
13
+ def out(k)
14
+ true
15
+ end
16
+ def rnum
17
+ 0
18
+ end
19
+ def each
20
+ end
21
+ end
22
+
23
+ class StorageErrorStorage < BasicStorage
24
+
25
+ def opendb
26
+ create_div_hash
27
+ @divnum.times{ |i|
28
+ @hdb[i] = Dummy.new
29
+ }
30
+ end
31
+
32
+ def close_db(hdb); end
33
+
34
+ end # class StorageErrorStorage
35
+
36
+ end # module Storage
37
+ end # module Roma
@@ -0,0 +1,326 @@
1
+ #!/usr/bin/env ruby
2
+ require 'roma/command/command_definition'
3
+ require 'digest/sha1'
4
+ require 'test/unit'
5
+
6
+ module CommandModuleTest1
7
+ include Roma::Command::Definition
8
+
9
+ def_command_with_relay :balse do |s|
10
+ command_argument_validation_num s, 3
11
+ case s[2]
12
+ when 'ex_runtime'
13
+ raise s[1]
14
+ when 'ex_client'
15
+ raise Roma::Command::Definition::ClientErrorException, s[1]
16
+ when 'ex_server'
17
+ raise Roma::Command::Definition::ServerErrorException, s[1]
18
+ end
19
+ s
20
+ end
21
+
22
+ def_read_command_with_key :rget, :no_forward do |ctx|
23
+ ctx
24
+ end
25
+
26
+ def_write_command_with_key :wget, :no_forward do |ctx|
27
+ ctx
28
+ end
29
+
30
+ def_command_with_key :get, :no_forward do |ctx|
31
+ case ctx.argv[2]
32
+ when 'ex_runtime'
33
+ raise ctx.argv[1]
34
+ when 'ex_client'
35
+ raise Roma::Command::Definition::ClientErrorException, ctx.argv[1]
36
+ when 'ex_server'
37
+ raise Roma::Command::Definition::ServerErrorException, ctx.argv[1]
38
+ end
39
+ ctx
40
+ end
41
+
42
+ def_write_command_with_key_value :wset, 4, :no_forward do |ctx|
43
+ ctx
44
+ end
45
+
46
+ def_read_command_with_key_value :rset, 4, :no_forward do |ctx|
47
+ ctx
48
+ end
49
+
50
+ def_command_with_key_value :set, 4, :no_forward do |ctx|
51
+ case ctx.argv[2]
52
+ when 'ex_runtime'
53
+ raise ctx.argv[1]
54
+ when 'ex_client'
55
+ raise Roma::Command::Definition::ClientErrorException, ctx.argv[1]
56
+ when 'ex_server'
57
+ raise Roma::Command::Definition::ServerErrorException, ctx.argv[1]
58
+ end
59
+ ctx
60
+ end
61
+ end
62
+
63
+ module CommandModuleTest2
64
+ include Roma::Command::Definition
65
+
66
+ def_command_with_relay :runtimeexception do |s|
67
+ raise
68
+ end
69
+ end
70
+
71
+ module CommandModuleTest3
72
+ include Roma::Command::Definition
73
+
74
+ def_command_with_relay :balse do |s|
75
+ "override"
76
+ end
77
+ end
78
+
79
+ class DefCmdTest
80
+ include Roma::Command::Definition
81
+ include CommandModuleTest1
82
+ include CommandModuleTest2
83
+
84
+ #
85
+ # define stub for test
86
+ #
87
+
88
+ class RtStub
89
+ attr_reader :hbits
90
+
91
+ def initialize
92
+ @hbits = 10
93
+ end
94
+
95
+ def get_vnode_id(d) 1 end
96
+ def search_nodes_for_write(vn) ['roma0','roma1'] end
97
+ end
98
+
99
+ class LogStub
100
+ def warn str
101
+ end
102
+ end
103
+
104
+ class StorageStub
105
+ def get_raw(*arg)
106
+ nil
107
+ end
108
+ end
109
+
110
+ def initialize
111
+ @stats = Struct.new(:ap_str).new(:ap_str)
112
+ @rttable = RtStub.new
113
+ @defhash = 'roma'
114
+ @log = LogStub.new
115
+ @storages = Hash.new(StorageStub.new)
116
+ end
117
+
118
+ def send_data str
119
+ str
120
+ end
121
+
122
+ def broadcast_cmd str
123
+ {:broadcast_cmd=>str}
124
+ end
125
+
126
+ def read_bytes n
127
+ ret = 'a'
128
+ (n - 1).times{ ret += ret[-1].succ }
129
+ ret
130
+ end
131
+
132
+ def command_argument_validation_num s, num
133
+ raise ClientErrorException, "number of arguments (#{s.length - 1} for #{num - 1})" if s.length != num
134
+ end
135
+ end
136
+
137
+ class DefineCommandTest < Test::Unit::TestCase
138
+
139
+ def setup
140
+ @obj = DefCmdTest.new
141
+ end
142
+
143
+ def teardown
144
+ end
145
+
146
+ def test_defcmd
147
+ # normal case
148
+ res = @obj.ev_balse ['balse','arg1','arg2']
149
+ res = eval res.chomp
150
+ assert_equal ['balse','arg1','arg2'], res[:ap_str]
151
+ assert_equal "rbalse arg1 arg2\r\n", res[:broadcast_cmd]
152
+
153
+ res = @obj.ev_rbalse ['balse','arg1','arg2']
154
+ res = eval res.chomp
155
+ assert_equal ['balse','arg1','arg2'], res
156
+
157
+ # case of argument error
158
+ res = @obj.ev_balse ['balse','arg1']
159
+ assert_equal "CLIENT_ERROR number of arguments (1 for 2)\r\n", res
160
+ res = @obj.ev_balse ['balse','arg1', 'arg2', 'arg3']
161
+ assert_equal "CLIENT_ERROR number of arguments (3 for 2)\r\n", res
162
+
163
+ # case of exception occur
164
+ assert_raise RuntimeError do
165
+ res = @obj.ev_balse ['balse','arg1','ex_runtime']
166
+ end
167
+ res = @obj.ev_balse ['balse','arg1','ex_client']
168
+ assert_equal "CLIENT_ERROR arg1\r\n", res
169
+ res = @obj.ev_balse ['balse','arg2','ex_server']
170
+ assert_equal "SERVER_ERROR arg2\r\n", res
171
+ end
172
+
173
+ def test_defcmd2
174
+ # define a command in DefCmdTest class is not define yet
175
+ DefCmdTest.class_eval do
176
+ def_command_with_relay :balse2 do |s|
177
+ "#{s.join(' ')} #{@stats.ap_str}"
178
+ end
179
+ end
180
+ assert true
181
+
182
+ # define the duplicated command in DefCmdTest scope
183
+ assert_raise RuntimeError do
184
+ DefCmdTest.class_eval do
185
+ def_command_with_relay :balse do |s|
186
+ "#{s.join(' ')} #{@stats.ap_str}"
187
+ end
188
+ end
189
+ end
190
+
191
+ # define the duplicated command in CommandModuleTest3 scope
192
+ # RuntimeError is nothing to occur
193
+ DefCmdTest.class_eval do
194
+ include CommandModuleTest3
195
+ end
196
+
197
+ res = @obj.ev_balse ['balse','arg1','arg2']
198
+ robj = eval res.chomp # String -> Hash
199
+ assert_equal "override", robj[:ap_str]
200
+ assert_equal "rbalse arg1 arg2\r\n", robj[:broadcast_cmd]
201
+
202
+ res = @obj.ev_rbalse ['balse','arg1','arg2']
203
+ assert_equal "override\r\n", res
204
+
205
+ # test for exception occured in a command
206
+ assert_raise RuntimeError do
207
+ @obj.ev_runtimeexception ['balse']
208
+ end
209
+ end
210
+
211
+ def test_defcmd_k
212
+ # normal case
213
+ ctx = @obj.ev_get ['get','arg1']
214
+ assert_equal ['get','arg1'], ctx.argv
215
+ assert_equal 'arg1', ctx.params.key
216
+ assert_equal 'roma', ctx.params.hash_name
217
+ assert_equal Digest::SHA1.hexdigest('arg1').hex % 10, ctx.params.digest
218
+ assert_equal 1, ctx.params.vn
219
+ assert_equal ['roma0','roma1'], ctx.params.nodes
220
+
221
+ ctx = @obj.ev_get ['get',"arg2\eruby"]
222
+ assert_equal ['get',"arg2\eruby"], ctx.argv
223
+ assert_equal 'arg2', ctx.params.key
224
+ assert_equal 'ruby', ctx.params.hash_name
225
+ assert_equal 1, ctx.params.vn
226
+ assert_equal Digest::SHA1.hexdigest('arg2').hex % 10, ctx.params.digest
227
+ assert_equal ['roma0','roma1'], ctx.params.nodes
228
+
229
+ # case of argument error
230
+ res = @obj.ev_get ['get']
231
+ assert_equal "CLIENT_ERROR dose not find key\r\n", res
232
+ res = @obj.ev_get []
233
+ assert_equal "CLIENT_ERROR dose not find key\r\n", res
234
+
235
+ # case of exception occur
236
+ assert_raise RuntimeError do
237
+ res = @obj.ev_get ['get','arg1','ex_runtime']
238
+ end
239
+ res = @obj.ev_get ['get','arg1','ex_client']
240
+ assert_equal "CLIENT_ERROR arg1\r\n", res
241
+ res = @obj.ev_get ['get','arg2','ex_server']
242
+ assert_equal "SERVER_ERROR arg2\r\n", res
243
+ end
244
+
245
+ def test_defcmd_kv
246
+ # normal case
247
+ ctx = @obj.ev_set ['set','arg1', '0', '0', '5']
248
+ assert_equal ['set','arg1', '0', '0', '5'], ctx.argv
249
+ assert_equal 'arg1', ctx.params.key
250
+ assert_equal 'roma', ctx.params.hash_name
251
+ assert_equal Digest::SHA1.hexdigest('arg1').hex % 10, ctx.params.digest
252
+ assert_equal 1, ctx.params.vn
253
+ assert_equal ['roma0','roma1'], ctx.params.nodes
254
+ assert_equal 'abcde', ctx.params.value
255
+
256
+ ctx = @obj.ev_set ['set',"arg2\eruby", '0', '0', '5']
257
+ assert_equal ['set',"arg2\eruby", '0', '0', '5'], ctx.argv
258
+ assert_equal 'arg2', ctx.params.key
259
+ assert_equal 'ruby', ctx.params.hash_name
260
+ assert_equal Digest::SHA1.hexdigest('arg2').hex % 10, ctx.params.digest
261
+ assert_equal 1, ctx.params.vn
262
+ assert_equal ['roma0','roma1'], ctx.params.nodes
263
+ assert_equal 'abcde', ctx.params.value
264
+
265
+ # case of argument error
266
+ res = @obj.ev_set ['set']
267
+ assert_equal "CLIENT_ERROR dose not find key\r\n", res
268
+ res = @obj.ev_set []
269
+ assert_equal "CLIENT_ERROR dose not find key\r\n", res
270
+
271
+ # case of exception occur
272
+ assert_raise RuntimeError do
273
+ res = @obj.ev_set ['set','arg1','ex_runtime']
274
+ end
275
+ res = @obj.ev_set ['set','arg1','ex_client']
276
+ assert_equal "CLIENT_ERROR arg1\r\n", res
277
+ res = @obj.ev_set ['set','arg2','ex_server']
278
+ assert_equal "SERVER_ERROR arg2\r\n", res
279
+ end
280
+ end
281
+
282
+ class DefCmdTestNoHash < DefCmdTest
283
+ def initialize
284
+ super
285
+ @storages = {}
286
+ end
287
+ end
288
+
289
+ class DefineCommandNoHashTest < Test::Unit::TestCase
290
+ def setup
291
+ @obj = DefCmdTestNoHash.new
292
+ end
293
+
294
+ def teardown
295
+ end
296
+
297
+ def test_rcwk
298
+ ret = @obj.ev_rget ['get',"arg1\eno_hash_name"]
299
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
300
+ end
301
+
302
+ def test_wcwk
303
+ ret = @obj.ev_wget ['get',"arg1\eno_hash_name"]
304
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
305
+ end
306
+
307
+ def test_cwk
308
+ ret = @obj.ev_get ['get',"arg1\eno_hash_name"]
309
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
310
+ end
311
+
312
+ def test_rcwkv
313
+ ret = @obj.ev_rset ['set',"arg1\eno_hash_name", '0', '0', '5']
314
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
315
+ end
316
+
317
+ def test_wcwkv
318
+ ret = @obj.ev_wset ['set',"arg1\eno_hash_name", '0', '0', '5']
319
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
320
+ end
321
+
322
+ def test_cwkv
323
+ ret = @obj.ev_set ['set',"arg1\eno_hash_name", '0', '0', '5']
324
+ assert_equal "SERVER_ERROR no_hash_name dose not exists.\r\n", ret
325
+ end
326
+ end