quetzall-cloud_cache 1.2.0 → 1.2.1
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.
- data/lib/cloud_cache.rb +5 -3
- data/test/cache_tests.rb +156 -151
- metadata +2 -2
data/lib/cloud_cache.rb
CHANGED
|
@@ -106,6 +106,7 @@ module ActiveSupport
|
|
|
106
106
|
data = val.to_s
|
|
107
107
|
else
|
|
108
108
|
data = (Marshal.dump(val))
|
|
109
|
+
data = Base64.encode64(data)
|
|
109
110
|
end
|
|
110
111
|
#puts 'putting=' + data.to_s
|
|
111
112
|
extra_headers = seconds_to_store > 0 ? {"ttl"=>seconds_to_store} : nil
|
|
@@ -143,7 +144,7 @@ module ActiveSupport
|
|
|
143
144
|
end
|
|
144
145
|
if line =~ /^VALUE (.+) (.+)/ then # (key) (bytes)
|
|
145
146
|
if !curr_key.nil?
|
|
146
|
-
values[curr_key] = raw ? val.strip : Marshal.load(val.strip)
|
|
147
|
+
values[curr_key] = raw ? val.strip : Marshal.load(Base64.decode64(val.strip))
|
|
147
148
|
end
|
|
148
149
|
curr_key, data_length = $1, $2
|
|
149
150
|
val = ""
|
|
@@ -155,7 +156,7 @@ module ActiveSupport
|
|
|
155
156
|
count += 1
|
|
156
157
|
end
|
|
157
158
|
if !val.nil? && val != ""
|
|
158
|
-
values[curr_key] = raw ? val.strip :
|
|
159
|
+
values[curr_key] = raw ? val.strip : Marshal.load(Base64.decode64(val.strip))
|
|
159
160
|
end
|
|
160
161
|
#puts 'values=' + values.inspect
|
|
161
162
|
values
|
|
@@ -170,10 +171,11 @@ module ActiveSupport
|
|
|
170
171
|
return nil if $!.message.include? "404"
|
|
171
172
|
raise $!
|
|
172
173
|
end
|
|
173
|
-
#
|
|
174
|
+
#puts 'data1=' + data.to_s
|
|
174
175
|
if raw
|
|
175
176
|
return data
|
|
176
177
|
else
|
|
178
|
+
data = Base64.decode64(data)
|
|
177
179
|
return Marshal.load((data))
|
|
178
180
|
end
|
|
179
181
|
end
|
data/test/cache_tests.rb
CHANGED
|
@@ -25,193 +25,193 @@ class CacheTests < Test::Unit::TestCase
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
def test_auth
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def test_bad_auth
|
|
32
|
-
|
|
33
|
-
temp = @cache.secret_key
|
|
34
|
-
@cache.secret_key = "badkey"
|
|
35
|
-
|
|
36
|
-
assert_raise Net::HTTPServerException do
|
|
37
|
-
test_basic_ops
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
@cache.secret_key = temp
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def test_basic_ops
|
|
44
|
-
to_put = "I am a testing string. Take me apart and put me back together again."
|
|
45
|
-
@cache.put("s1", to_put)
|
|
46
|
-
|
|
47
|
-
sleep(1)
|
|
48
|
-
|
|
49
|
-
response = @cache.get("s1")
|
|
50
|
-
assert_equal(to_put, response)
|
|
28
|
+
@cache.auth()
|
|
29
|
+
end
|
|
51
30
|
|
|
52
|
-
|
|
31
|
+
def test_bad_auth
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
end
|
|
33
|
+
temp = @cache.secret_key
|
|
34
|
+
@cache.secret_key = "badkey"
|
|
57
35
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
36
|
+
assert_raise Net::HTTPServerException do
|
|
37
|
+
test_basic_ops
|
|
38
|
+
end
|
|
61
39
|
|
|
62
|
-
|
|
40
|
+
@cache.secret_key = temp
|
|
41
|
+
end
|
|
63
42
|
|
|
64
|
-
|
|
65
|
-
|
|
43
|
+
def test_basic_ops
|
|
44
|
+
to_put = "I am a testing string. Take me apart and put me back together again."
|
|
45
|
+
@cache.put("s1", to_put)
|
|
66
46
|
|
|
67
|
-
|
|
47
|
+
sleep(1)
|
|
68
48
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
49
|
+
response = @cache.get("s1")
|
|
50
|
+
assert_equal(to_put, response)
|
|
72
51
|
|
|
73
|
-
|
|
74
|
-
to_put = "I am a testing string. Take me apart and put me back together again."
|
|
75
|
-
@cache.put("s1", to_put, :ttl=>2);
|
|
76
|
-
sleep(4)
|
|
77
|
-
response = @cache.get("s1")
|
|
78
|
-
assert_nil(response)
|
|
52
|
+
end
|
|
79
53
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
assert_nil(response)
|
|
84
|
-
end
|
|
54
|
+
def test_not_exists
|
|
55
|
+
assert_nil @cache.get("does_not_exist")
|
|
56
|
+
end
|
|
85
57
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
keys = @cache.list_keys
|
|
90
|
-
puts("PRINTING KEYS:")
|
|
91
|
-
for key in keys
|
|
92
|
-
puts key
|
|
93
|
-
end
|
|
94
|
-
haskey = keys.index("k1")
|
|
95
|
-
assert_not_nil(haskey)
|
|
96
|
-
end
|
|
58
|
+
def test_delete
|
|
59
|
+
to_put = "I am a testing string. Take me apart and put me back together again."
|
|
60
|
+
@cache.put("s1", to_put)
|
|
97
61
|
|
|
98
|
-
|
|
99
|
-
val = 0
|
|
100
|
-
key = "counter1" # should add a test for a key with a slash
|
|
101
|
-
@cache.put(key, val, :ttl=>50000, :raw=>true)
|
|
102
|
-
10.times do
|
|
103
|
-
val = @cache.increment(key)
|
|
104
|
-
puts 'val=' + val.to_s
|
|
105
|
-
end
|
|
106
|
-
assert_equal(10, val)
|
|
62
|
+
sleep(1)
|
|
107
63
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
assert_equal(10, get_val)
|
|
64
|
+
response = @cache.get("s1")
|
|
65
|
+
assert_equal(to_put, response)
|
|
111
66
|
|
|
112
|
-
|
|
113
|
-
val = @cache.decrement(key)
|
|
114
|
-
end
|
|
115
|
-
assert_equal(0, val)
|
|
67
|
+
@cache.delete("s1")
|
|
116
68
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
69
|
+
response = @cache.get("s1")
|
|
70
|
+
assert_nil(response)
|
|
71
|
+
end
|
|
120
72
|
|
|
121
|
-
|
|
73
|
+
def test_expiry
|
|
74
|
+
to_put = "I am a testing string. Take me apart and put me back together again."
|
|
75
|
+
@cache.put("s1", to_put, :ttl=>2);
|
|
76
|
+
sleep(4)
|
|
77
|
+
response = @cache.get("s1")
|
|
78
|
+
assert_nil(response)
|
|
79
|
+
|
|
80
|
+
@cache.write("s1", to_put, :expires_in=>2);
|
|
81
|
+
sleep(4)
|
|
82
|
+
response = @cache.get("s1")
|
|
83
|
+
assert_nil(response)
|
|
84
|
+
end
|
|
122
85
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
86
|
+
def test_list_keys
|
|
87
|
+
@cache.put("k1", "v2", :expires_in=>15)
|
|
88
|
+
sleep 1
|
|
89
|
+
keys = @cache.list_keys
|
|
90
|
+
puts("PRINTING KEYS:")
|
|
91
|
+
for key in keys
|
|
92
|
+
puts key
|
|
93
|
+
end
|
|
94
|
+
haskey = keys.index("k1")
|
|
95
|
+
assert_not_nil(haskey)
|
|
96
|
+
end
|
|
127
97
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
98
|
+
def test_counters
|
|
99
|
+
val = 0
|
|
100
|
+
key = "counter1" # should add a test for a key with a slash
|
|
101
|
+
@cache.put(key, val, :ttl=>50000, :raw=>true)
|
|
102
|
+
10.times do
|
|
103
|
+
val = @cache.increment(key)
|
|
104
|
+
puts 'val=' + val.to_s
|
|
105
|
+
end
|
|
106
|
+
assert_equal(10, val)
|
|
132
107
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
@cache.remove("m3") rescue false
|
|
137
|
-
@cache.remove("m4") rescue false
|
|
108
|
+
# get as normal int now
|
|
109
|
+
get_val = @cache.get_i(key)
|
|
110
|
+
assert_equal(10, get_val)
|
|
138
111
|
|
|
139
|
-
|
|
140
|
-
|
|
112
|
+
10.times do
|
|
113
|
+
val = @cache.decrement(key)
|
|
114
|
+
end
|
|
115
|
+
assert_equal(0, val)
|
|
141
116
|
|
|
142
|
-
|
|
143
|
-
|
|
117
|
+
# One more to make sure it stays at 0
|
|
118
|
+
val = @cache.decrement(key)
|
|
119
|
+
assert_equal(0, val)
|
|
144
120
|
|
|
145
|
-
|
|
146
|
-
assert_equal("v2", vz["m2"])
|
|
147
|
-
assert_nil(vz["m3"])
|
|
121
|
+
end
|
|
148
122
|
|
|
123
|
+
def test_flush
|
|
124
|
+
x = @cache.flush
|
|
125
|
+
assert_equal('[]', x)
|
|
126
|
+
end
|
|
149
127
|
|
|
150
|
-
|
|
128
|
+
def test_stats
|
|
129
|
+
x = @cache.stats
|
|
130
|
+
puts x
|
|
131
|
+
end
|
|
151
132
|
|
|
152
|
-
|
|
133
|
+
def test_get_multi_raw
|
|
134
|
+
@cache.remove("m1") rescue false
|
|
135
|
+
@cache.remove("m2") rescue false
|
|
136
|
+
@cache.remove("m3") rescue false
|
|
137
|
+
@cache.remove("m4") rescue false
|
|
153
138
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
assert vz.size == 0
|
|
139
|
+
@cache.put("m1", "v1", :ttl=>500, :raw=>true)
|
|
140
|
+
@cache.put("m2", "v2", :ttl=>500, :raw=>true)
|
|
157
141
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
assert vz.size == 0
|
|
142
|
+
kz = Array["m1", "m2", "m3"]
|
|
143
|
+
vz = @cache.get_multi(kz, :raw=>true)
|
|
161
144
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
@cache.remove("m4") rescue false
|
|
145
|
+
assert_equal("v1", vz["m1"])
|
|
146
|
+
assert_equal("v2", vz["m2"])
|
|
147
|
+
assert_nil(vz["m3"])
|
|
166
148
|
|
|
167
|
-
@cache.put("m1", "v1", :ttl=>500, :raw=>false)
|
|
168
|
-
@cache.put("m2", "v2", :ttl=>500, :raw=>false)
|
|
169
|
-
@cache.put("m4", MyClass.new("Travis", 10), :ttl=>500, :raw=>false)
|
|
170
|
-
|
|
171
|
-
kz = ["m1", "m2", "m3", "m4"]
|
|
172
|
-
vz = @cache.get_multi(kz)
|
|
173
|
-
|
|
174
|
-
assert_equal("v1", vz["m1"]);
|
|
175
|
-
assert_equal("v2", vz["m2"]);
|
|
176
|
-
assert_nil(vz["m3"]);
|
|
177
|
-
assert_equal("Travis", vz["m4"].name)
|
|
178
|
-
assert_equal(10, vz["m4"].age)
|
|
179
149
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def test_get_multi
|
|
153
|
+
|
|
154
|
+
kz = []
|
|
155
|
+
vz = @cache.get_multi(kz)
|
|
156
|
+
assert vz.size == 0
|
|
157
|
+
|
|
158
|
+
kz = ["nothere"]
|
|
159
|
+
vz = @cache.get_multi(kz)
|
|
160
|
+
assert vz.size == 0
|
|
161
|
+
|
|
162
|
+
@cache.remove("m1") rescue false
|
|
163
|
+
@cache.remove("m2") rescue false
|
|
164
|
+
@cache.remove("m3") rescue false
|
|
165
|
+
@cache.remove("m4") rescue false
|
|
166
|
+
|
|
167
|
+
@cache.put("m1", "v1", :ttl=>500, :raw=>false)
|
|
168
|
+
@cache.put("m2", "v2", :ttl=>500, :raw=>false)
|
|
169
|
+
@cache.put("m4", MyClass.new("Travis", 10), :ttl=>500, :raw=>false)
|
|
170
|
+
|
|
171
|
+
kz = ["m1", "m2", "m3", "m4"]
|
|
172
|
+
vz = @cache.get_multi(kz)
|
|
184
173
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
assert_equal(10, vz["m4"].age)
|
|
174
|
+
assert_equal("v1", vz["m1"]);
|
|
175
|
+
assert_equal("v2", vz["m2"]);
|
|
176
|
+
assert_nil(vz["m3"]);
|
|
177
|
+
assert_equal("Travis", vz["m4"].name)
|
|
178
|
+
assert_equal(10, vz["m4"].age)
|
|
191
179
|
|
|
180
|
+
@cache.put("m3", MyClass.new("Leroy", 3), :ttl=>500, :raw=>false)
|
|
192
181
|
|
|
193
|
-
|
|
182
|
+
kz = ["m1", "m2", "m3", "m4"]
|
|
183
|
+
vz = @cache.get_multi(kz)
|
|
194
184
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
assert_equal("v1", vz["m1"]);
|
|
186
|
+
assert_equal("v2", vz["m2"]);
|
|
187
|
+
assert_equal("Leroy", vz["m3"].name)
|
|
188
|
+
assert_equal(3, vz["m3"].age)
|
|
189
|
+
assert_equal("Travis", vz["m4"].name)
|
|
190
|
+
assert_equal(10, vz["m4"].age)
|
|
198
191
|
|
|
199
|
-
s2 = @cache.get("s1")
|
|
200
192
|
|
|
201
|
-
|
|
202
|
-
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
def test_big
|
|
196
|
+
s = random_string(100000)
|
|
197
|
+
@cache.put("s1", s)
|
|
203
198
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
password
|
|
209
|
-
end
|
|
199
|
+
s2 = @cache.get("s1")
|
|
200
|
+
|
|
201
|
+
assert_equal(s, s2)
|
|
202
|
+
end
|
|
210
203
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
204
|
+
def random_string(length=10)
|
|
205
|
+
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
|
|
206
|
+
password = ''
|
|
207
|
+
length.times { password << chars[rand(chars.size)] }
|
|
208
|
+
password
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_usage
|
|
212
|
+
usage = @cache.usage
|
|
213
|
+
assert_kind_of(Numeric, usage)
|
|
214
|
+
end
|
|
215
215
|
|
|
216
216
|
|
|
217
217
|
def test_set_if_not_found
|
|
@@ -223,7 +223,12 @@ class CacheTests < Test::Unit::TestCase
|
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
val = 3
|
|
226
|
-
@cache.increment(key, 1, :set_if_not_found=>val)
|
|
226
|
+
ret = @cache.increment(key, 1, :set_if_not_found=>val)
|
|
227
|
+
assert ret == val
|
|
228
|
+
ret = @cache.get(key)
|
|
229
|
+
assert ret == val
|
|
230
|
+
ret = @cache.increment(key, 1, :set_if_not_found=>val)
|
|
231
|
+
assert ret == val + 1
|
|
227
232
|
|
|
228
233
|
end
|
|
229
234
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quetzall-cloud_cache
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Travis Reeder
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-09-
|
|
12
|
+
date: 2009-09-11 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|