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.
- data/.gitignore +4 -0
- data/CHANGELOG.txt +6 -0
- data/Rakefile +91 -0
- data/doc/decision_table.numbers +0 -0
- data/lib/rufus/edo/README.txt +101 -0
- data/lib/rufus/edo/tabcore.rb +1 -3
- data/lib/rufus/tokyo.rb +1 -2
- data/lib/rufus/tokyo/cabinet/lib.rb +4 -7
- data/lib/rufus/tokyo/cabinet/table.rb +10 -13
- data/lib/rufus/tokyo/cabinet/util.rb +4 -1
- data/lib/rufus/tokyo/hmethods.rb +4 -4
- data/lib/rufus/tokyo/outlen.rb +5 -1
- data/lib/rufus/tokyo/tyrant/abstract.rb +8 -0
- data/lib/rufus/tokyo/tyrant/lib.rb +6 -6
- data/lib/rufus/tokyo/tyrant/table.rb +9 -1
- data/lib/rufus/tokyo/version.rb +32 -0
- data/rufus-tokyo.gemspec +135 -0
- data/spec/cabinet_btree_spec.rb +92 -0
- data/spec/cabinet_fixed_spec.rb +33 -0
- data/spec/cabinet_spec.rb +291 -0
- data/spec/cabinetconfig_spec.rb +82 -0
- data/spec/dystopia_core_spec.rb +124 -0
- data/spec/edo_cabinet_btree_spec.rb +123 -0
- data/spec/edo_cabinet_fixed_spec.rb +42 -0
- data/spec/edo_cabinet_spec.rb +286 -0
- data/spec/edo_ntyrant_spec.rb +224 -0
- data/spec/edo_ntyrant_table_spec.rb +296 -0
- data/spec/edo_table_spec.rb +292 -0
- data/spec/hmethods_spec.rb +73 -0
- data/spec/incr.lua +23 -0
- data/spec/openable_spec.rb +51 -0
- data/spec/shared_abstract_spec.rb +426 -0
- data/spec/shared_table_spec.rb +675 -0
- data/spec/shared_tyrant_spec.rb +42 -0
- data/spec/spec_base.rb +23 -0
- data/spec/start_tyrants.sh +28 -0
- data/spec/stop_tyrants.sh +9 -0
- data/spec/table_spec.rb +267 -0
- data/spec/tyrant_spec.rb +218 -0
- data/spec/tyrant_table_spec.rb +298 -0
- data/spec/util_list_spec.rb +197 -0
- data/spec/util_map_spec.rb +130 -0
- data/tasks/dev.rb +70 -0
- data/test/bm0.rb +353 -0
- data/test/bm1_compression.rb +54 -0
- data/test/con0.rb +30 -0
- data/test/mem.rb +49 -0
- data/test/mem1.rb +44 -0
- data/test/readme0.rb +17 -0
- data/test/readme1.rb +21 -0
- data/test/readme2.rb +15 -0
- data/test/readme3.rb +24 -0
- data/test/readmes_test.sh +17 -0
- metadata +81 -21
- data/MIGRATED.txt +0 -1
@@ -0,0 +1,82 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Specifying rufus-tokyo
|
4
|
+
#
|
5
|
+
# Sun Feb 8 16:01:51 JST 2009
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/spec_base'
|
9
|
+
|
10
|
+
require 'rufus/tokyo'
|
11
|
+
|
12
|
+
|
13
|
+
describe 'Rufus::Tokyo::CabinetConfig' do
|
14
|
+
|
15
|
+
before do
|
16
|
+
@c = Object.new
|
17
|
+
@c.extend(Rufus::Tokyo::CabinetConfig)
|
18
|
+
class << @c
|
19
|
+
public :determine_open_mode, :determine_conf
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should open with mode=cw by default' do
|
24
|
+
|
25
|
+
@c.determine_open_mode({ :mode => ''}).should.equal(6)
|
26
|
+
@c.determine_open_mode({ 'mode' => '' }).should.equal(6)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should determine mode flags correctly' do
|
30
|
+
|
31
|
+
@c.determine_open_mode( :mode => 'e').should.equal(16)
|
32
|
+
@c.determine_open_mode( :mode => 're').should.equal(17)
|
33
|
+
@c.determine_open_mode( :mode => 'ce').should.equal(20)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should separate path from params' do
|
37
|
+
|
38
|
+
@c.determine_conf(
|
39
|
+
'nada.tdb#mode=r', {}, '.tdb')[:path].should.equal('nada.tdb')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should not accept suffixes else than .tdb' do
|
43
|
+
|
44
|
+
lambda {
|
45
|
+
@c.determine_conf('nada.tcx', {}, '.tdb').should.be.nil
|
46
|
+
}.should.raise(RuntimeError)
|
47
|
+
|
48
|
+
lambda {
|
49
|
+
@c.determine_conf('nada.tcx#mode=r', {}, '.tdb').should.be.nil
|
50
|
+
}.should.raise(RuntimeError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should grant write/create by default' do
|
54
|
+
|
55
|
+
@c.determine_conf('nada.tdb', {}, '.tdb')[:mode].should.equal(6)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should respect :mutex' do
|
59
|
+
|
60
|
+
@c.determine_conf(
|
61
|
+
'nada.tdb#mutex=true', {}, '.tdb')[:mutex].should.equal(true)
|
62
|
+
@c.determine_conf(
|
63
|
+
'nada.tdb', { :mutex => true}, '.tdb')[:mutex].should.equal(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should compute opts correctly' do
|
67
|
+
|
68
|
+
@c.determine_conf('nada.tdb', {}, '.tdb')[:opts].should.equal(0)
|
69
|
+
@c.determine_conf('nada.tdb#opts=ld', {}, '.tdb')[:opts].should.equal(3)
|
70
|
+
@c.determine_conf('nada.tdb', { :opts => 'ld' }, '.tdb')[:opts].should.equal(3)
|
71
|
+
@c.determine_conf('nada.tdb#opts=lb', {}, '.tdb')[:opts].should.equal(5)
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should accept :dfunit (TC 1.4.21)' do
|
75
|
+
|
76
|
+
@c.determine_conf('nada.tdb', {}, '.tdb')[:dfunit].should.equal(0)
|
77
|
+
@c.determine_conf('nada.tch#dfunit=8', {}, '.tch')[:dfunit].should.equal(8)
|
78
|
+
@c.determine_conf('nada.tct#dfunit=8', {}, '.tdb')[:dfunit].should.equal(8)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
@@ -0,0 +1,124 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Specifying rufus-tokyo
|
4
|
+
#
|
5
|
+
require File.dirname(__FILE__) + '/spec_base'
|
6
|
+
|
7
|
+
require 'rufus/tokyo/dystopia'
|
8
|
+
|
9
|
+
FileUtils.mkdir('tmp') rescue nil
|
10
|
+
|
11
|
+
describe Rufus::Tokyo::Dystopia::Core do
|
12
|
+
after do
|
13
|
+
FileUtils.rm_rf( 'tmp/dystopia' )
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should use open with a block will auto close the db correctly' do
|
17
|
+
res = Rufus::Tokyo::Dystopia::Core.open('tmp/dystopia') do |index|
|
18
|
+
index.store( 1, "John Adams" )
|
19
|
+
index.store( 3, "George Washington" )
|
20
|
+
index.count.should.equal( 2 )
|
21
|
+
:result
|
22
|
+
end
|
23
|
+
|
24
|
+
res.should.equal(:result)
|
25
|
+
|
26
|
+
index = Rufus::Tokyo::Dystopia::Core.new('tmp/dystopia')
|
27
|
+
r = index.search( "John" )
|
28
|
+
r.size.should.equal( 1 )
|
29
|
+
r.should.equal( [ 1 ] )
|
30
|
+
index.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should use open without a block just like calling new correctly' do
|
34
|
+
index = Rufus::Tokyo::Dystopia::Core.open('tmp/dystopia')
|
35
|
+
index.store( 1, "John Adams" )
|
36
|
+
index.store( 3, "George Washington" )
|
37
|
+
index.count.should.equal( 2 )
|
38
|
+
index.close
|
39
|
+
|
40
|
+
index = Rufus::Tokyo::Dystopia::Core.new('tmp/dystopia')
|
41
|
+
r = index.search( "John" )
|
42
|
+
r.size.should.equal( 1 )
|
43
|
+
r.should.equal( [ 1 ] )
|
44
|
+
index.close
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'Rufus::Tokyo::Dystopia::Core' do
|
49
|
+
before do
|
50
|
+
@db = Rufus::Tokyo::Dystopia::Core.new( 'tmp/dystopia' )
|
51
|
+
@db.clear
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
@db.close
|
56
|
+
FileUtils.rm_rf( 'tmp/dystopia' )
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'creates a new directory when started' do
|
60
|
+
File.directory?( 'tmp/dystopia' ).should.equal( true )
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'knows its own full path' do
|
64
|
+
p = @db.path
|
65
|
+
File.directory?( p ).should.equal( true )
|
66
|
+
p.should.equal( File.expand_path( "tmp/dystopia" ) )
|
67
|
+
end
|
68
|
+
|
69
|
+
it "knows its record count" do
|
70
|
+
@db.count.should.equal( 0 )
|
71
|
+
@db.store( 1, "John Adams" )
|
72
|
+
@db.count.should.equal( 1 )
|
73
|
+
end
|
74
|
+
|
75
|
+
it "knows how much drive space it takes up in bytes" do
|
76
|
+
b = @db.fsize
|
77
|
+
@db.store( 1, "John Adams" )
|
78
|
+
@db.store( 3, "George Washington" )
|
79
|
+
@db.fsize.should > b
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can add records" do
|
83
|
+
@db.count.should.equal(0)
|
84
|
+
@db.store( 1, "John Adams" )
|
85
|
+
@db.store( 3, "George Washington" )
|
86
|
+
@db.count.should.equal( 2 )
|
87
|
+
end
|
88
|
+
|
89
|
+
it "can remove records" do
|
90
|
+
@db.count.should.equal(0)
|
91
|
+
@db.store( 1, "John Adams" )
|
92
|
+
@db.store( 3, "George Washington" )
|
93
|
+
@db.count.should.equal( 2 )
|
94
|
+
@db.delete( 3 )
|
95
|
+
@db.count.should.equal( 1 )
|
96
|
+
end
|
97
|
+
|
98
|
+
it "retrieves the whole record of items it has stored" do
|
99
|
+
@db.store( 1, "John Adams" )
|
100
|
+
@db.store( 3, "George Washington" )
|
101
|
+
|
102
|
+
@db.fetch( 3 ).should.equal( "George Washington" )
|
103
|
+
@db.fetch( 1 ).should.equal( "John Adams" )
|
104
|
+
end
|
105
|
+
|
106
|
+
it "returns nil when the fetched document does not exist" do
|
107
|
+
@db.store( 1, "John Adams" )
|
108
|
+
@db.count.should.equal( 1 )
|
109
|
+
@db.fetch( 3 ).should.be.nil
|
110
|
+
end
|
111
|
+
|
112
|
+
it "searches for text in the database" do
|
113
|
+
[ 'John Adams', 'George Washington', 'Thomas Jefferson' ].each_with_index do |e, idx|
|
114
|
+
@db.store( idx + 1, e )
|
115
|
+
end
|
116
|
+
r = @db.search( "on" )
|
117
|
+
r.size.should.equal( 2 )
|
118
|
+
r.sort.should.equal( [ 2, 3 ] )
|
119
|
+
|
120
|
+
r = @db.search( "John" )
|
121
|
+
r.size.should.equal( 1 )
|
122
|
+
r.should.equal( [ 1 ] )
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Specifying rufus-tokyo
|
4
|
+
#
|
5
|
+
# Fri Aug 28 08:58:37 JST 2009
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/spec_base'
|
9
|
+
|
10
|
+
begin
|
11
|
+
require 'rufus/edo'
|
12
|
+
rescue LoadError
|
13
|
+
puts "'TokyoCabinet' ruby bindings not available on this ruby platform"
|
14
|
+
end
|
15
|
+
|
16
|
+
DB_FILE = "tmp/edo_cabinet_btree_spec.tcb"
|
17
|
+
|
18
|
+
if defined?(TokyoCabinet)
|
19
|
+
|
20
|
+
FileUtils.mkdir('tmp') rescue nil
|
21
|
+
|
22
|
+
|
23
|
+
describe 'Rufus::Edo::Cabinet .tcb' do
|
24
|
+
|
25
|
+
before do
|
26
|
+
FileUtils.rm(DB_FILE) if File.exist? DB_FILE
|
27
|
+
@db = Rufus::Edo::Cabinet.new(DB_FILE)
|
28
|
+
end
|
29
|
+
after do
|
30
|
+
@db.close
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should accept duplicate values' do
|
34
|
+
|
35
|
+
@db.putdup('a', 'a0')
|
36
|
+
@db.putdup('a', 'a1')
|
37
|
+
|
38
|
+
@db.getdup('a').should.equal([ 'a0', 'a1' ])
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should be able to fetch keys for duplicate values' do
|
42
|
+
[ %w[John Hornbeck],
|
43
|
+
%w[Tim Gourley],
|
44
|
+
%w[Grant Schofield],
|
45
|
+
%w[James Gray],
|
46
|
+
%w[Dana Gray] ].each do |first, last|
|
47
|
+
@db.putdup(last, first)
|
48
|
+
end
|
49
|
+
@db.keys.should.equal(%w[Gourley Gray Hornbeck Schofield])
|
50
|
+
@db.keys(:prefix => "G").should.equal(%w[Gourley Gray])
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'Rufus::Edo::Cabinet .tcb methods' do
|
55
|
+
|
56
|
+
it 'should fail on other structures' do
|
57
|
+
|
58
|
+
@db = Rufus::Edo::Cabinet.new(DB_FILE.sub(/\.tcb\z/, ".tch"))
|
59
|
+
|
60
|
+
lambda { @db.putdup('a', 'a0') }.should.raise(NoMethodError)
|
61
|
+
|
62
|
+
@db.close
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'Rufus::Edo::Cabinet .tcb order' do
|
67
|
+
|
68
|
+
before do
|
69
|
+
FileUtils.rm(DB_FILE) if File.exist? DB_FILE
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should default to a lexical order' do
|
73
|
+
|
74
|
+
db = Rufus::Edo::Cabinet.new(DB_FILE)
|
75
|
+
fields = [1, 2, 10, 11, 20, 21]
|
76
|
+
fields.each do |n|
|
77
|
+
db[n] = n
|
78
|
+
end
|
79
|
+
db.keys.should.equal(fields.map { |n| n.to_s }.sort)
|
80
|
+
db.close
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should allow an explicit :cmpfunc => :lexical' do
|
84
|
+
|
85
|
+
db = Rufus::Edo::Cabinet.new(DB_FILE, :cmpfunc => :lexical)
|
86
|
+
fields = [1, 2, 10, 11, 20, 21]
|
87
|
+
fields.each do |n|
|
88
|
+
db[n] = n
|
89
|
+
end
|
90
|
+
db.keys.should.equal(fields.map { |n| n.to_s }.sort)
|
91
|
+
db.close
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should allow a :cmpfunc => :decimal' do
|
95
|
+
|
96
|
+
db = Rufus::Edo::Cabinet.new(DB_FILE, :cmpfunc => :decimal)
|
97
|
+
fields = [1, 2, 10, 11, 20, 21]
|
98
|
+
fields.each do |n|
|
99
|
+
db[n] = n
|
100
|
+
end
|
101
|
+
db.keys.should.equal(fields.sort.map { |n| n.to_s })
|
102
|
+
db.close
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should allow a custom :cmpfunc as a Proc' do
|
106
|
+
|
107
|
+
db = Rufus::Edo::Cabinet.new(
|
108
|
+
DB_FILE,
|
109
|
+
:cmpfunc => lambda { |a, b| [a.size, a] <=> [b.size, b] }
|
110
|
+
)
|
111
|
+
db["one"] = 1
|
112
|
+
db["two"] = 2
|
113
|
+
db["three"] = 3
|
114
|
+
db["four"] = 4
|
115
|
+
db["five"] = 5
|
116
|
+
db.to_a.should.equal( [ %w[one 1], %w[two 2],
|
117
|
+
%w[five 5], %w[four 4],
|
118
|
+
%w[three 3] ] )
|
119
|
+
db.close
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_base'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rufus/edo'
|
5
|
+
rescue LoadError
|
6
|
+
puts "'TokyoCabinet' ruby bindings not available on this ruby platform"
|
7
|
+
end
|
8
|
+
|
9
|
+
if defined?(TokyoCabinet)
|
10
|
+
|
11
|
+
FileUtils.mkdir('tmp') rescue nil
|
12
|
+
|
13
|
+
|
14
|
+
describe 'Rufus::Edo::Cabinet .tcf' do
|
15
|
+
|
16
|
+
before do
|
17
|
+
@db = Rufus::Edo::Cabinet.new( 'tmp/edo_cabinet_fixed_spec.tcf',
|
18
|
+
:width => 4 )
|
19
|
+
@db.clear
|
20
|
+
end
|
21
|
+
after do
|
22
|
+
@db.close
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should support keys' do
|
26
|
+
@db[1] = "one"
|
27
|
+
@db[2] = "two"
|
28
|
+
@db[3] = "three"
|
29
|
+
@db[7] = "seven"
|
30
|
+
@db.keys.should.equal(%w[1 2 3 7])
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should accept a width at creation' do
|
34
|
+
|
35
|
+
@db[1] = "one"
|
36
|
+
@db[2] = "two"
|
37
|
+
@db[3] = "three"
|
38
|
+
@db.to_a.should.equal([%w[1 one], %w[2 two], %w[3 thre]])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,286 @@
|
|
1
|
+
|
2
|
+
#
|
3
|
+
# Specifying rufus-tokyo
|
4
|
+
#
|
5
|
+
# Sat Feb 21 22:16:23 JST 2009
|
6
|
+
#
|
7
|
+
|
8
|
+
require File.dirname(__FILE__) + '/spec_base'
|
9
|
+
require File.dirname(__FILE__) + '/shared_abstract_spec'
|
10
|
+
|
11
|
+
begin
|
12
|
+
require 'rufus/edo'
|
13
|
+
rescue LoadError
|
14
|
+
puts "'TokyoCabinet' ruby bindings not available on this ruby platform"
|
15
|
+
end
|
16
|
+
|
17
|
+
if defined?(TokyoCabinet)
|
18
|
+
|
19
|
+
FileUtils.mkdir('tmp') rescue nil
|
20
|
+
|
21
|
+
describe 'a missing Rufus::Edo::Cabinet' do
|
22
|
+
|
23
|
+
it 'should raise an error' do
|
24
|
+
|
25
|
+
lambda {
|
26
|
+
Rufus::Edo::Cabinet.new('tmp/naidesuyo.tch', :mode => 'r')
|
27
|
+
}.should.raise(Rufus::Edo::EdoError).message.should.equal(
|
28
|
+
'(err 3) file not found')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe Rufus::Edo::Cabinet do
|
33
|
+
|
34
|
+
before do
|
35
|
+
@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_spec.tch')
|
36
|
+
@db.clear
|
37
|
+
end
|
38
|
+
after do
|
39
|
+
@db.close
|
40
|
+
end
|
41
|
+
|
42
|
+
behaves_like "an abstract structure"
|
43
|
+
|
44
|
+
it 'should return its path' do
|
45
|
+
|
46
|
+
@db.path.should.equal('tmp/edo_cabinet_spec.tch')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should create its underlying file' do
|
50
|
+
|
51
|
+
File.exist?('tmp/cabinet_spec.tch').should.equal(true)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'Rufus::Edo::Cabinet #keys' do
|
56
|
+
|
57
|
+
before do
|
58
|
+
@n = 50
|
59
|
+
@db = Rufus::Edo::Cabinet.new('tmp/cabinet_spec.tch')
|
60
|
+
@db.clear
|
61
|
+
@n.times { |i| @db["person#{i}"] = 'whoever' }
|
62
|
+
@n.times { |i| @db["animal#{i}"] = 'whichever' }
|
63
|
+
@db["toto#{0.chr}5"] = 'toto'
|
64
|
+
end
|
65
|
+
after do
|
66
|
+
@db.close
|
67
|
+
end
|
68
|
+
|
69
|
+
behaves_like 'abstract structure #keys'
|
70
|
+
end
|
71
|
+
|
72
|
+
describe Rufus::Edo::Cabinet do
|
73
|
+
|
74
|
+
before do
|
75
|
+
@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_tran_spec.tch')
|
76
|
+
@db.clear
|
77
|
+
end
|
78
|
+
after do
|
79
|
+
@db.close
|
80
|
+
end
|
81
|
+
|
82
|
+
behaves_like 'abstract structure with transactions'
|
83
|
+
end
|
84
|
+
|
85
|
+
describe Rufus::Edo::Cabinet do
|
86
|
+
|
87
|
+
it 'should accept a default value' do
|
88
|
+
|
89
|
+
cab = Rufus::Edo::Cabinet.new(
|
90
|
+
'tmp/cabinet_spec_default.tch', :default => '@?!')
|
91
|
+
cab['a'] = 'A'
|
92
|
+
cab.size.should.equal(1)
|
93
|
+
cab['b'].should.equal('@?!')
|
94
|
+
cab.close
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should accept a default value (later)' do
|
98
|
+
|
99
|
+
cab = Rufus::Edo::Cabinet.new('tmp/cabinet_spec_default.tch')
|
100
|
+
cab.default = '@?!'
|
101
|
+
cab['a'] = 'A'
|
102
|
+
cab.size.should.equal(1)
|
103
|
+
cab['b'].should.equal('@?!')
|
104
|
+
cab.close
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe Rufus::Edo::Cabinet do
|
109
|
+
|
110
|
+
before do
|
111
|
+
@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_spec.tch')
|
112
|
+
#@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_spec.tch', :type => :abstract)
|
113
|
+
@db.clear
|
114
|
+
3.times { |i| @db[i.to_s] = "val#{i}" }
|
115
|
+
end
|
116
|
+
after do
|
117
|
+
@db.close
|
118
|
+
end
|
119
|
+
|
120
|
+
behaves_like 'abstract structure #lget/lput/ldelete'
|
121
|
+
end
|
122
|
+
|
123
|
+
describe Rufus::Edo::Cabinet do
|
124
|
+
|
125
|
+
before do
|
126
|
+
@db = Rufus::Edo::Cabinet.new('tmp/cabinet_spec.tch')
|
127
|
+
@db.clear
|
128
|
+
end
|
129
|
+
after do
|
130
|
+
@db.close
|
131
|
+
end
|
132
|
+
|
133
|
+
behaves_like 'abstract structure #add{int|double}'
|
134
|
+
end
|
135
|
+
|
136
|
+
describe Rufus::Edo::Cabinet do
|
137
|
+
|
138
|
+
before do
|
139
|
+
@db = Rufus::Edo::Cabinet.new('tmp/cabinet_spec.tch')
|
140
|
+
@db.clear
|
141
|
+
end
|
142
|
+
after do
|
143
|
+
@db.close
|
144
|
+
end
|
145
|
+
|
146
|
+
behaves_like 'abstract structure #putkeep'
|
147
|
+
behaves_like 'abstract structure #putcat'
|
148
|
+
end
|
149
|
+
|
150
|
+
describe Rufus::Edo::Cabinet do
|
151
|
+
|
152
|
+
it 'should copy correctly' do
|
153
|
+
|
154
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_source.tch')
|
155
|
+
5000.times { |i| cab["key #{i}"] = "val #{i}" }
|
156
|
+
cab.size.should.equal(5000)
|
157
|
+
cab.copy('tmp/spec_target.tch')
|
158
|
+
cab.close
|
159
|
+
|
160
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_target.tch')
|
161
|
+
cab.size.should.equal(5000)
|
162
|
+
cab['key 4999'].should.equal('val 4999')
|
163
|
+
cab.close
|
164
|
+
|
165
|
+
FileUtils.rm('tmp/spec_source.tch')
|
166
|
+
FileUtils.rm('tmp/spec_target.tch')
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should copy compactly' do
|
170
|
+
|
171
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_source.tch')
|
172
|
+
100.times { |i| cab["key #{i}"] = "val #{i}" }
|
173
|
+
50.times { |i| cab.delete("key #{i}") }
|
174
|
+
cab.size.should.equal(50)
|
175
|
+
cab.compact_copy('tmp/spec_target.tch')
|
176
|
+
cab.close
|
177
|
+
|
178
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_target.tch')
|
179
|
+
cab.size.should.equal(50)
|
180
|
+
cab['key 99'].should.equal('val 99')
|
181
|
+
cab.close
|
182
|
+
|
183
|
+
fs0 = File.size('tmp/spec_source.tch')
|
184
|
+
fs1 = File.size('tmp/spec_target.tch')
|
185
|
+
(fs0 > fs1).should.equal(true)
|
186
|
+
|
187
|
+
FileUtils.rm('tmp/spec_source.tch')
|
188
|
+
FileUtils.rm('tmp/spec_target.tch')
|
189
|
+
end
|
190
|
+
|
191
|
+
|
192
|
+
it 'should use open with a block will auto close the db correctly' do
|
193
|
+
|
194
|
+
res = Rufus::Edo::Cabinet.open('tmp/spec_source.tch') do |cab|
|
195
|
+
10.times { |i| cab["key #{i}"] = "val #{i}" }
|
196
|
+
cab.size.should.equal(10)
|
197
|
+
:result
|
198
|
+
end
|
199
|
+
|
200
|
+
res.should.equal(:result)
|
201
|
+
|
202
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_source.tch')
|
203
|
+
10.times do |i|
|
204
|
+
cab["key #{i}"].should.equal("val #{i}")
|
205
|
+
end
|
206
|
+
cab.close
|
207
|
+
|
208
|
+
FileUtils.rm('tmp/spec_source.tch')
|
209
|
+
end
|
210
|
+
|
211
|
+
|
212
|
+
it 'should use open without a block just like calling new correctly' do
|
213
|
+
|
214
|
+
cab = Rufus::Edo::Cabinet.open('tmp/spec_source.tch')
|
215
|
+
10.times { |i| cab["key #{i}"] = "val #{i}" }
|
216
|
+
cab.size.should.equal(10)
|
217
|
+
cab.close
|
218
|
+
|
219
|
+
cab = Rufus::Edo::Cabinet.new('tmp/spec_source.tch')
|
220
|
+
10.times do |i|
|
221
|
+
cab["key #{i}"].should.equal("val #{i}")
|
222
|
+
end
|
223
|
+
cab.close
|
224
|
+
|
225
|
+
FileUtils.rm('tmp/spec_source.tch')
|
226
|
+
end
|
227
|
+
|
228
|
+
it 'should honour the :type parameter' do
|
229
|
+
|
230
|
+
cab = Rufus::Edo::Cabinet.open('tmp/toto.tch')
|
231
|
+
cab.clear
|
232
|
+
cab['hello'] = 'world'
|
233
|
+
cab.close
|
234
|
+
|
235
|
+
cab = Rufus::Edo::Cabinet.open('tmp/toto', :type => :hash)
|
236
|
+
cab['hello'].should.equal('world')
|
237
|
+
cab.close
|
238
|
+
|
239
|
+
FileUtils.rm('tmp/toto.tch')
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe Rufus::Edo::Cabinet do
|
244
|
+
|
245
|
+
before do
|
246
|
+
@db = Rufus::Edo::Cabinet.new('tmp/edo_cabinet_spec.tch')
|
247
|
+
@db.clear
|
248
|
+
end
|
249
|
+
after do
|
250
|
+
@db.close
|
251
|
+
end
|
252
|
+
|
253
|
+
behaves_like 'an abstract structure flattening keys and values'
|
254
|
+
end
|
255
|
+
|
256
|
+
describe 'Rufus::Edo::Cabinet with a default value' do
|
257
|
+
|
258
|
+
before do
|
259
|
+
@db = Rufus::Edo::Cabinet.new('tmp/cabinet_spec.tch', :default => 'Nemo')
|
260
|
+
@db.clear
|
261
|
+
@db['known'] = 'Ulysse'
|
262
|
+
end
|
263
|
+
after do
|
264
|
+
@db.close
|
265
|
+
end
|
266
|
+
|
267
|
+
behaves_like 'an abstract structure with a default value'
|
268
|
+
end
|
269
|
+
|
270
|
+
describe 'Rufus::Edo::Cabinet with a default_proc' do
|
271
|
+
|
272
|
+
before do
|
273
|
+
@db = Rufus::Edo::Cabinet.new(
|
274
|
+
'tmp/cabinet_spec.tch',
|
275
|
+
:default_proc => lambda { |db, k| "default:#{k}" })
|
276
|
+
@db.clear
|
277
|
+
@db['known'] = 'Ulysse'
|
278
|
+
end
|
279
|
+
after do
|
280
|
+
@db.close
|
281
|
+
end
|
282
|
+
|
283
|
+
behaves_like 'an abstract structure with a default_proc'
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|