rufus-tokyo 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGELOG.txt +6 -0
  3. data/Rakefile +91 -0
  4. data/doc/decision_table.numbers +0 -0
  5. data/lib/rufus/edo/README.txt +101 -0
  6. data/lib/rufus/edo/tabcore.rb +1 -3
  7. data/lib/rufus/tokyo.rb +1 -2
  8. data/lib/rufus/tokyo/cabinet/lib.rb +4 -7
  9. data/lib/rufus/tokyo/cabinet/table.rb +10 -13
  10. data/lib/rufus/tokyo/cabinet/util.rb +4 -1
  11. data/lib/rufus/tokyo/hmethods.rb +4 -4
  12. data/lib/rufus/tokyo/outlen.rb +5 -1
  13. data/lib/rufus/tokyo/tyrant/abstract.rb +8 -0
  14. data/lib/rufus/tokyo/tyrant/lib.rb +6 -6
  15. data/lib/rufus/tokyo/tyrant/table.rb +9 -1
  16. data/lib/rufus/tokyo/version.rb +32 -0
  17. data/rufus-tokyo.gemspec +135 -0
  18. data/spec/cabinet_btree_spec.rb +92 -0
  19. data/spec/cabinet_fixed_spec.rb +33 -0
  20. data/spec/cabinet_spec.rb +291 -0
  21. data/spec/cabinetconfig_spec.rb +82 -0
  22. data/spec/dystopia_core_spec.rb +124 -0
  23. data/spec/edo_cabinet_btree_spec.rb +123 -0
  24. data/spec/edo_cabinet_fixed_spec.rb +42 -0
  25. data/spec/edo_cabinet_spec.rb +286 -0
  26. data/spec/edo_ntyrant_spec.rb +224 -0
  27. data/spec/edo_ntyrant_table_spec.rb +296 -0
  28. data/spec/edo_table_spec.rb +292 -0
  29. data/spec/hmethods_spec.rb +73 -0
  30. data/spec/incr.lua +23 -0
  31. data/spec/openable_spec.rb +51 -0
  32. data/spec/shared_abstract_spec.rb +426 -0
  33. data/spec/shared_table_spec.rb +675 -0
  34. data/spec/shared_tyrant_spec.rb +42 -0
  35. data/spec/spec_base.rb +23 -0
  36. data/spec/start_tyrants.sh +28 -0
  37. data/spec/stop_tyrants.sh +9 -0
  38. data/spec/table_spec.rb +267 -0
  39. data/spec/tyrant_spec.rb +218 -0
  40. data/spec/tyrant_table_spec.rb +298 -0
  41. data/spec/util_list_spec.rb +197 -0
  42. data/spec/util_map_spec.rb +130 -0
  43. data/tasks/dev.rb +70 -0
  44. data/test/bm0.rb +353 -0
  45. data/test/bm1_compression.rb +54 -0
  46. data/test/con0.rb +30 -0
  47. data/test/mem.rb +49 -0
  48. data/test/mem1.rb +44 -0
  49. data/test/readme0.rb +17 -0
  50. data/test/readme1.rb +21 -0
  51. data/test/readme2.rb +15 -0
  52. data/test/readme3.rb +24 -0
  53. data/test/readmes_test.sh +17 -0
  54. metadata +81 -21
  55. data/MIGRATED.txt +0 -1
@@ -0,0 +1,224 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Mon Feb 23 23:24:45 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+ require File.dirname(__FILE__) + '/shared_abstract_spec'
10
+ require File.dirname(__FILE__) + '/shared_tyrant_spec'
11
+
12
+ begin
13
+ require 'rufus/edo/ntyrant'
14
+ rescue LoadError
15
+ puts "'TokyoTyrant' ruby lib not available on this ruby platform"
16
+ end
17
+
18
+ if defined?(Rufus::Edo)
19
+
20
+ describe 'a missing Rufus::Edo::NetTyrant' do
21
+
22
+ it 'should raise an error' do
23
+
24
+ lambda {
25
+ Rufus::Edo::NetTyrant.new('tyrant.example.com', 45000)
26
+ }.should.raise(Rufus::Edo::EdoError).message.should.equal(
27
+ '(err 2) host not found')
28
+ end
29
+ end
30
+
31
+ describe Rufus::Edo::NetTyrant do
32
+
33
+ it 'should use open with a block will auto close the db correctly' do
34
+
35
+ res = Rufus::Edo::NetTyrant.open('127.0.0.1', 45000) do |cab|
36
+ cab.clear
37
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
38
+ cab.size.should.equal(10)
39
+ :result
40
+ end
41
+
42
+ res.should.equal(:result)
43
+
44
+ cab = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
45
+ 10.times do |i|
46
+ cab["key #{i}"].should.equal("val #{i}")
47
+ end
48
+ cab.close
49
+ end
50
+
51
+
52
+ it 'should use open without a block just like calling new correctly' do
53
+
54
+ cab = Rufus::Edo::NetTyrant.open('127.0.0.1', 45000)
55
+ cab.clear
56
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
57
+ cab.size.should.equal(10)
58
+ cab.close
59
+
60
+ cab = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
61
+ 10.times do |i|
62
+ cab["key #{i}"].should.equal("val #{i}")
63
+ end
64
+ cab.close
65
+ end
66
+ end
67
+
68
+ describe Rufus::Edo::NetTyrant do
69
+
70
+ it 'should open and close' do
71
+
72
+ should.not.raise {
73
+ t = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
74
+ t.close
75
+ }
76
+ end
77
+
78
+ it 'should refuse to connect to a TyrantTable' do
79
+
80
+ lambda {
81
+ t = Rufus::Edo::NetTyrant.new('127.0.0.1', 45001)
82
+ }.should.raise(ArgumentError)
83
+ end
84
+ end
85
+
86
+ describe Rufus::Edo::NetTyrant do
87
+
88
+ before do
89
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
90
+ #puts @t.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
91
+ @db.clear
92
+ end
93
+ after do
94
+ @db.close
95
+ end
96
+
97
+ behaves_like "an abstract structure"
98
+
99
+ it 'should respond to stat' do
100
+
101
+ stat = @db.stat
102
+ stat['type'].should.equal('hash')
103
+ end
104
+
105
+ behaves_like 'a Tyrant structure (no transactions)'
106
+ behaves_like 'a Tyrant structure (copy method)'
107
+ end
108
+
109
+ describe Rufus::Edo::NetTyrant do
110
+
111
+ before do
112
+ @n = 50
113
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
114
+ @db.clear
115
+ @n.times { |i| @db["person#{i}"] = 'whoever' }
116
+ @n.times { |i| @db["animal#{i}"] = 'whichever' }
117
+ @db["toto#{0.chr}5"] = 'toto'
118
+ end
119
+ after do
120
+ @db.close
121
+ end
122
+
123
+ behaves_like 'abstract structure #keys'
124
+ end
125
+
126
+ describe 'Rufus::Edo::NetTyrant lget/lput/ldelete' do
127
+
128
+ before do
129
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
130
+ @db.clear
131
+ 3.times { |i| @db[i.to_s] = "val#{i}" }
132
+ end
133
+ after do
134
+ @db.close
135
+ end
136
+
137
+ behaves_like 'abstract structure #lget/lput/ldelete'
138
+ end
139
+
140
+ describe 'Rufus::Edo::NetTyrant#add{int|double}' do
141
+
142
+ before do
143
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
144
+ @db.clear
145
+ end
146
+ after do
147
+ @db.close
148
+ end
149
+
150
+ behaves_like 'abstract structure #add{int|double}'
151
+ end
152
+
153
+ describe Rufus::Edo::NetTyrant do
154
+
155
+ before do
156
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
157
+ @db.clear
158
+ end
159
+ after do
160
+ @db.close
161
+ end
162
+
163
+ behaves_like 'abstract structure #putkeep'
164
+ behaves_like 'abstract structure #putcat'
165
+ end
166
+
167
+ describe 'Rufus::Edo::NetTyrant (lua extensions)' do
168
+
169
+ before do
170
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
171
+ @db.clear
172
+ end
173
+ after do
174
+ @db.close
175
+ end
176
+
177
+ behaves_like 'tyrant with embedded lua'
178
+ end
179
+
180
+ describe Rufus::Edo::NetTyrant do
181
+
182
+ before do
183
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
184
+ @db.clear
185
+ end
186
+ after do
187
+ @db.close
188
+ end
189
+
190
+ behaves_like 'an abstract structure flattening keys and values'
191
+ end
192
+
193
+ describe 'Rufus::Edo::NetTyrant with a default value' do
194
+
195
+ before do
196
+ @db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000, :default => 'Nemo')
197
+ @db.clear
198
+ @db['known'] = 'Ulysse'
199
+ end
200
+ after do
201
+ @db.close
202
+ end
203
+
204
+ behaves_like 'an abstract structure with a default value'
205
+ end
206
+
207
+ describe 'Rufus::Edo::Tyrant with a default_proc' do
208
+
209
+ before do
210
+ @db = Rufus::Edo::NetTyrant.new(
211
+ '127.0.0.1',
212
+ 45000,
213
+ :default_proc => lambda { |db, k| "default:#{k}" })
214
+ @db.clear
215
+ @db['known'] = 'Ulysse'
216
+ end
217
+ after do
218
+ @db.close
219
+ end
220
+
221
+ behaves_like 'an abstract structure with a default_proc'
222
+ end
223
+ end
224
+
@@ -0,0 +1,296 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Wed Feb 25 10:38:42 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'spec_base')
9
+ require File.join(File.dirname(__FILE__), 'shared_table_spec')
10
+ require File.join(File.dirname(__FILE__), 'shared_tyrant_spec')
11
+
12
+ require 'rufus/edo/ntyrant'
13
+
14
+
15
+ describe 'a missing Rufus::Edo::NetTyrantTable' do
16
+
17
+ it 'should raise an error' do
18
+
19
+ lambda {
20
+ Rufus::Edo::NetTyrantTable.new('127.0.0.1', 1)
21
+ }.should.raise(Rufus::Edo::EdoError).message.should.equal(
22
+ '(err 3) connection refused')
23
+ end
24
+ end
25
+
26
+ describe 'Rufus::Edo::NetTyrantTable' do
27
+
28
+ it 'should refuse to connect to a plain Tyrant' do
29
+
30
+ lambda {
31
+ t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45000)
32
+ }.should.raise(ArgumentError)
33
+ end
34
+ end
35
+
36
+ describe 'Rufus::Edo::NetTyrantTable' do
37
+
38
+ before do
39
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
40
+ #puts @t.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
41
+ @t.clear
42
+ end
43
+ after do
44
+ @t.close
45
+ end
46
+
47
+ it 'should respond to stat' do
48
+
49
+ @t.stat['type'].should.equal('table')
50
+ end
51
+
52
+ behaves_like 'table'
53
+ behaves_like 'a Tyrant structure (no transactions)'
54
+ end
55
+
56
+ describe Rufus::Edo::NetTyrantTable do
57
+
58
+ it 'should use open with a block will auto close the db correctly' do
59
+
60
+ res = Rufus::Edo::NetTyrantTable.open('127.0.0.1', 45001) do |table|
61
+ table.clear
62
+ 10.times { |i| table["key #{i}"] = {:val => i} }
63
+ table.size.should.equal(10)
64
+ :result
65
+ end
66
+
67
+ res.should.equal(:result)
68
+
69
+ table = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
70
+ 10.times do |i|
71
+ table["key #{i}"].should.equal({"val" => i.to_s})
72
+ end
73
+ table.close
74
+ end
75
+
76
+
77
+ it 'should use open without a block just like calling new correctly' do
78
+
79
+ table = Rufus::Edo::NetTyrantTable.open('127.0.0.1', 45001)
80
+ table.clear
81
+ 10.times { |i| table["key #{i}"] = {:val => i} }
82
+ table.size.should.equal(10)
83
+ table.close
84
+
85
+ table = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
86
+ 10.times do |i|
87
+ table["key #{i}"].should.equal({"val" => i.to_s})
88
+ end
89
+ table.close
90
+ end
91
+ end
92
+
93
+ describe Rufus::Edo::NetTyrantTable do
94
+
95
+ before do
96
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
97
+ @t.clear
98
+ end
99
+ after do
100
+ @t.close
101
+ end
102
+
103
+ it 'should not support transactions' do
104
+ lambda {
105
+ @t.transaction {}
106
+ }.should.raise(NoMethodError)
107
+ lambda {
108
+ @t.abort
109
+ }.should.raise(NoMethodError)
110
+ end
111
+ end
112
+
113
+ describe 'Rufus::Edo::NetTyrantTable #keys' do
114
+
115
+ before do
116
+ @n = 50
117
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
118
+ @t.clear
119
+ @n.times { |i| @t["person#{i}"] = { 'name' => 'whoever' } }
120
+ @n.times { |i| @t["animal#{i}"] = { 'name' => 'whichever' } }
121
+ @t["toto#{0.chr}5"] = { 'name' => 'toto' }
122
+ end
123
+ after do
124
+ @t.close
125
+ end
126
+
127
+ behaves_like 'table #keys'
128
+ end
129
+
130
+ def prepare_table_with_data (port)
131
+ t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', port)
132
+ t.clear
133
+ t['pk0'] = { 'name' => 'jim', 'age' => '25', 'lang' => 'ja,en' }
134
+ t['pk1'] = { 'name' => 'jeff', 'age' => '32', 'lang' => 'en,es' }
135
+ t['pk2'] = { 'name' => 'jack', 'age' => '44', 'lang' => 'en' }
136
+ t['pk3'] = { 'name' => 'jake', 'age' => '45', 'lang' => 'en,li' }
137
+ t
138
+ end
139
+
140
+ describe 'a Tokyo Tyrant table' do
141
+
142
+ before do
143
+ @t = prepare_table_with_data(45001)
144
+ end
145
+ after do
146
+ @t.close
147
+ # TODO : well there are trailing indexes now... :(
148
+ end
149
+
150
+ behaves_like 'table indexes'
151
+ end
152
+
153
+ describe 'Rufus::Edo::NetTyrantTable#lget' do
154
+
155
+ before do
156
+ @t = prepare_table_with_data(45001)
157
+ end
158
+ after do
159
+ @t.close
160
+ end
161
+
162
+ behaves_like 'table lget'
163
+ end
164
+
165
+ describe 'Rufus::Edo::NetTyrantTable, like a Ruby Hash,' do
166
+
167
+ before do
168
+ @t = prepare_table_with_data(45001)
169
+ end
170
+ after do
171
+ @t.close
172
+ end
173
+
174
+ behaves_like 'table like a hash'
175
+ end
176
+
177
+ describe 'queries on Rufus::Edo::NetTyrantTable' do
178
+
179
+ before do
180
+ @t = prepare_table_with_data(45001)
181
+ end
182
+ after do
183
+ @t.close
184
+ end
185
+
186
+ behaves_like 'table query'
187
+ end
188
+
189
+ describe 'Queries on Tokyo Tyrant tables (via Rufus::Edo)' do
190
+
191
+ before do
192
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
193
+ @t.clear
194
+ [
195
+ "consul readableness choleric hopperdozer juckies",
196
+ "fume overharshness besprinkler whirling erythrene",
197
+ "trumper defiable detractively cattiness superioress",
198
+ "vivificative consul agglomerated Peterloo way",
199
+ "unkilned bituminate antimatrimonial uran polyphony",
200
+ "kurumaya unannexed renownedly apetaloid consul",
201
+ "overdare nescience seronegative nagster overfatten",
202
+ ].each_with_index { |w, i|
203
+ @t["pk#{i}"] = { 'name' => "lambda#{i}", 'words' => w }
204
+ }
205
+ end
206
+ after do
207
+ @t.close
208
+ end
209
+
210
+ behaves_like 'table query (fts)'
211
+ end
212
+
213
+ describe 'Rufus::Edo::NetTyrantTable and TableQuery#process' do
214
+
215
+ before do
216
+ @t = prepare_table_with_data(45001)
217
+ end
218
+ after do
219
+ @t.close
220
+ end
221
+
222
+ # TODO : orly ?
223
+
224
+ it 'should not work' do
225
+
226
+ lambda {
227
+ @t.prepare_query { |q|
228
+ q.add 'lang', :includes, 'en'
229
+ }.process { |k, v|
230
+ }.free
231
+ }.should.raise(NoMethodError)
232
+ end
233
+ end
234
+
235
+ describe 'results from Rufus::Edo::NetTyrantTable queries' do
236
+
237
+ before do
238
+ @t = prepare_table_with_data(45001)
239
+ end
240
+ after do
241
+ @t.close
242
+ end
243
+
244
+ behaves_like 'table query results'
245
+ end
246
+
247
+ describe 'Rufus::Edo::NetTyrantTable (lua extensions)' do
248
+
249
+ before do
250
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
251
+ @t.clear
252
+ end
253
+ after do
254
+ @t.close
255
+ end
256
+
257
+ behaves_like 'tyrant table with embedded lua'
258
+ end
259
+
260
+ describe Rufus::Edo::NetTyrantTable do
261
+
262
+ before do
263
+ @t = Rufus::Edo::NetTyrantTable.new('127.0.0.1', 45001)
264
+ @t.clear
265
+ end
266
+ after do
267
+ @t.close
268
+ end
269
+
270
+ behaves_like 'a table structure flattening keys and values'
271
+ end
272
+
273
+ describe 'Rufus::Edo::NetTyrantTable\'s queries' do
274
+
275
+ before do
276
+ @t = prepare_table_with_data(45001)
277
+ end
278
+ after do
279
+ @t.close
280
+ end
281
+
282
+ behaves_like 'a table structure to_s-ing query stuff'
283
+ end
284
+
285
+ describe 'Rufus::Edo::Table and metasearch' do
286
+
287
+ before do
288
+ @t = prepare_table_with_data(45001)
289
+ end
290
+ after do
291
+ @t.close
292
+ end
293
+
294
+ behaves_like 'table query metasearch'
295
+ end
296
+