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,42 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Thu Sep 24 10:59:39 JST 2009
6
+ #
7
+
8
+ shared 'a Tyrant structure (no transactions)' do
9
+
10
+ it 'should raise NoMethodError on transactions' do
11
+
12
+ ex = nil
13
+
14
+ begin
15
+ (@db || @t).transaction {}
16
+ rescue Exception => e
17
+ ex = e
18
+ end
19
+
20
+ ex.class.should.equal(NoMethodError)
21
+ ex.message.should.match(/ support /)
22
+ end
23
+ end
24
+
25
+ shared 'a Tyrant structure (copy method)' do
26
+
27
+ it 'should accept #copy calls' do
28
+
29
+ SOURCE = 'tmp/tyrant.tch'
30
+
31
+ TARGET = File.expand_path(
32
+ File.join(File.dirname(__FILE__), '../tmp/tyrant_copy.tch'))
33
+
34
+ @db.copy(TARGET)
35
+
36
+ File.exist?(TARGET).should.be.true
37
+ File.stat(TARGET).size.should.equal(File.stat(SOURCE).size)
38
+
39
+ FileUtils.rm(TARGET)
40
+ end
41
+ end
42
+
data/spec/spec_base.rb ADDED
@@ -0,0 +1,23 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Sun Feb 8 13:15:08 JST 2009
6
+ #
7
+
8
+ #
9
+ # bacon
10
+
11
+ $:.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib')))
12
+
13
+ require 'rubygems'
14
+ require 'fileutils'
15
+
16
+ $:.unshift(File.expand_path('~/tmp/bacon/lib')) # my own bacon for a while
17
+
18
+ require 'bacon'
19
+
20
+ puts
21
+
22
+ Bacon.summary_on_exit
23
+
@@ -0,0 +1,28 @@
1
+ #!/bin/bash
2
+
3
+ #
4
+ # starting the tt servers (standard + table)
5
+ #
6
+
7
+ TMP=`pwd`/tmp
8
+ # so that tt doesn't complain about relative paths...
9
+
10
+ [ -d $TMP ] || mkdir $TMP
11
+
12
+ ttserver \
13
+ -dmn \
14
+ -ext `pwd`/spec/incr.lua \
15
+ -port 45000 \
16
+ -pid $TMP/t_spec.pid -rts $TMP/t_spec.rts \
17
+ -log $TMP/t.log \
18
+ -unmask copy \
19
+ $TMP/tyrant.tch
20
+
21
+ ttserver \
22
+ -dmn \
23
+ -ext `pwd`/spec/incr.lua \
24
+ -port 45001 \
25
+ -pid $TMP/tt_spec.pid -rts $TMP/tt_spec.rts \
26
+ -log $TMP/tt.log \
27
+ $TMP/tyrant_table.tct
28
+
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+
3
+ # stopping the spec ttservers
4
+
5
+ ruby -e "%w{ tmp/t_spec.pid tmp/tt_spec.pid }.each { |pf| File.exist?(pf) && Process.kill(9, File.read(pf).strip.to_i) }"
6
+
7
+ rm tmp/t_spec.pid
8
+ rm tmp/tt_spec.pid
9
+
@@ -0,0 +1,267 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Sun Feb 8 16:07:16 JST 2009
6
+ #
7
+
8
+ require File.join(File.dirname(__FILE__), 'spec_base')
9
+ require File.join(File.dirname(__FILE__), 'shared_table_spec')
10
+
11
+ require 'rufus/tokyo'
12
+
13
+ FileUtils.mkdir('tmp') rescue nil
14
+
15
+
16
+ describe Rufus::Tokyo::Table do
17
+
18
+ it 'should open in write/create mode by default' do
19
+
20
+ t = Rufus::Tokyo::Table.new('tmp/default.tct')
21
+ t.close
22
+ File.exist?('tmp/default.tct').should.equal(true)
23
+ FileUtils.rm('tmp/default.tct')
24
+ end
25
+
26
+ it 'should raise an error when file is missing' do
27
+
28
+ lambda {
29
+ Rufus::Tokyo::Table.new('tmp/missing.tct', :mode => 'r')
30
+ }.should.raise(
31
+ Rufus::Tokyo::TokyoError).message.should.equal('(err 3) file not found')
32
+ end
33
+ end
34
+
35
+ describe Rufus::Tokyo::Table do
36
+
37
+ it 'should use open with a block will auto close the db correctly' do
38
+
39
+ res = Rufus::Tokyo::Table.open('tmp/spec_source.tct') do |table|
40
+ 10.times { |i| table["key #{i}"] = {:val => i} }
41
+ table.size.should.equal(10)
42
+ :result
43
+ end
44
+
45
+ res.should.equal(:result)
46
+
47
+ table = Rufus::Tokyo::Table.new('tmp/spec_source.tct')
48
+ 10.times do |i|
49
+ table["key #{i}"].should.equal({"val" => i.to_s})
50
+ end
51
+ table.close
52
+
53
+ FileUtils.rm('tmp/spec_source.tct')
54
+ end
55
+
56
+
57
+ it 'should use open without a block just like calling new correctly' do
58
+
59
+ table = Rufus::Tokyo::Table.open('tmp/spec_source.tct')
60
+ 10.times { |i| table["key #{i}"] = {:val => i} }
61
+ table.size.should.equal(10)
62
+ table.close
63
+
64
+ table = Rufus::Tokyo::Table.new('tmp/spec_source.tct')
65
+ 10.times do |i|
66
+ table["key #{i}"].should.equal({"val" => i.to_s})
67
+ end
68
+ table.close
69
+
70
+ FileUtils.rm('tmp/spec_source.tct')
71
+ end
72
+ end
73
+
74
+ describe Rufus::Tokyo::Table do
75
+
76
+ before do
77
+ @t = Rufus::Tokyo::Table.new('tmp/table.tct')
78
+ @t.clear
79
+ end
80
+ after do
81
+ @t.close
82
+ end
83
+
84
+ it 'should return its path' do
85
+
86
+ @t.path.should.equal('tmp/table.tct')
87
+ end
88
+
89
+ behaves_like 'table'
90
+ end
91
+
92
+ describe Rufus::Tokyo::Table do
93
+
94
+ before do
95
+ @t = Rufus::Tokyo::Table.new('tmp/table.tct')
96
+ @t.clear
97
+ end
98
+ after do
99
+ @t.close
100
+ end
101
+
102
+ behaves_like 'table with transactions'
103
+ end
104
+
105
+ describe 'Rufus::Tokyo::Table #keys' do
106
+
107
+ before do
108
+ @n = 50
109
+ @t = Rufus::Tokyo::Table.new('tmp/test_new.tct')
110
+ @t.clear
111
+ @n.times { |i| @t["person#{i}"] = { 'name' => 'whoever' } }
112
+ @n.times { |i| @t["animal#{i}"] = { 'name' => 'whichever' } }
113
+ @t["toto#{0.chr}5"] = { 'name' => 'toto' }
114
+ end
115
+ after do
116
+ @t.close
117
+ end
118
+
119
+ behaves_like 'table #keys'
120
+ end
121
+
122
+ def prepare_table_with_data
123
+
124
+ t = Rufus::Tokyo::Table.new('tmp/test_new.tct')
125
+ t.clear
126
+ t['pk0'] = { 'name' => 'jim', 'age' => '25', 'lang' => 'ja,en' }
127
+ t['pk1'] = { 'name' => 'jeff', 'age' => '32', 'lang' => 'en,es' }
128
+ t['pk2'] = { 'name' => 'jack', 'age' => '44', 'lang' => 'en' }
129
+ t['pk3'] = { 'name' => 'jake', 'age' => '45', 'lang' => 'en,li' }
130
+ t
131
+ end
132
+
133
+ describe Rufus::Tokyo::Table do
134
+
135
+ before do
136
+ @t = prepare_table_with_data
137
+ end
138
+ after do
139
+ @t.close
140
+ end
141
+
142
+ behaves_like 'table indexes'
143
+ end
144
+
145
+ describe 'Rufus::Tokyo::Table#lget' do
146
+
147
+ before do
148
+ @t = prepare_table_with_data
149
+ end
150
+ after do
151
+ @t.close
152
+ end
153
+
154
+ behaves_like 'table lget'
155
+ end
156
+
157
+ # DONE
158
+
159
+ describe 'Rufus::Tokyo::Table, like a Ruby Hash' do
160
+
161
+ before do
162
+ @t = prepare_table_with_data
163
+ end
164
+ after do
165
+ @t.close
166
+ end
167
+
168
+ behaves_like 'table like a hash'
169
+ end
170
+
171
+ describe Rufus::Tokyo::TableQuery do
172
+
173
+ before do
174
+ @t = prepare_table_with_data
175
+ end
176
+ after do
177
+ @t.close
178
+ end
179
+
180
+ behaves_like 'table query'
181
+ end
182
+
183
+ describe 'Rufus::Tokyo::TableQuery (fts)' do
184
+
185
+ before do
186
+ @t = Rufus::Tokyo::Table.new('tmp/test_new.tct')
187
+ @t.clear
188
+ [
189
+ "consul readableness choleric hopperdozer juckies",
190
+ "fume overharshness besprinkler whirling erythrene",
191
+ "trumper defiable detractively cattiness superioress",
192
+ "vivificative consul agglomerated Peterloo way",
193
+ "unkilned bituminate antimatrimonial uran polyphony",
194
+ "kurumaya unannexed renownedly apetaloid consul",
195
+ "overdare nescience seronegative nagster overfatten",
196
+ ].each_with_index { |w, i|
197
+ @t["pk#{i}"] = { 'name' => "lambda#{i}", 'words' => w }
198
+ }
199
+ end
200
+ after do
201
+ @t.close
202
+ end
203
+
204
+ behaves_like 'table query (fts)'
205
+ end
206
+
207
+ describe 'Rufus::Tokyo::TableQuery#process' do
208
+
209
+ before do
210
+ @t = prepare_table_with_data
211
+ end
212
+ after do
213
+ @t.close
214
+ end
215
+
216
+ behaves_like 'table query #process'
217
+ end
218
+
219
+ describe 'results from queries on Rufus::Tokyo::Table' do
220
+
221
+ before do
222
+ @t = prepare_table_with_data
223
+ end
224
+ after do
225
+ @t.close
226
+ end
227
+
228
+ behaves_like 'table query results'
229
+ end
230
+
231
+ describe Rufus::Tokyo::Table do
232
+
233
+ before do
234
+ @t = Rufus::Tokyo::Table.new('tmp/table.tct')
235
+ @t.clear
236
+ end
237
+ after do
238
+ @t.close
239
+ end
240
+
241
+ behaves_like 'a table structure flattening keys and values'
242
+ end
243
+
244
+ describe 'Rufus::Tokyo::Table\'s queries' do
245
+
246
+ before do
247
+ @t = prepare_table_with_data
248
+ end
249
+ after do
250
+ @t.close
251
+ end
252
+
253
+ behaves_like 'a table structure to_s-ing query stuff'
254
+ end
255
+
256
+ describe 'Rufus::Tokyo::Table and metasearch' do
257
+
258
+ before do
259
+ @t = prepare_table_with_data
260
+ end
261
+ after do
262
+ @t.close
263
+ end
264
+
265
+ behaves_like 'table query metasearch'
266
+ end
267
+
@@ -0,0 +1,218 @@
1
+
2
+ #
3
+ # Specifying rufus-tokyo
4
+ #
5
+ # Sun Feb 8 13:13:41 JST 2009
6
+ #
7
+
8
+ require File.dirname(__FILE__) + '/spec_base'
9
+ require File.dirname(__FILE__) + '/shared_abstract_spec'
10
+ require File.join(File.dirname(__FILE__), 'shared_tyrant_spec')
11
+
12
+ require 'rufus/tokyo/tyrant'
13
+
14
+
15
+ describe 'a missing Rufus::Tokyo::Tyrant' do
16
+
17
+ it 'should raise an error' do
18
+
19
+ lambda {
20
+ Rufus::Tokyo::Tyrant.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::Tyrant do
27
+
28
+ it 'should open and close' do
29
+
30
+ should.not.raise {
31
+ t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
32
+ t.close
33
+ }
34
+ end
35
+
36
+ it 'should refuse to connect to a TyrantTable' do
37
+
38
+ lambda {
39
+ t = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45001)
40
+ }.should.raise(ArgumentError)
41
+ end
42
+ end
43
+
44
+ describe Rufus::Tokyo::Tyrant do
45
+
46
+ it 'should use open with a block will auto close the db correctly' do
47
+
48
+ res = Rufus::Tokyo::Tyrant.open('127.0.0.1', 45000) do |cab|
49
+ cab.clear
50
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
51
+ cab.size.should.equal(10)
52
+ :result
53
+ end
54
+
55
+ res.should.equal(:result)
56
+
57
+ cab = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
58
+ 10.times do |i|
59
+ cab["key #{i}"].should.equal("val #{i}")
60
+ end
61
+ cab.close
62
+ end
63
+
64
+
65
+ it 'should use open without a block just like calling new correctly' do
66
+
67
+ cab = Rufus::Tokyo::Tyrant.open('127.0.0.1', 45000)
68
+ cab.clear
69
+ 10.times { |i| cab["key #{i}"] = "val #{i}" }
70
+ cab.size.should.equal(10)
71
+ cab.close
72
+
73
+ cab = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
74
+ 10.times do |i|
75
+ cab["key #{i}"].should.equal("val #{i}")
76
+ end
77
+ cab.close
78
+ end
79
+ end
80
+
81
+ describe Rufus::Tokyo::Tyrant do
82
+
83
+ before do
84
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
85
+ @db.clear
86
+ end
87
+ after do
88
+ @db.close
89
+ end
90
+
91
+ behaves_like 'an abstract structure'
92
+ behaves_like 'a Tyrant structure (no transactions)'
93
+ behaves_like 'a Tyrant structure (copy method)'
94
+
95
+ it 'should respond to stat' do
96
+
97
+ stat = @db.stat
98
+ stat['type'].should.equal('hash')
99
+ end
100
+ end
101
+
102
+ describe Rufus::Tokyo::Tyrant do
103
+
104
+ before do
105
+
106
+ @n = 50
107
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
108
+ @db.clear
109
+ @n.times { |i| @db["person#{i}"] = 'whoever' }
110
+ @n.times { |i| @db["animal#{i}"] = 'whichever' }
111
+ @db["toto#{0.chr}5"] = 'toto'
112
+ end
113
+
114
+ after do
115
+
116
+ @db.close
117
+ end
118
+
119
+ behaves_like 'abstract structure #keys'
120
+ end
121
+
122
+ describe Rufus::Tokyo::Tyrant do
123
+
124
+ before do
125
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
126
+ @db.clear
127
+ 3.times { |i| @db[i.to_s] = "val#{i}" }
128
+ end
129
+ after do
130
+ @db.close
131
+ end
132
+
133
+ behaves_like 'abstract structure #lget/lput/ldelete'
134
+ end
135
+
136
+ describe Rufus::Tokyo::Tyrant do
137
+
138
+ before do
139
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
140
+ @db.clear
141
+ end
142
+ after do
143
+ @db.close
144
+ end
145
+
146
+ behaves_like 'abstract structure #add{int|double}'
147
+ end
148
+
149
+ describe Rufus::Tokyo::Tyrant do
150
+
151
+ before do
152
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
153
+ @db.clear
154
+ end
155
+ after do
156
+ @db.close
157
+ end
158
+
159
+ behaves_like 'abstract structure #putkeep'
160
+ behaves_like 'abstract structure #putcat'
161
+ end
162
+
163
+ describe 'Rufus::Tokyo::Tyrant (lua extensions)' do
164
+
165
+ before do
166
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
167
+ @db.clear
168
+ end
169
+ after do
170
+ @db.close
171
+ end
172
+
173
+ behaves_like 'tyrant with embedded lua'
174
+ end
175
+
176
+ describe Rufus::Tokyo::Tyrant do
177
+
178
+ before do
179
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000)
180
+ @db.clear
181
+ end
182
+ after do
183
+ @db.close
184
+ end
185
+
186
+ behaves_like 'an abstract structure flattening keys and values'
187
+ end
188
+
189
+ describe 'Rufus::Tokyo::Tyrant with a default value' do
190
+
191
+ before do
192
+ @db = Rufus::Tokyo::Tyrant.new('127.0.0.1', 45000, :default => 'Nemo')
193
+ @db.clear
194
+ @db['known'] = 'Ulysse'
195
+ end
196
+ after do
197
+ @db.close
198
+ end
199
+
200
+ behaves_like 'an abstract structure with a default value'
201
+ end
202
+
203
+ describe 'Rufus::Tokyo::Tyrant with a default_proc' do
204
+
205
+ before do
206
+ @db = Rufus::Tokyo::Tyrant.new(
207
+ '127.0.0.1',
208
+ 45000,
209
+ :default_proc => lambda { |db, k| "default:#{k}" })
210
+ @db.clear
211
+ @db['known'] = 'Ulysse'
212
+ end
213
+ after do
214
+ @db.close
215
+ end
216
+
217
+ behaves_like 'an abstract structure with a default_proc'
218
+ end