roma 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/LICENSE.rdoc +675 -0
  2. data/README.rdoc +0 -0
  3. data/Rakefile +70 -0
  4. data/bin/mkrecent +7 -0
  5. data/bin/mkroute +7 -0
  6. data/bin/recoverlost +8 -0
  7. data/bin/recoverlost_alist +8 -0
  8. data/bin/romad +7 -0
  9. data/bin/sample_watcher +8 -0
  10. data/bin/sample_watcher2 +8 -0
  11. data/bin/simple_bench +8 -0
  12. data/bin/ssroute +7 -0
  13. data/bin/tribunus +7 -0
  14. data/lib/roma/async_process.rb +696 -0
  15. data/lib/roma/command/bg_command_receiver.rb +188 -0
  16. data/lib/roma/command/mh_command_receiver.rb +117 -0
  17. data/lib/roma/command/receiver.rb +287 -0
  18. data/lib/roma/command/rt_command_receiver.rb +147 -0
  19. data/lib/roma/command/st_command_receiver.rb +564 -0
  20. data/lib/roma/command/util_command_receiver.rb +67 -0
  21. data/lib/roma/command/vn_command_receiver.rb +143 -0
  22. data/lib/roma/command_plugin.rb +11 -0
  23. data/lib/roma/config.rb +64 -0
  24. data/lib/roma/event/con_pool.rb +140 -0
  25. data/lib/roma/event/handler.rb +159 -0
  26. data/lib/roma/plugin/plugin_alist.rb +1572 -0
  27. data/lib/roma/plugin/plugin_debug.rb +19 -0
  28. data/lib/roma/plugin/plugin_test.rb +14 -0
  29. data/lib/roma/romad.rb +582 -0
  30. data/lib/roma/routing/cb_rttable.rb +326 -0
  31. data/lib/roma/routing/merkle_tree.rb +54 -0
  32. data/lib/roma/routing/rttable.rb +148 -0
  33. data/lib/roma/stats.rb +112 -0
  34. data/lib/roma/storage/basic_storage.rb +510 -0
  35. data/lib/roma/storage/dbm_storage.rb +80 -0
  36. data/lib/roma/storage/dummy_storage.rb +44 -0
  37. data/lib/roma/storage/rh_storage.rb +35 -0
  38. data/lib/roma/storage/sqlite3_storage.rb +73 -0
  39. data/lib/roma/storage/tc_storage.rb +133 -0
  40. data/lib/roma/tools/mkrecent.rb +138 -0
  41. data/lib/roma/tools/mkroute.rb +52 -0
  42. data/lib/roma/tools/recoverlost.rb +9 -0
  43. data/lib/roma/tools/recoverlost_alist.rb +9 -0
  44. data/lib/roma/tools/recoverlost_lib.rb +217 -0
  45. data/lib/roma/tools/sample_watcher.rb +38 -0
  46. data/lib/roma/tools/sample_watcher2.rb +38 -0
  47. data/lib/roma/tools/simple_bench.rb +57 -0
  48. data/lib/roma/tools/ssroute.rb +23 -0
  49. data/lib/roma/tools/tribunus.rb +299 -0
  50. data/lib/roma/version.rb +4 -0
  51. data/lib/roma/write_behind.rb +179 -0
  52. data/test/rcirb.rb +16 -0
  53. data/test/roma-test-utils.rb +65 -0
  54. data/test/run-test.rb +16 -0
  55. data/test/t_cpdata.rb +277 -0
  56. data/test/t_listplugin.rb +592 -0
  57. data/test/t_rclient.rb +318 -0
  58. data/test/t_routing_data.rb +100 -0
  59. data/test/t_storage.rb +644 -0
  60. data/test/t_writebehind.rb +200 -0
  61. metadata +134 -0
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ require 'date'
3
+ require 'roma/client/rclient'
4
+
5
+ @@cnt=0
6
+ @@tmax=0
7
+ @@tmin=100
8
+
9
+ Thread.new {
10
+ sleep_time=10
11
+ while(true)
12
+ sleep sleep_time
13
+ printf("qps=%d max=%f min=%f ave=%f\n",@@cnt/sleep_time,@@tmax,@@tmin,sleep_time/@@cnt.to_f)
14
+ @@cnt=0
15
+ @@tmax=0
16
+ @@tmin=100
17
+ end
18
+ }
19
+
20
+ def random_rquest_sender(ini_nodes)
21
+ rc=Roma::Client::RomaClient.new(ini_nodes)
22
+
23
+ n=10000
24
+ loop{
25
+ i=rand(n)
26
+ ts = DateTime.now
27
+ case rand(3)
28
+ when 0
29
+ res=rc.set(i.to_s,'hoge'+i.to_s)
30
+ puts "set k=#{i} #{res}" if res==nil || res.chomp != 'STORED'
31
+ when 1
32
+ res=rc.get(i.to_s)
33
+ puts "get k=#{i} #{res}" if res == :error
34
+ when 2
35
+ res=rc.delete(i.to_s)
36
+ puts "del k=#{i} #{res}" if res != 'DELETED' && res != 'NOT_FOUND'
37
+ end
38
+ t=(DateTime.now - ts).to_f * 86400.0
39
+ @@tmax=t if t > @@tmax
40
+ @@tmin=t if t < @@tmin
41
+ @@cnt+=1
42
+ }
43
+ end
44
+
45
+ if ARGV.length == 0
46
+ STDERR.puts "usage:simple_bench addr:port"
47
+ exit
48
+ end
49
+
50
+ tn=10
51
+ t=[]
52
+ tn.times{
53
+ t << Thread.new{
54
+ random_rquest_sender(ARGV)
55
+ }
56
+ }
57
+
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # usage:ssroute address_port
5
+ #
6
+ require 'roma/routing/routing_data'
7
+
8
+ if ARGV.length!=1
9
+ puts "usage:ssroute address:port"
10
+ exit
11
+ end
12
+
13
+ ap = ARGV[0].sub(':','_')
14
+
15
+ begin
16
+ if Roma::Routing::RoutingData::snapshot("#{ap}.route")
17
+ puts "succeed"
18
+ else
19
+ puts "Routing-log file dose not found."
20
+ end
21
+ rescue =>e
22
+ puts "error:#{e}"
23
+ end
@@ -0,0 +1,299 @@
1
+ #!/usr/bin/ruby
2
+ # encoding: utf-8
3
+ require 'socket'
4
+ require 'ipaddr'
5
+ require 'optparse'
6
+ UDP_PORT=14329
7
+ MULTICAST_ADDR="225.0.0.123"
8
+ ROMA_LOAD_PATH=File.expand_path(File.join(File.dirname(__FILE__),"../.."))
9
+ RUBY_COMMAND_OPTIONS=["-I",ROMA_LOAD_PATH]
10
+ ROMAD_OPTIONS=["--enabled_repeathost"]
11
+ bin_dir=File.expand_path(File.join(File.dirname(__FILE__),"../../../bin"))
12
+ ROMAD_PATH= File.expand_path(File.join(bin_dir,"romad"))
13
+ MKROUTE_PATH= File.expand_path(File.join(bin_dir,"mkroute"))
14
+
15
+ ROMAD_WORK_DIR='.'
16
+ class Tribunus
17
+ #protocol
18
+ #
19
+ #update:<reply_ocunt>: <romad_hostname> [<romad_port> ...]
20
+
21
+ RomadHost=Struct.new(:hostname,:ports,:updated_at)
22
+ def log(obj)
23
+ if @verbose
24
+ if obj.is_a? String
25
+ $stderr.puts obj
26
+ else
27
+ $stderr.puts obj.inspect
28
+ end
29
+ end
30
+ end
31
+ private :log
32
+
33
+ def initialize(romad_hostname,romad_ports,options={})
34
+ @multi_addr=options[:multicast_addr]||MULTICAST_ADDR
35
+ @port=options[:udp_port]||UDP_PORT
36
+ @romad_work_dir=options[:romad_work_dir]||ROMAD_WORK_DIR
37
+ @ruby_command_name=options[:ruby_command_name]||"ruby"
38
+ @verbose=options[:verbose]
39
+ log [:initalized,@multi_addr,@port,@romad_work_dir,@ruby_command_name]
40
+
41
+ @threads=[]
42
+ @romads={} #port => pid
43
+ @local_romad_host=RomadHost.new(romad_hostname,romad_ports,nil)
44
+
45
+ @mutex=Mutex.new
46
+ @remote_servers={} #ipaddr => RomadHost
47
+
48
+ end
49
+
50
+ def from_remote?(ipaddr)
51
+ from_remote= !Socket.ip_address_list.any?{|addr|addr.ip_address==ipaddr}
52
+ end
53
+ private :from_remote?
54
+
55
+
56
+ def spawn_new_roma_ring
57
+ spawn_romads(nil,nil)
58
+ end
59
+
60
+
61
+ def spawn_romads(remote_host,remote_port)
62
+ nodes=@local_romad_host.ports.map do|port|
63
+ "#{@local_romad_host.hostname}_#{port}"
64
+ end
65
+ nodes << "#{remote_host}_#{remote_port}" if remote_host
66
+ pid=Process.spawn(@ruby_command_name,*RUBY_COMMAND_OPTIONS,MKROUTE_PATH,*nodes,:chdir=>@romad_work_dir)
67
+ if(Process.waitpid2(pid)[1].to_i!=0)
68
+ raise "failed to make route"
69
+ end
70
+
71
+ @local_romad_host.ports.each do|port|
72
+ pid=Process.spawn(@ruby_command_name,*RUBY_COMMAND_OPTIONS,ROMAD_PATH,*ROMAD_OPTIONS,"-p",port.to_s,@local_romad_host.hostname, :chdir=>@romad_work_dir)
73
+ @romads[port]=pid
74
+ end
75
+ end
76
+
77
+ def spawn_romads_join(remote_host,remote_port)
78
+ @local_romad_host.ports.map do|port|
79
+ spawn_romad_join(port,remote_host,remote_port)
80
+ end
81
+ end
82
+
83
+
84
+ def spawn_romad_join(port,remote_host,remote_port)
85
+ pid=Process.spawn(@ruby_command_name,*RUBY_COMMAND_OPTIONS,ROMAD_PATH,*ROMAD_OPTIONS,"-p",port.to_s,@local_romad_host.hostname,"-j","#{remote_host}_#{remote_port}",:chdir=>@romad_work_dir)
86
+ @romads[port]=pid
87
+ end
88
+
89
+
90
+ def receive_update_command(ipaddr,reply_count,params)
91
+ param_ary=params.strip.split(/\s+/)
92
+ unless param_ary.empty?
93
+ hostname=param_ary[0]
94
+ ports=param_ary[1..-1].map{|port| port.to_i}
95
+ rhost=RomadHost.new(hostname,ports,Time.now)
96
+ @remote_servers[ipaddr]=rhost
97
+ if reply_count>0
98
+ unicast(ipaddr,update_message(reply_count-1))
99
+ end
100
+ end
101
+ end
102
+
103
+ def run_command(ipaddr,msg)
104
+ match_data=/\A(.*):(\d+):(.*)/.match(msg)
105
+ if(match_data)
106
+ command=match_data[1]
107
+ reply_count=match_data[2].to_i
108
+ rest=match_data[3]
109
+ case command
110
+ when "update"
111
+ receive_update_command(ipaddr,reply_count,rest)
112
+ end
113
+ end
114
+ end
115
+ private :run_command
116
+
117
+ def update_message(reply_count,initial=false)
118
+ msg="update:#{reply_count}: #{@local_romad_host.hostname}"
119
+ if !initial && !@romads.keys.empty?
120
+ msg+=" "
121
+ msg+= @romads.keys.join(' ')
122
+ end
123
+ log [:msg, msg,@romads]
124
+ msg
125
+ end
126
+
127
+ def server_loop
128
+ sock=UDPSocket.new
129
+ sock.bind('0.0.0.0',@port)
130
+ sock.setsockopt(Socket::IPPROTO_IP, Socket::IP_ADD_MEMBERSHIP, IPAddr.new(MULTICAST_ADDR).hton+IPAddr.new('0.0.0.0').hton)
131
+ log 'start_listen'
132
+ Socket.udp_server_loop_on([sock]) do|msg,msg_src|
133
+ log [:received ,msg,msg_src]
134
+ if from_remote?(msg_src.remote_address.ip_address)
135
+ run_command(msg_src.remote_address.ip_address,msg)
136
+ end
137
+ end
138
+ end
139
+
140
+ HEARTBEAT_SECONDS=300
141
+ HEARTBEAT_LOOP_INTERVAL=50
142
+ TIMEOUT_SECONDS=600
143
+
144
+
145
+ def heartbeat_loop
146
+ loop do
147
+ delete_ipaddrs=[]
148
+ @remote_servers.each do|ipaddr,host|
149
+
150
+ if host.updated_at+TIMEOUT_SECONDS < Time.now
151
+ delete_ipaddrs << ipaddr
152
+ elsif host.updated_at+HEARTBEAT_SECONDS < Time.now
153
+ unicast(ipaddr,update_message(0))
154
+ elsif host.ports.empty?
155
+ unicast(ipaddr,update_message(1))
156
+ end
157
+ end
158
+
159
+ @mutex.synchronize do
160
+ delete_ipaddrs.each do|ipaddr|
161
+ @remote_servers.delete(ipaddr)
162
+ end
163
+ end
164
+
165
+
166
+
167
+
168
+ sleep(HEARTBEAT_LOOP_INTERVAL)
169
+ end
170
+ rescue =>e
171
+ p e
172
+ end
173
+
174
+ def set_trap
175
+ [:INT,:TERM,:HUP].each do|sig|
176
+ Signal.trap(sig){ Process.kill(sig,*@romads.values);exit(1) }
177
+ end
178
+ end
179
+
180
+ def prepare_to_start
181
+ set_trap
182
+ @threads << Thread.start{self.server_loop}
183
+ @threads << Thread.start{self.heartbeat_loop}
184
+ end
185
+ private :prepare_to_start
186
+
187
+ def start_new_ring
188
+ prepare_to_start
189
+ spawn_new_roma_ring
190
+ end
191
+
192
+ def choose_rhost
193
+ @remote_servers.each do|ipaddr,rhost|
194
+ unless rhost.ports.empty?
195
+ return rhost
196
+ end
197
+ end
198
+ nil
199
+ end
200
+ def start_join(host,port)
201
+ prepare_to_start
202
+ sleep(0.2)
203
+ spawn_romads_join(host,port)
204
+ end
205
+
206
+ def start_discover
207
+ prepare_to_start
208
+ sleep(0.2)
209
+ multicast(update_message(1,true))
210
+ 10.times{sleep(0.3)}
211
+ rhost=choose_rhost
212
+ if rhost
213
+ spawn_romads_join(rhost.hostname,rhost.ports.first)
214
+ else
215
+ $stderr.puts "no server responded"
216
+ exit 1
217
+ end
218
+
219
+ end
220
+
221
+ def join
222
+ @threads.each{|t|t.join}
223
+ end
224
+
225
+ def unicast(ipaddr,msg)
226
+ log [:message, ipaddr,msg]
227
+ s=UDPSocket.new
228
+ begin
229
+ s.connect(ipaddr,@port)
230
+ s.sendmsg(msg)
231
+ ensure
232
+ s.close
233
+ end
234
+ end
235
+
236
+ def multicast(msg)
237
+ unicast(@multi_addr,msg)
238
+ end
239
+ end
240
+
241
+ opt=OptionParser.new
242
+ conf={}
243
+ opt.on('-d','discover the node by multicast [default]') do|v|
244
+ conf[:mode]=:discover
245
+ end
246
+ opt.on('-c','craete new ring') do|v|
247
+ conf[:mode]=:new_ring
248
+ end
249
+ opt.on('-j HOST:PORT',/\A.+?[_:]\d+\Z/,'join the specified romad node') do|v|
250
+ conf[:mode]=:join
251
+ node=v.split(/[_:]/)
252
+ conf[:joining_node]=[node[0],node[1].to_i]
253
+ end
254
+
255
+ opt.on('-p UDP_PORT',/\A\d+\Z/,'the port for multicast') do|v|
256
+ conf[:udp_port]=v.to_i
257
+ end
258
+ opt.on('-w WORKING_DIR','the directory where romads run') do|v|
259
+ conf[:romad_work_dir]=v
260
+ end
261
+ opt.on('-m MULTICAST_ADDRESS',/\A\d+\.\d+\.\d+\.\d+\Z/,'the ip address for multicast') do|v|
262
+ conf[:multicast_addr]=v
263
+ end
264
+ opt.on('-r RUBY_COMMAND','name of ruby interpreter (default: "ruby")') do|v|
265
+ conf[:ruby_command_name]=v
266
+ end
267
+ opt.on('-v','--verbose') do|v|
268
+ conf[:verbose]=v
269
+ end
270
+ opt.banner += " hostname port_range"
271
+
272
+ opt.parse!(ARGV)
273
+
274
+ if ARGV.size!=2
275
+ puts opt.help
276
+ exit 1
277
+ end
278
+ hostname=ARGV[0]
279
+ port_ary=ARGV[1].split('-')
280
+ ports=(port_ary[0].to_i..port_ary[1].to_i).to_a
281
+ if ports.size < 2
282
+ puts 'less ports'
283
+ exit 1
284
+ end
285
+ if ports.size >100
286
+ puts 'too many ports'
287
+ exit 1
288
+ end
289
+
290
+ tri=Tribunus.new(hostname,ports,conf)
291
+ case conf[:mode]
292
+ when:new_ring
293
+ tri.start_new_ring
294
+ when :join
295
+ tri.start_join(conf[:joining_node][0],conf[:joining_node][1])
296
+ else
297
+ tri.start_discover
298
+ end
299
+ tri.join
@@ -0,0 +1,4 @@
1
+
2
+ module Roma
3
+ VERSION = "0.8.2"
4
+ end
@@ -0,0 +1,179 @@
1
+ require 'thread'
2
+ require 'roma/stats'
3
+
4
+ module Roma
5
+
6
+ module WriteBehind
7
+
8
+ class FileWriter
9
+
10
+ def initialize(path, shift_size, log)
11
+ @stats = Roma::Stats.instance
12
+ path.chop! if path[-1]=='/'
13
+ @path = path
14
+ @log = log
15
+ @fdh = {} # file handle hash
16
+ @fnh = {} # file name hash
17
+ @do_write = false
18
+ @shift_size = shift_size
19
+ @total_size = Hash.new(0)
20
+ @rottime = Time.now
21
+ end
22
+
23
+ def get_stat
24
+ ret = {}
25
+ ret['write-behind.path'] = File.expand_path(@path)
26
+ ret['write-behind.shift_size'] = @shift_size
27
+ ret['write-behind.do_write'] = @do_write
28
+ @fdh.each{|hname,fname|
29
+ ret["write-behind[#{hname}].path"] = File.expand_path(fname)
30
+ ret["write-behind[#{hname}].size"] = @total_size[hname]
31
+ }
32
+ ret
33
+ end
34
+
35
+ def write(hname, cmd, key, val)
36
+ @do_write = true
37
+ t = Time.now
38
+ if @total_size[hname] >= @shift_size || t >= @rottime
39
+ @do_write = false
40
+ rotate(hname)
41
+ end
42
+
43
+ fd = @fdh[hname]
44
+ unless fd
45
+ fd = openfile(hname)
46
+ @total_size[hname] = 0
47
+ end
48
+ klen = key.length
49
+ val = val.to_s
50
+ vlen = val.length
51
+ size = fd.write([t.to_i, cmd, klen, key, vlen, val].pack("NnNa#{klen}Na#{vlen}"))
52
+ @total_size[hname] += size
53
+ # @log.debug("WriteBehind:hname=#{hname} cmd=#{cmd} key=#{key} val=#{val} total_size=#{@total_size}")
54
+ ensure
55
+ @do_write = false
56
+ end
57
+
58
+ def rotate(hname)
59
+ @log.info("WriteBehind:rotate #{hname}")
60
+ fd_old = @fdh[hname]
61
+ unless fd_old
62
+ @log.info("WriteBehind:rotate #{hname} not opend")
63
+ return false
64
+ end
65
+ @fdh.delete(hname)
66
+ @fnh.delete(hname)
67
+ sleep 0.01 while @do_write
68
+ fd_old.close
69
+ @log.info("WriteBehind:rotate sccseed")
70
+ true
71
+ end
72
+
73
+ def openfile(hname)
74
+ t = Time.now
75
+ path = "#{@path}/#{@stats.ap_str}/#{hname}/#{t.strftime('%Y%m%d')}"
76
+ mkdir(path)
77
+ # set a next rotation time
78
+ @rottime = Time.local(t.year,t.month,t.day,0,0,0) + 24 * 60 * 60
79
+
80
+ max = -1
81
+ Dir::glob("#{path}/*.wb").each{|f|
82
+ if /\D(\d+).wb$/ =~ f
83
+ max = $1.to_i if $1.to_i > max
84
+ end
85
+ }
86
+ fname = "#{path}/#{max + 1}.wb"
87
+ fd = open(fname,'wb')
88
+ @fnh[hname] = fname
89
+ @fdh[hname] = fd
90
+ end
91
+
92
+ def wb_get_path(hname)
93
+ File.expand_path("#{@path}/#{@stats.ap_str}/#{hname}")
94
+ end
95
+
96
+ def get_current_file_path(hname)
97
+ @log.info("WriteBehind:get_current_file_path #{hname}")
98
+ unless @fnh[hname]
99
+ @log.info("WriteBehind:get_current_file_path #{hname} not opend")
100
+ return nil
101
+ end
102
+ File.expand_path("#{@fnh[hname]}")
103
+ end
104
+
105
+ def close_all
106
+ @fdh.each_value{|fd| fd.close }
107
+ end
108
+
109
+ def mkdir(path)
110
+ pbuf = ''
111
+ path.split('/').each{|p|
112
+ pbuf << p
113
+ begin
114
+ Dir::mkdir(pbuf) unless File.exist?(pbuf)
115
+ rescue
116
+ end
117
+ pbuf << '/'
118
+ }
119
+ end
120
+
121
+ end # class FileWriter
122
+
123
+ end # module WriteBehind
124
+
125
+ module WriteBehindProcess
126
+
127
+ @@wb_queue = Queue.new
128
+
129
+ def self.push(hname, cmd, key, val)
130
+ @@wb_queue.push([hname, cmd, key, val])
131
+ end
132
+
133
+ def start_wb_process
134
+ @wb_thread = Thread.new{
135
+ wb_process_loop
136
+ }
137
+ rescue =>e
138
+ @log.error("#{e}\n#{$@}")
139
+ end
140
+
141
+ def stop_wb_process
142
+ until @@wb_queue.empty?
143
+ sleep 0.01
144
+ end
145
+ @wb_thread.exit
146
+ @wb_writer.close_all
147
+ end
148
+
149
+ def wb_rotate(hname)
150
+ @wb_writer.rotate(hname)
151
+ end
152
+
153
+ def wb_get_path(hname)
154
+ @wb_writer.wb_get_path(hname)
155
+ end
156
+
157
+ def wb_get_current_file_path(hname)
158
+ @wb_writer.get_current_file_path(hname)
159
+ end
160
+
161
+ def wb_get_stat
162
+ @wb_writer.get_stat
163
+ end
164
+
165
+ def wb_process_loop
166
+ loop {
167
+ while dat = @@wb_queue.pop
168
+ @wb_writer.write(dat[0], dat[1], dat[2], dat[3])
169
+ end
170
+ }
171
+ rescue =>e
172
+ @log.error("#{e}\n#{$@}")
173
+ retry
174
+ end
175
+ private :wb_process_loop
176
+
177
+ end # module WriteBehindProcess
178
+
179
+ end # module Roma
data/test/rcirb.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'pp'
5
+ require 'irb'
6
+
7
+ path = File.dirname(File.expand_path($PROGRAM_NAME))
8
+ $LOAD_PATH << path + "/../lib"
9
+ $LOAD_PATH << path + "/../../commons/lib"
10
+ $LOAD_PATH << path + "/../../client/lib"
11
+
12
+ require 'roma/client/rclient'
13
+
14
+ $rc=Roma::Client::RomaClient.new(['roma0_11211'])
15
+
16
+ IRB.start
@@ -0,0 +1,65 @@
1
+ require 'shell'
2
+
3
+ require 'pathname'
4
+ require 'fileutils'
5
+ require 'rbconfig'
6
+
7
+ module RomaTestUtils
8
+ module_function
9
+ def base_dir
10
+ Pathname(__FILE__).dirname.parent.parent.expand_path
11
+ end
12
+
13
+ def server_base_dir
14
+ base_dir + "server"
15
+ end
16
+
17
+ def server_bin_dir
18
+ server_base_dir + "bin"
19
+ end
20
+
21
+ def mkroute_path
22
+ (server_bin_dir + "mkroute").to_s
23
+ end
24
+
25
+ def romad_path
26
+ (server_bin_dir + "romad").to_s
27
+ end
28
+
29
+ def ruby_path
30
+ File.join(RbConfig::CONFIG["bindir"],
31
+ RbConfig::CONFIG["ruby_install_name"])
32
+ end
33
+
34
+ def start_roma
35
+ sh = Shell.new
36
+ sh.transact do
37
+ Dir.glob("localhost_1121?.*").each{|f| rm f }
38
+ end
39
+ FileUtils.rm_rf("localhost_11211")
40
+ FileUtils.rm_rf("localhost_11212")
41
+ sleep 0.1
42
+
43
+ sh.system(ruby_path, mkroute_path,
44
+ "localhost_11211","localhost_11212",
45
+ "-d","3",
46
+ "--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
51
+ end
52
+
53
+ def stop_roma
54
+ conn = Roma::Messaging::ConPool.instance.get_connection("localhost_11211")
55
+ if conn
56
+ conn.write "balse\r\n"
57
+ conn.gets
58
+ conn.write "yes\r\n"
59
+ conn.gets
60
+ conn.close
61
+ end
62
+ rescue =>e
63
+ puts "#{e} #{$@}"
64
+ end
65
+ end
data/test/run-test.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+ require 'pathname'
5
+
6
+ base_path = Pathname(__FILE__).dirname.parent.parent.expand_path
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
+ $LOAD_PATH.unshift("#{base_path}/server/test")
11
+
12
+ require 'roma-test-utils'
13
+
14
+ Dir["#{base_path}/server/test/t_*.rb"].each do |test_file|
15
+ require File.basename(test_file, '*.rb')
16
+ end