actsasflinn-ruby-tokyotyrant 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/benchmarks/bulk_db.rb +74 -0
- data/benchmarks/bulk_table.rb +85 -0
- data/benchmarks/db.rb +114 -0
- data/benchmarks/table.rb +161 -0
- data/ext/tokyo_tyrant.c +162 -0
- data/ext/tokyo_tyrant.h +48 -0
- data/ext/tokyo_tyrant_db.c +242 -0
- data/ext/tokyo_tyrant_db.h +8 -0
- data/ext/tokyo_tyrant_module.c +298 -0
- data/ext/tokyo_tyrant_module.h +8 -0
- data/ext/tokyo_tyrant_query.c +149 -0
- data/ext/tokyo_tyrant_query.h +9 -0
- data/ext/tokyo_tyrant_table.c +259 -0
- data/ext/tokyo_tyrant_table.h +8 -0
- data/spec/plu_db.rb +538 -0
- data/spec/spec_base.rb +16 -0
- data/spec/tokyo_tyrant_query_spec.rb +71 -0
- data/spec/tokyo_tyrant_spec.rb +180 -0
- data/spec/tokyo_tyrant_table_spec.rb +190 -0
- metadata +24 -1
data/spec/spec_base.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require 'pathname'
|
3
|
+
$root = Pathname(__FILE__).dirname
|
4
|
+
|
5
|
+
$:.unshift $root
|
6
|
+
$:.unshift $root.parent.join('ext').expand_path
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'bacon'
|
11
|
+
require 'tokyo_tyrant'
|
12
|
+
|
13
|
+
$root.class.glob('spec/*_spec.rb').each {|l| load l}
|
14
|
+
|
15
|
+
puts "\n#{Bacon.summary_on_exit}"
|
16
|
+
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.join('spec_base') unless $root
|
3
|
+
|
4
|
+
describe TokyoTyrant::Query, "with an open database" do
|
5
|
+
@db = TokyoTyrant::Table.new('127.0.0.1', 45001)
|
6
|
+
@db.clear
|
7
|
+
load('plu_db.rb')
|
8
|
+
@db.mput($codes)
|
9
|
+
|
10
|
+
it "should get a query object" do
|
11
|
+
@db.query.class.should == TokyoTyrant::Query
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should get keys for search conditions" do
|
15
|
+
q = @db.query
|
16
|
+
q.addcond('type', :streq, 'Spinach')
|
17
|
+
q.search.sort.should == %w[3332 34173]
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should get keys for negated search conditions" do
|
21
|
+
q = @db.query
|
22
|
+
q.addcond('type', '!streq', 'Spinach')
|
23
|
+
res = q.search
|
24
|
+
%w[3332 34173].each do |k|
|
25
|
+
res.should.not.include?(k)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get ordered keys for search conditions with ascending order" do
|
30
|
+
q = @db.query
|
31
|
+
q.addcond('type', :streq, 'Spinach')
|
32
|
+
q.setorder('variety', :strasc)
|
33
|
+
q.search.should == ["3332", "34173"]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should get ordered keys for search conditions with decending order" do
|
37
|
+
q = @db.query
|
38
|
+
q.addcond('type', :streq, 'Spinach')
|
39
|
+
q.order_by('variety', :strdesc)
|
40
|
+
q.search.should == ["34173", "3332"]
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should get limited keys for search conditions with limit" do
|
44
|
+
q = @db.query
|
45
|
+
q.addcond('type', :streq, 'Apple')
|
46
|
+
q.setmax(10)
|
47
|
+
q.search.sort.should == ["3072", "3073", "3074", "3075", "3076", "3077", "3078", "3348", "3349", "4182"]
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should get records for search conditions" do
|
51
|
+
q = @db.query
|
52
|
+
q.addcond('type', :streq, 'Garlic')
|
53
|
+
res = q.get.sort{ |x,y| x[:variety] <=> y[:variety] }
|
54
|
+
res.should == [{ :__id => "4609", :variety => "Elephant", :code => "4609", :type => "Garlic" },
|
55
|
+
{ :__id => "3401", :variety => "One-clove types", :code => "3401", :type => "Garlic" },
|
56
|
+
{ :__id => "3052", :variety => "String", :code => "3052", :type => "Garlic" }]
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should remove records for conditions" do
|
60
|
+
q = @db.query
|
61
|
+
q.addcond(:type, :streq, 'Orange')
|
62
|
+
q.search.size.should == 11
|
63
|
+
q.searchout.should.be.true
|
64
|
+
q.search.size.should == 0
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should chain search options" do
|
68
|
+
res = @db.query.condition(:type, :streq, 'Cucumber').order_by(:variety, :strdesc).limit(3).search
|
69
|
+
res.should == ["4596", "4595", "4594"]
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.join('spec_base') unless $root
|
3
|
+
|
4
|
+
describe TokyoTyrant::DB, "with an open database" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@db = TokyoTyrant::DB.new('127.0.0.1', 45000)
|
8
|
+
@db.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not be nil" do
|
12
|
+
@db.should.not.be.nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should close" do
|
16
|
+
@db.close.should.be.true
|
17
|
+
begin
|
18
|
+
@db.close
|
19
|
+
rescue => e
|
20
|
+
e.message.should == 'close error: invalid operation'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should save a value" do
|
25
|
+
@db[:salad] = 'bacon bits'
|
26
|
+
@db[:salad].should == 'bacon bits'
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return a value" do
|
30
|
+
@db[:salad] = 'bacon bits'
|
31
|
+
@db[:salad].should == 'bacon bits'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should save multiple values" do
|
35
|
+
h = { 'pizza' => 'old forge style',
|
36
|
+
'sandwich' => 'peanut butter jelly',
|
37
|
+
'yogurt' => 'greek',
|
38
|
+
'coffee' => 'black' }
|
39
|
+
@db.mput(h).should.be.empty
|
40
|
+
h.each_pair do |k,v|
|
41
|
+
@db[k].should == v
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get multiple values" do
|
46
|
+
h = { 'pizza' => 'old forge style',
|
47
|
+
'sandwich' => 'peanut butter jelly',
|
48
|
+
'yogurt' => 'greek',
|
49
|
+
'coffee' => 'black' }
|
50
|
+
@db.mput(h)
|
51
|
+
@db.mget(h.keys).should == h
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should out a value" do
|
55
|
+
k = :tomato
|
56
|
+
@db[k] = 'green'
|
57
|
+
@db.out(k).should.be.true
|
58
|
+
@db[k].should.be.nil
|
59
|
+
@db.out(k).should.be.false
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should get a value size" do
|
63
|
+
k = :cereal
|
64
|
+
v = 'granola'
|
65
|
+
@db[k] = v
|
66
|
+
@db.vsiz(k).should == v.size
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should check a key" do
|
70
|
+
k = :fruit
|
71
|
+
@db[k] = 'banana'
|
72
|
+
@db.check(k).should.be.true
|
73
|
+
@db.out(k)
|
74
|
+
@db.check(k).should.be.false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should iterate" do
|
78
|
+
@db[:cheese] = 'gouda'
|
79
|
+
@db[:grapes] = 'green'
|
80
|
+
@db[:oranges] = 'florida'
|
81
|
+
@db[:crackers] = 'triscuit'
|
82
|
+
|
83
|
+
@db.iterinit.should.be.true
|
84
|
+
@db.iternext.should == 'cheese'
|
85
|
+
@db.iternext.should == 'grapes'
|
86
|
+
@db.iternext.should == 'oranges'
|
87
|
+
@db.iternext.should == 'crackers'
|
88
|
+
@db.iternext.should == nil
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should get forward matching keys" do
|
92
|
+
@db['apples/royalgala'] = '4173'
|
93
|
+
@db['apples/grannysmith'] = '4139'
|
94
|
+
@db['bananas/yellow'] = '4011'
|
95
|
+
@db['oranges/shamouti'] = '3027'
|
96
|
+
@db['grapefruit/deepred'] = '4288'
|
97
|
+
@db.fwmkeys('apples').sort.should == ["apples/grannysmith", "apples/royalgala"]
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should get all keys" do
|
101
|
+
keys = %w[appetizers entree dessert]
|
102
|
+
values = %w[chips chicken\ caeser\ salad ice\ cream]
|
103
|
+
keys.each_with_index do |k,i|
|
104
|
+
@db[k] = values[i]
|
105
|
+
end
|
106
|
+
@db.keys.should == keys
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should get all values" do
|
110
|
+
keys = %w[appetizers entree dessert]
|
111
|
+
values = %w[chips chicken\ caeser\ salad ice\ cream]
|
112
|
+
keys.each_with_index do |k,i|
|
113
|
+
@db[k] = values[i]
|
114
|
+
end
|
115
|
+
@db.values.should == values
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should vanish all records" do
|
119
|
+
@db['chocolate'] = 'dark'
|
120
|
+
@db['tea'] = 'earl grey'
|
121
|
+
@db.empty?.should.be.false
|
122
|
+
@db.vanish.should.be.true
|
123
|
+
@db.empty?.should.be.true
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should count records" do
|
127
|
+
@db['hummus'] = 'chickpeas'
|
128
|
+
@db['falafel'] = 'chickpeas'
|
129
|
+
@db.rnum.should == 2
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should report db size" do
|
133
|
+
@db['rootbeer'] = 'virgils'
|
134
|
+
@db.size.should == 528736
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should fetch a record" do
|
138
|
+
@db.out('beer')
|
139
|
+
@db.fetch('beer','heineken').should == 'heineken'
|
140
|
+
@db['beer'] = 'heineken'
|
141
|
+
@db.fetch('beer','becks').should == 'heineken'
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should iterate through records" do
|
145
|
+
keys = %w[grapejuice tacoshells rice]
|
146
|
+
values = %w[Kedem Ortega Uncle\ Ben]
|
147
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
148
|
+
|
149
|
+
i = 0
|
150
|
+
@db.each do |k,v|
|
151
|
+
k.should == keys[i]
|
152
|
+
v.should == values[i]
|
153
|
+
i = i += 1
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should iterate through keys" do
|
158
|
+
keys = %w[burritos fajitas tacos tostas enchiladas]
|
159
|
+
values = Array.new(keys.size, 'yum')
|
160
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
161
|
+
|
162
|
+
i = 0
|
163
|
+
@db.each_key do |k|
|
164
|
+
k.should == keys[i]
|
165
|
+
i = i += 1
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should iterate through values" do
|
170
|
+
keys = %w[falafel humus couscous tabbouleh tzatziki]
|
171
|
+
values = %w[chickpeas chickpeas semolina bulgar yogurt]
|
172
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
173
|
+
|
174
|
+
i = 0
|
175
|
+
@db.each_value do |v|
|
176
|
+
v.should == values[i]
|
177
|
+
i = i += 1
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require Pathname(__FILE__).dirname.join('spec_base') unless $root
|
3
|
+
|
4
|
+
describe TokyoTyrant::Table, "with an open database" do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@db = TokyoTyrant::Table.new('127.0.0.1', 45001)
|
8
|
+
@db.clear
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not be nil" do
|
12
|
+
@db.should.not.be.nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should close" do
|
16
|
+
@db.close.should.be.true
|
17
|
+
begin
|
18
|
+
@db.close
|
19
|
+
rescue => e
|
20
|
+
e.message.should == 'close error: invalid operation'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should save a value" do
|
25
|
+
value = { :lettuce => 'Red Leaf', :dressing => 'ranch', :extra => 'bacon bits' }
|
26
|
+
@db[:salad] = value
|
27
|
+
@db[:salad].should == value
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should return a value" do
|
31
|
+
value = { :lettuce => 'Red Leaf', :dressing => 'ranch', :extra => 'bacon bits' }
|
32
|
+
@db[:salad] = value
|
33
|
+
@db[:salad].should == value
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should save multiple values" do
|
37
|
+
h = { 'pizza' => { :best => 'old forge style', :ok => 'new york style', :worst => 'chicago style' },
|
38
|
+
'sandwich' => { :best => 'peanut butter jelly', :ok => 'turkey', :worst => 'olive loaf' },
|
39
|
+
'yogurt' => { :best => 'greek', :ok => 'organic', :worst => '+hfcs' },
|
40
|
+
'coffee' => { :best => 'black', :ok => 'espresso', :worst => 'latte' } }
|
41
|
+
|
42
|
+
@db.mput(h).should.be.empty
|
43
|
+
h.each_pair do |k,v|
|
44
|
+
@db[k].should == v
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should get multiple values" do
|
49
|
+
h = { 'pizza' => { :best => 'old forge style', :ok => 'new york style', :worst => 'chicago style' },
|
50
|
+
'sandwich' => { :best => 'peanut butter jelly', :ok => 'turkey', :worst => 'olive loaf' },
|
51
|
+
'yogurt' => { :best => 'greek', :ok => 'organic', :worst => '+hfcs' },
|
52
|
+
'coffee' => { :best => 'black', :ok => 'espresso', :worst => 'latte' } }
|
53
|
+
|
54
|
+
@db.mput(h)
|
55
|
+
@db.mget(h.keys).should == h
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should out a value" do
|
59
|
+
k = :tomato
|
60
|
+
@db[k] = { :color => 'red', :variety => 'beefy' }
|
61
|
+
@db.out(k).should.be.true
|
62
|
+
@db[k].should.be.nil
|
63
|
+
@db.out(k).should.be.false
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should check a key" do
|
67
|
+
k = :fruit
|
68
|
+
@db[k] = { :name => 'banana', :code => '4011' }
|
69
|
+
@db.check(k).should.be.true
|
70
|
+
@db.out(k)
|
71
|
+
@db.check(k).should.be.false
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should iterate" do
|
75
|
+
@db[:cheese] = { :melty => 'gouda', :sharp => 'cheddar', :stringy => 'mozerella' }
|
76
|
+
@db[:grapes] = { :sour => 'green', :big => 'red', :wine => 'purple' }
|
77
|
+
@db[:oranges] = { :juicy => 'florida', :yellow => 'california' }
|
78
|
+
@db[:crackers] = { :wheat => 'triscuit', :snack => 'ritz', :soup => 'saltine' }
|
79
|
+
|
80
|
+
@db.iterinit.should.be.true
|
81
|
+
@db.iternext.should == 'cheese'
|
82
|
+
@db.iternext.should == 'grapes'
|
83
|
+
@db.iternext.should == 'oranges'
|
84
|
+
@db.iternext.should == 'crackers'
|
85
|
+
@db.iternext.should == nil
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should get forward matching keys" do
|
89
|
+
@db['apples/royalgala'] = { :code => '4173', :color => 'red-yellow' }
|
90
|
+
@db['apples/grannysmith'] = { :code => '4139', :color => 'green' }
|
91
|
+
@db['bananas/yellow'] = { :code => '4011', :color => 'yellow' }
|
92
|
+
@db['oranges/shamouti'] = { :code => '3027', :color => 'orange' }
|
93
|
+
@db['grapefruit/deepred'] = { :code => '4288', :color => 'yellow/pink' }
|
94
|
+
@db.fwmkeys('apples').sort.should == ["apples/grannysmith", "apples/royalgala"]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should get all keys" do
|
98
|
+
keys = %w[appetizers entree dessert]
|
99
|
+
values = [{ :cheap => 'chips', :expensive => 'sample everything platter' },
|
100
|
+
{ :cheap => 'hoagie', :expensive => 'steak' },
|
101
|
+
{ :cheap => 'water ice', :expensive => 'cheesecake' }]
|
102
|
+
|
103
|
+
keys.each_with_index do |k,i|
|
104
|
+
@db[k] = values[i]
|
105
|
+
end
|
106
|
+
@db.keys.should == keys
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should get all values" do
|
110
|
+
keys = %w[appetizers entree dessert]
|
111
|
+
values = [{ :cheap => 'chips', :expensive => 'sample everything platter' },
|
112
|
+
{ :cheap => 'hoagie', :expensive => 'steak' },
|
113
|
+
{ :cheap => 'water ice', :expensive => 'cheesecake' }]
|
114
|
+
|
115
|
+
keys.each_with_index do |k,i|
|
116
|
+
@db[k] = values[i]
|
117
|
+
end
|
118
|
+
@db.values.should == values
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should vanish all records" do
|
122
|
+
@db['chocolate'] = { :type => 'dark' }
|
123
|
+
@db['tea'] = { :type => 'earl grey' }
|
124
|
+
@db.empty?.should.be.false
|
125
|
+
@db.vanish.should.be.true
|
126
|
+
@db.empty?.should.be.true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should count records" do
|
130
|
+
@db['hummus'] = { :ingredients => 'chickpeas,garlic' }
|
131
|
+
@db['falafel'] = { :ingredients => 'chickpeas,herbs' }
|
132
|
+
@db.rnum.should == 2
|
133
|
+
end
|
134
|
+
|
135
|
+
it "should report db size" do
|
136
|
+
@db['rootbeer'] = { :gourmet => 'Virgils', :natural => 'Hansens' }
|
137
|
+
@db.size.should == 528768
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should fetch a record" do
|
141
|
+
@db.out('beer')
|
142
|
+
@db.fetch('beer', { :import => 'heineken' }).should == { :import => 'heineken' }
|
143
|
+
@db['beer'] = { :import => 'heineken' }
|
144
|
+
@db.fetch('beer', { :import => 'becks' }).should == { :import => 'heineken' }
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should iterate through records" do
|
148
|
+
keys = %w[grapejuice tacoshells rice]
|
149
|
+
values = [{ :purple => 'Kedem', :green => 'Juicy Juice' },
|
150
|
+
{ :crunchy => 'Ortega', :soft => 'Taco Bell' },
|
151
|
+
{ :brown => 'Instant', :white => 'Uncle Ben' }]
|
152
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
153
|
+
|
154
|
+
i = 0
|
155
|
+
@db.each do |k,v|
|
156
|
+
k.should == keys[i]
|
157
|
+
v.should == values[i]
|
158
|
+
i = i += 1
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should iterate through keys" do
|
163
|
+
keys = %w[burritos fajitas tacos tostas enchiladas]
|
164
|
+
values = Array.new(keys.size, { :tasty => 'yes' })
|
165
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
166
|
+
|
167
|
+
i = 0
|
168
|
+
@db.each_key do |k|
|
169
|
+
k.should == keys[i]
|
170
|
+
i = i += 1
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should iterate through values" do
|
175
|
+
keys = %w[falafel humus couscous tabbouleh tzatziki]
|
176
|
+
values = [{ :ingredient => 'chickpeas' },
|
177
|
+
{ :ingredient => 'chickpeas' },
|
178
|
+
{ :ingredient => 'semolina' },
|
179
|
+
{ :ingredient => 'bulgar' },
|
180
|
+
{ :ingredient => 'yogurt' }]
|
181
|
+
|
182
|
+
keys.each_with_index{ |k,i| @db[k] = values[i] }
|
183
|
+
|
184
|
+
i = 0
|
185
|
+
@db.each_value do |v|
|
186
|
+
v.should == values[i]
|
187
|
+
i = i += 1
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|