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,200 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'logger'
5
+ require 'roma/write_behind'
6
+
7
+ class FileWriterTest < Test::Unit::TestCase
8
+
9
+ def initialize(arg)
10
+ super(arg)
11
+ end
12
+
13
+ def setup
14
+ @stats = Roma::Stats.instance
15
+ @stats.address = 'roma0'
16
+ @stats.port = 11211
17
+
18
+ @log = Logger.new(StringIO.new)
19
+ @log.level = Logger::INFO
20
+ end
21
+
22
+ def teardown
23
+ system('rm -rf wb_test')
24
+ end
25
+
26
+ # 作成と write のテスト
27
+ def test_write
28
+ system('rm -rf wb_test')
29
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 1024 * 1024, @log)
30
+ path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
31
+
32
+ assert(!File.exist?("#{path}/0.wb"))
33
+ 100.times{|i|
34
+ fw.write('roma',i,"key-#{i}","val-#{i}")
35
+ }
36
+ assert(File.exist?("#{path}/0.wb"))
37
+ assert(!File.exist?("#{path}/1.wb"))
38
+
39
+ fw.rotate('roma')
40
+
41
+ i = 100
42
+ fw.write('roma',i,"key-#{i}","val-#{i}")
43
+ assert(File.exist?("#{path}/1.wb"))
44
+
45
+ fw.close_all
46
+
47
+ wb0 = read_wb("#{path}/0.wb")
48
+ assert(100,wb0.length )
49
+ wb0.each{|last, cmd, key, val|
50
+ assert_equal( "key-#{cmd}",key)
51
+ assert_equal( "val-#{cmd}",val)
52
+ }
53
+ wb1 = read_wb("#{path}/1.wb")
54
+ assert_equal(1,wb1.length )
55
+ end
56
+
57
+ # サイズによるローテーションのテスト
58
+ def test_rotation
59
+ system('rm -rf wb_test')
60
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 900, @log)
61
+ path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
62
+
63
+ 100.times{|i|
64
+ fw.write('roma',0,
65
+ sprintf("key-%04d",i),
66
+ sprintf("val-%04d",i))
67
+ }
68
+
69
+ assert(File.exist?("#{path}/0.wb"))
70
+ assert(File.exist?("#{path}/1.wb"))
71
+ assert(File.exist?("#{path}/2.wb"))
72
+ assert(File.exist?("#{path}/3.wb"))
73
+ assert(!File.exist?("#{path}/4.wb"))
74
+ end
75
+
76
+ # 時間によるローテーションのテスト
77
+ def test_rotation2
78
+ system('rm -rf wb_test')
79
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 1024 * 1024, @log)
80
+ path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
81
+
82
+ # インスタンス生成直後の rottime の時分秒usecは何かの値を持っている
83
+ rt = fw.instance_eval{ @rottime }
84
+ assert_not_equal(0, rt.hour + rt.min + rt.sec+ rt.usec)
85
+ # 初期化は今日の日付で行われる
86
+ assert_equal(Time.now.day, rt.day)
87
+ # ファイルは存在しない
88
+ assert(!File.exist?("#{path}/0.wb"))
89
+ fw.write('roma',1,"key","val")
90
+ # 何かを書き込むとオープンされ、そのタイミングで rottime が更新される
91
+ rt = fw.instance_eval{ @rottime }
92
+ # この時、日付以下は 0 となる
93
+ assert_equal(0, rt.hour + rt.min + rt.sec+ rt.usec)
94
+ # 日付は明日になる
95
+ assert_not_equal(Time.now.day, rt.day)
96
+ 10.times{|i|
97
+ fw.write('roma',i,"key-#{i}","val-#{i}")
98
+ }
99
+ # ファイルは1つ
100
+ assert(File.exist?("#{path}/0.wb"))
101
+ assert(!File.exist?("#{path}/1.wb"))
102
+
103
+ # ローテーションの時刻を強制的に今にする
104
+ fw.instance_eval{ @rottime=Time.now }
105
+ # rottime の変更を確認
106
+ assert_not_equal(rt, fw.instance_eval{ @rottime })
107
+ # 何かを書き込むとローテーションが発生する
108
+ fw.write('roma',1,"key","val")
109
+ assert(File.exist?("#{path}/1.wb"))
110
+ # テストは日をまたがないので rottime は元に戻る
111
+ assert_equal(rt, fw.instance_eval{ @rottime })
112
+ end
113
+
114
+ # 外部からローテーションするテスト
115
+ def test_rotation3
116
+ system('rm -rf wb_test')
117
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 1024 * 1024, @log)
118
+ path = "wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/"
119
+
120
+ # ファイルはない
121
+ assert(!File.exist?("#{path}/0.wb"))
122
+ 10.times{|i|
123
+ fw.write('roma',i,"key-#{i}","val-#{i}")
124
+ }
125
+ # ファイルは1つ
126
+ assert(File.exist?("#{path}/0.wb"))
127
+ assert(!File.exist?("#{path}/1.wb"))
128
+
129
+ fw.rotate('roma')
130
+ 10.times{|i|
131
+ fw.write('roma',i,"key-#{i}","val-#{i}")
132
+ }
133
+ # ファイルは2つ
134
+ assert(File.exist?("#{path}/0.wb"))
135
+ assert(File.exist?("#{path}/1.wb"))
136
+ assert(!File.exist?("#{path}/2.wb"))
137
+
138
+ # ローテーションの重複呼び出し
139
+ fw.rotate('roma')
140
+ fw.rotate('roma')
141
+ fw.rotate('roma')
142
+ # ファイルは2つで変化なし
143
+ assert(File.exist?("#{path}/0.wb"))
144
+ assert(File.exist?("#{path}/1.wb"))
145
+ assert(!File.exist?("#{path}/2.wb"))
146
+ 10.times{|i|
147
+ fw.write('roma',i,"key-#{i}","val-#{i}")
148
+ }
149
+ # ファイルは3つ
150
+ assert(File.exist?("#{path}/0.wb"))
151
+ assert(File.exist?("#{path}/1.wb"))
152
+ assert(File.exist?("#{path}/2.wb"))
153
+ assert(!File.exist?("#{path}/3.wb"))
154
+ end
155
+
156
+
157
+ def test_get_current_file_path
158
+ system('rm -rf wb_test')
159
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 900, @log)
160
+
161
+ assert_nil( fw.get_current_file_path('roma') )
162
+
163
+ fw.write('roma',0,"key","val")
164
+
165
+ path = File.expand_path("./wb_test/roma0_11211/roma/#{Time.now.strftime('%Y%m%d')}/")
166
+ assert_equal( File.join(path,"0.wb"), fw.get_current_file_path('roma'))
167
+
168
+ fw.rotate('roma')
169
+ assert_nil( fw.get_current_file_path('roma'))
170
+
171
+ fw.write('roma',0,"key","val")
172
+ assert_equal( File.join(path,"1.wb"), fw.get_current_file_path('roma') )
173
+ end
174
+
175
+ def test_get_path
176
+ system('rm -rf wb_test')
177
+ fw = Roma::WriteBehind::FileWriter.new("wb_test", 900, @log)
178
+ path = File.expand_path("./wb_test/roma0_11211/roma")
179
+ assert_equal( path, fw.wb_get_path('roma'))
180
+ end
181
+
182
+ private
183
+
184
+ def read_wb(fname)
185
+ ret = []
186
+ open(fname,'rb'){|f|
187
+ until(f.eof?)
188
+ b1 = f.read(10)
189
+ last, cmd, klen = b1.unpack('NnN')
190
+ key = f.read(klen)
191
+ b2 = f.read(4)
192
+ vlen = b2.unpack('N')[0]
193
+ val = f.read(vlen)
194
+ ret << [last,cmd,key,val]
195
+ end
196
+ }
197
+ ret
198
+ end
199
+
200
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: roma
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.2
5
+ platform: ruby
6
+ authors: []
7
+
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-19 00:00:00 +09:00
13
+ default_executable: romad
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: roma-commons
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: " ROMA server\n"
26
+ email:
27
+ executables:
28
+ - mkrecent
29
+ - mkroute
30
+ - tribunus
31
+ - simple_bench
32
+ - ssroute
33
+ - recoverlost_alist
34
+ - romad
35
+ - recoverlost
36
+ extensions: []
37
+
38
+ extra_rdoc_files:
39
+ - README.rdoc
40
+ files:
41
+ - Rakefile
42
+ - README.rdoc
43
+ - LICENSE.rdoc
44
+ - bin/mkrecent
45
+ - bin/mkroute
46
+ - bin/tribunus
47
+ - bin/simple_bench
48
+ - bin/sample_watcher
49
+ - bin/ssroute
50
+ - bin/recoverlost_alist
51
+ - bin/sample_watcher2
52
+ - bin/romad
53
+ - bin/recoverlost
54
+ - lib/roma/tools/mkrecent.rb
55
+ - lib/roma/tools/sample_watcher.rb
56
+ - lib/roma/tools/simple_bench.rb
57
+ - lib/roma/tools/recoverlost_alist.rb
58
+ - lib/roma/tools/mkroute.rb
59
+ - lib/roma/tools/ssroute.rb
60
+ - lib/roma/tools/tribunus.rb
61
+ - lib/roma/tools/sample_watcher2.rb
62
+ - lib/roma/tools/recoverlost_lib.rb
63
+ - lib/roma/tools/recoverlost.rb
64
+ - lib/roma/storage/rh_storage.rb
65
+ - lib/roma/storage/dummy_storage.rb
66
+ - lib/roma/storage/basic_storage.rb
67
+ - lib/roma/storage/sqlite3_storage.rb
68
+ - lib/roma/storage/dbm_storage.rb
69
+ - lib/roma/storage/tc_storage.rb
70
+ - lib/roma/command/st_command_receiver.rb
71
+ - lib/roma/command/vn_command_receiver.rb
72
+ - lib/roma/command/bg_command_receiver.rb
73
+ - lib/roma/command/rt_command_receiver.rb
74
+ - lib/roma/command/util_command_receiver.rb
75
+ - lib/roma/command/mh_command_receiver.rb
76
+ - lib/roma/command/receiver.rb
77
+ - lib/roma/write_behind.rb
78
+ - lib/roma/version.rb
79
+ - lib/roma/command_plugin.rb
80
+ - lib/roma/config.rb
81
+ - lib/roma/routing/merkle_tree.rb
82
+ - lib/roma/routing/rttable.rb
83
+ - lib/roma/routing/cb_rttable.rb
84
+ - lib/roma/plugin/plugin_test.rb
85
+ - lib/roma/plugin/plugin_debug.rb
86
+ - lib/roma/plugin/plugin_alist.rb
87
+ - lib/roma/event/con_pool.rb
88
+ - lib/roma/event/handler.rb
89
+ - lib/roma/romad.rb
90
+ - lib/roma/stats.rb
91
+ - lib/roma/async_process.rb
92
+ - test/rcirb.rb
93
+ - test/roma-test-utils.rb
94
+ - test/run-test.rb
95
+ - test/t_routing_data.rb
96
+ - test/t_writebehind.rb
97
+ - test/t_listplugin.rb
98
+ - test/t_cpdata.rb
99
+ - test/t_rclient.rb
100
+ - test/t_storage.rb
101
+ has_rdoc: true
102
+ homepage:
103
+ licenses: []
104
+
105
+ post_install_message:
106
+ rdoc_options:
107
+ - --line-numbers
108
+ - --inline-source
109
+ - --main
110
+ - README.rdoc
111
+ - -c UTF-8
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: "0"
119
+ version:
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: "0"
125
+ version:
126
+ requirements: []
127
+
128
+ rubyforge_project:
129
+ rubygems_version: 1.3.5
130
+ signing_key:
131
+ specification_version: 3
132
+ summary: ROMA server
133
+ test_files: []
134
+