rufus-tokyo 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,298 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Sun Feb 8 22:55:11 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.dirname(__FILE__) + '/shared_tyrant_spec'
11
+
12
+ require 'rufus/tokyo/tyrant'
13
+
14
+
15
+ describe 'a missing Rufus::Tokyo::TyrantTable' do
16
+
17
+ it 'should raise an error' do
18
+
19
+ lambda {
20
+ Rufus::Tokyo::TyrantTable.new('127.0.0.1', 1)
21
+ }.should.raise(Rufus::Tokyo::TokyoError).message.should.equal(
22
+ "couldn't connect to tyrant at 127.0.0.1:1")
23
+ end
24
+ end
25
+
26
+ describe 'Rufus::Tokyo::TyrantTable' do
27
+
28
+ it 'should refuse to connect to a plain Tyrant' do
29
+
30
+ lambda {
31
+ t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45000)
32
+ }.should.raise(ArgumentError)
33
+ end
34
+ end
35
+
36
+ describe Rufus::Tokyo::TyrantTable do
37
+
38
+ it 'should use open with a block will auto close the db correctly' do
39
+
40
+ res = Rufus::Tokyo::TyrantTable.open('127.0.0.1', 45001) do |table|
41
+ table.clear
42
+ 10.times { |i| table["key #{i}"] = {:val => i} }
43
+ table.size.should.equal(10)
44
+ :result
45
+ end
46
+
47
+ res.should.equal(:result)
48
+
49
+ table = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45001)
50
+ 10.times do |i|
51
+ table["key #{i}"].should.equal({"val" => i.to_s})
52
+ end
53
+ table.close
54
+ end
55
+
56
+
57
+ it 'should use open without a block just like calling new correctly' do
58
+
59
+ table = Rufus::Tokyo::TyrantTable.open('127.0.0.1', 45001)
60
+ table.clear
61
+ 10.times { |i| table["key #{i}"] = {:val => i} }
62
+ table.size.should.equal(10)
63
+ table.close
64
+
65
+ table = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45001)
66
+ 10.times do |i|
67
+ table["key #{i}"].should.equal({"val" => i.to_s})
68
+ end
69
+ table.close
70
+ end
71
+ end
72
+
73
+ describe Rufus::Tokyo::TyrantTable do
74
+
75
+ before do
76
+ @t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45001)
77
+ #puts @t.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
78
+ @t.clear
79
+ end
80
+ after do
81
+ @t.close
82
+ end
83
+
84
+ it 'should respond to stat' do
85
+
86
+ @t.stat['type'].should.equal('table')
87
+ end
88
+
89
+ behaves_like 'table'
90
+ behaves_like 'a Tyrant structure (no transactions)'
91
+ end
92
+
93
+ describe Rufus::Tokyo::TyrantTable do
94
+
95
+ before do
96
+ @t = Rufus::Tokyo::TyrantTable.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::Tokyo::Table #keys' do
114
+
115
+ before do
116
+ @n = 50
117
+ @t = Rufus::Tokyo::TyrantTable.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::Tokyo::TyrantTable.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 Rufus::Tokyo::TyrantTable 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::Tokyo::TyrantTable#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 'a Tokyo Tyrant table, 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 Tokyo Tyrant tables' 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' do
190
+
191
+ before do
192
+ @t = Rufus::Tokyo::TyrantTable.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 'Tokyo Tyrant 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
+ #behaves_like 'table query #process'
225
+
226
+ it 'should not work' do
227
+
228
+ lambda {
229
+ @t.prepare_query { |q|
230
+ q.add 'lang', :includes, 'en'
231
+ }.process { |k, v|
232
+ }.free
233
+ }.should.raise(NoMethodError)
234
+ end
235
+ end
236
+
237
+ describe 'results from Tokyo Tyrant table queries' do
238
+
239
+ before do
240
+ @t = prepare_table_with_data(45001)
241
+ end
242
+ after do
243
+ @t.close
244
+ end
245
+
246
+ behaves_like 'table query results'
247
+ end
248
+
249
+ describe 'Rufus::Tokyo::TyrantTable (lua extensions)' do
250
+
251
+ before do
252
+ @t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45001)
253
+ @t.clear
254
+ end
255
+ after do
256
+ @t.close
257
+ end
258
+
259
+ behaves_like 'tyrant table with embedded lua'
260
+ end
261
+
262
+ describe Rufus::Tokyo::TyrantTable do
263
+
264
+ before do
265
+ @t = Rufus::Tokyo::TyrantTable.new('127.0.0.1', 45001)
266
+ @t.clear
267
+ end
268
+ after do
269
+ @t.close
270
+ end
271
+
272
+ behaves_like 'a table structure flattening keys and values'
273
+ end
274
+
275
+ describe 'Rufus::Tokyo::TyrantTable\'s queries' do
276
+
277
+ before do
278
+ @t = prepare_table_with_data(45001)
279
+ end
280
+ after do
281
+ @t.close
282
+ end
283
+
284
+ behaves_like 'a table structure to_s-ing query stuff'
285
+ end
286
+
287
+ describe 'Rufus::Tokyo::Table and metasearch' do
288
+
289
+ before do
290
+ @t = prepare_table_with_data(45001)
291
+ end
292
+ after do
293
+ @t.close
294
+ end
295
+
296
+ behaves_like 'table query metasearch'
297
+ end
298
+
@@ -0,0 +1,197 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Tue Jan 27 16:30:34 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+
10
+ require 'rufus/tokyo'
11
+
12
+
13
+ describe 'Rufus::Tokyo::List' do
14
+
15
+ before do
16
+ @l = Rufus::Tokyo::List.new
17
+ end
18
+ after do
19
+ @l.free
20
+ end
21
+
22
+ it 'should be empty initially' do
23
+ @l.size.should.be.zero
24
+ end
25
+
26
+ it 'should respond to <<' do
27
+ l = @l << 'a'
28
+ @l.size.should.equal(1)
29
+ l.should.equal(@l)
30
+ end
31
+
32
+ it 'should respond to push' do
33
+ l = @l.push('a')
34
+ @l.size.should.equal(1)
35
+ l.should.equal(@l)
36
+ end
37
+
38
+ it 'should respond to push with multiple arguments' do
39
+ @l.push('a', 'b', 'c')
40
+ @l.size.should.equal(3)
41
+ end
42
+
43
+ it 'should respond to pop' do
44
+ @l.pop.should.be.nil
45
+ end
46
+
47
+ it 'should respond to shift' do
48
+ @l.shift.should.be.nil
49
+ end
50
+
51
+ it 'should accept strings with \\0' do
52
+ s = "tokyo#{0.chr}cabinet"
53
+ @l << s
54
+ @l.pop.should.equal(s)
55
+ end
56
+
57
+ it 'should iterate over values with \\0' do
58
+ @l << 'ab' << "c#{0.chr}d" << 'ef'
59
+ ss = @l.inject('') { |s, e| s << e }
60
+ ss.should.equal("abc#{0.chr}def")
61
+ end
62
+
63
+ it 'should pop values with \\0' do
64
+ s = "shinbashi#{0.chr}closet"
65
+ @l << s
66
+ @l.pop.should.equal(s)
67
+ end
68
+
69
+ it 'should shift values with \\0' do
70
+ s = "shinbashi#{0.chr}closet"
71
+ @l << s
72
+ @l.shift.should.equal(s)
73
+ end
74
+
75
+ it 'should unshift values with \\0' do
76
+ s = "shinbashi#{0.chr}closet"
77
+ @l.unshift(s)
78
+ @l[0].should.equal(s)
79
+ end
80
+
81
+ it 'should remove values with \\0' do
82
+ s = "shinbashi#{0.chr}closet"
83
+ @l << s
84
+ @l.delete_at(0).should.equal(s)
85
+ end
86
+
87
+ it 'should overwrite values with \\0' do
88
+ s0 = "shinbashi#{0.chr}closet"
89
+ s1 = "sugamo#{0.chr}drawer"
90
+ @l << s0
91
+ @l[0] = s1
92
+ @l[0].should.equal(s1)
93
+ end
94
+
95
+ #it 'should delete [multiple] values' do
96
+ # %w[ a b a c a ].each { |e| @l << e }
97
+ # @l.delete('a')
98
+ # @l.to_a.should.equal(%w[ b c ])
99
+ #end
100
+ #it 'should return the deleted value' do
101
+ # %w[ a b a c a ].each { |e| @l << e }
102
+ # @l.delete('d').should.be.nil
103
+ #end
104
+ #it 'should return the value of the default block when deleting a missing elt' do
105
+ # %w[ a b a c a ].each { |e| @l << e }
106
+ # @l.delete('d') { 'nada' }.should.equal('nada')
107
+ #end
108
+
109
+ it 'should not accept non-string values' do
110
+ lambda {
111
+ @l << 2
112
+ }.should.raise(ArgumentError)
113
+ end
114
+ end
115
+
116
+ describe 'Rufus::Tokyo::List' do
117
+
118
+ it 'should close itself and return its ruby version upon #release' do
119
+
120
+ l = Rufus::Tokyo::List.new << 'a' << 'b' << 'c'
121
+ l.release.should.equal(%w{ a b c })
122
+ l.instance_variable_get(:@pointer).should.be.nil
123
+ end
124
+
125
+ it 'can be created from a Ruby Array' do
126
+
127
+ l = Rufus::Tokyo::List.new(%w{ a b c })
128
+ l.pointer.is_a?(FFI::Pointer).should.be.true
129
+ end
130
+ end
131
+
132
+ describe 'Rufus::Tokyo::List' do
133
+
134
+ before do
135
+ @l = Rufus::Tokyo::List.new
136
+ @l << 'a' << 'b' << 'c' << 'd'
137
+ end
138
+ after do
139
+ @l.free
140
+ end
141
+
142
+ it 'should respond to pop' do
143
+ @l.pop.should.equal('d')
144
+ @l.size.should.equal(3)
145
+ end
146
+
147
+ it 'should respond to shift' do
148
+ @l.shift.should.equal('a')
149
+ @l.size.should.equal(3)
150
+ end
151
+
152
+ it 'should respond to unshift' do
153
+ @l.unshift('z')
154
+ @l.size.should.equal(5)
155
+ end
156
+
157
+ it 'should slice correctly' do
158
+ @l[1].should.equal('b')
159
+ @l[-1].should.equal('d')
160
+ @l[0, 2].should.equal(%w{ a b })
161
+ @l[0..-1].should.equal(%w{ a b c d })
162
+ @l[0..1].should.equal(%w{ a b })
163
+ @l[0, -1].should.be.nil
164
+ end
165
+ end
166
+
167
+ describe 'Rufus::Tokyo::List' do
168
+
169
+ before do
170
+ @l = Rufus::Tokyo::List.new
171
+ @l.push(*%w{ - - - - e })
172
+ end
173
+ after do
174
+ @l.free
175
+ end
176
+
177
+ it 'should overwrite slices (0)' do
178
+ @l[0, 3] = %w{ a b c }
179
+ @l.to_a.should.equal(%w{ a b c - e })
180
+ end
181
+
182
+ it 'should overwrite slices (1)' do
183
+ @l[1..2] = %w{ a b }
184
+ @l.to_a.should.equal(%w{ - a b - e })
185
+ end
186
+
187
+ it 'should overwrite slices (2)' do
188
+ @l[0, 2] = '?'
189
+ @l.to_a.should.equal(%w{ ? - - e })
190
+ end
191
+
192
+ it 'should overwrite slices (3)' do
193
+ @l[0..2] = '?'
194
+ @l.to_a.should.equal(%w{ ? - e })
195
+ end
196
+ end
197
+