/
edo_ntyrant_spec.rb
151 lines (115 loc) · 2.94 KB
/
edo_ntyrant_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#
# Specifying rufus-tokyo
#
# Mon Feb 23 23:24:45 JST 2009
#
require File.dirname(__FILE__) + '/spec_base'
require File.dirname(__FILE__) + '/shared_abstract_spec'
begin
require 'rufus/edo/ntyrant'
rescue LoadError
puts "'TokyoTyrant' ruby lib not available on this ruby platform"
end
if defined?(Rufus::Edo)
describe 'a missing Rufus::Edo::NetTyrant' do
it 'should raise an error' do
lambda {
Rufus::Edo::NetTyrant.new('tyrant.example.com', 45000)
}.should.raise(Rufus::Edo::EdoError).message.should.equal(
'(err 2) host not found')
end
end
describe Rufus::Edo::NetTyrant do
it 'should open and close' do
should.not.raise {
t = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
t.close
}
end
it 'should refuse to connect to a TyrantTable' do
lambda {
t = Rufus::Edo::NetTyrant.new('127.0.0.1', 45001)
}.should.raise(ArgumentError)
end
end
describe Rufus::Edo::NetTyrant do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
#puts @t.stat.inject('') { |s, (k, v)| s << "#{k} => #{v}\n" }
@db.clear
end
after do
@db.close
end
behaves_like "an abstract structure"
it 'should respond to stat' do
stat = @db.stat
stat['type'].should.equal('hash')
end
end
describe Rufus::Edo::NetTyrant do
before do
@n = 50
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
@n.times { |i| @db["person#{i}"] = 'whoever' }
@n.times { |i| @db["animal#{i}"] = 'whichever' }
@db["toto#{0.chr}5"] = 'toto'
end
after do
@db.close
end
behaves_like 'abstract structure #keys'
end
describe 'Rufus::Edo::NetTyrant lget/lput/ldelete' do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
3.times { |i| @db[i.to_s] = "val#{i}" }
end
after do
@db.close
end
behaves_like 'abstract structure #lget/lput/ldelete'
end
describe 'Rufus::Edo::NetTyrant#add{int|double}' do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
end
after do
@db.close
end
behaves_like 'abstract structure #add{int|double}'
end
describe 'Rufus::Edo::NetTyrant#putkeep' do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
end
after do
@db.close
end
behaves_like 'abstract structure #putkeep'
end
describe 'Rufus::Edo::NetTyrant (lua extensions)' do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
end
after do
@db.close
end
behaves_like 'tyrant with embedded lua'
end
describe Rufus::Edo::NetTyrant do
before do
@db = Rufus::Edo::NetTyrant.new('127.0.0.1', 45000)
@db.clear
end
after do
@db.close
end
behaves_like 'an abstract structure flattening keys and values'
end
end