quetzall-cloud_cache 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/cloud_cache.rb CHANGED
@@ -78,7 +78,7 @@ module ActiveSupport
78
78
  end
79
79
  case res
80
80
  when Net::HTTPSuccess
81
- # puts 'response body=' + res.body
81
+ #puts 'response body=' + res.body
82
82
  res.body
83
83
  else
84
84
  res.error!
@@ -93,6 +93,7 @@ module ActiveSupport
93
93
  end
94
94
 
95
95
  def put(key, val, seconds_to_store=0, raw=false)
96
+ #puts 'putting ' + val.to_s + ' to key=' + key
96
97
  seconds_to_store = 0 if seconds_to_store.nil?
97
98
  if raw
98
99
  data = val.to_s
@@ -181,11 +182,15 @@ module ActiveSupport
181
182
  end
182
183
 
183
184
  def stats
184
- body = run_http(:get, "mystats", "mystats")
185
+ body = run_http(:get, "myusage", "myusage")
185
186
  #keys = ActiveSupport::JSON.decode body # body[1..-2].split(',').collect! {|n| n.to_i}
186
- body
187
+ #puts 'body=' + body
188
+ body.to_i
187
189
  end
188
190
 
191
+ def usage
192
+ return stats
193
+ end
189
194
 
190
195
  def flush
191
196
  body = run_http(:get, "flush", "flush")
@@ -212,6 +217,10 @@ module ActiveSupport
212
217
  run_http(:delete, "DELETE", name)
213
218
  end
214
219
 
220
+ def remove(name, options=nil)
221
+ delete(name, options)
222
+ end
223
+
215
224
  def delete_matched(matcher, options = nil)
216
225
  super
217
226
  raise "delete_matched not yet supported by CloudCache"
data/test/cache_tests.rb CHANGED
@@ -9,14 +9,6 @@ require 'my_class'
9
9
  #
10
10
  class CacheTests < Test::Unit::TestCase
11
11
 
12
- #def initialize(*params)
13
- # super(*params)
14
- #end
15
-
16
- def test_for_truth
17
- assert true
18
- end
19
-
20
12
  def setup
21
13
  puts("Setting up cache...")
22
14
  props = nil
@@ -136,6 +128,11 @@ class CacheTests < Test::Unit::TestCase
136
128
  end
137
129
 
138
130
  def test_get_multi_raw
131
+ @cache.remove("m1") rescue false
132
+ @cache.remove("m2") rescue false
133
+ @cache.remove("m3") rescue false
134
+ @cache.remove("m4") rescue false
135
+
139
136
  @cache.put("m1", "v1", 500, true)
140
137
  @cache.put("m2", "v2", 500, true)
141
138
 
@@ -145,9 +142,16 @@ class CacheTests < Test::Unit::TestCase
145
142
  assert_equal("v1", vz["m1"]);
146
143
  assert_equal("v2", vz["m2"]);
147
144
  assert_nil(vz["m3"]);
145
+
146
+
148
147
  end
149
148
 
150
149
  def test_get_multi
150
+ @cache.remove("m1") rescue false
151
+ @cache.remove("m2") rescue false
152
+ @cache.remove("m3") rescue false
153
+ @cache.remove("m4") rescue false
154
+
151
155
  @cache.put("m1", "v1", 500, false)
152
156
  @cache.put("m2", "v2", 500, false)
153
157
  @cache.put("m4", MyClass.new("Travis", 10), 500, false)
@@ -158,9 +162,44 @@ class CacheTests < Test::Unit::TestCase
158
162
  assert_equal("v1", vz["m1"]);
159
163
  assert_equal("v2", vz["m2"]);
160
164
  assert_nil(vz["m3"]);
161
- assert_equal("Travis", vz["m4"].name, vz["m4"].age)
165
+ assert_equal("Travis", vz["m4"].name)
166
+ assert_equal(10, vz["m4"].age)
167
+
168
+ @cache.put("m3", MyClass.new("Leroy", 3), 500, false)
169
+
170
+ kz = Array["m1", "m2", "m3", "m4"]
171
+ vz = @cache.get_multi(kz)
172
+
173
+ assert_equal("v1", vz["m1"]);
174
+ assert_equal("v2", vz["m2"]);
175
+ assert_equal("Leroy", vz["m3"].name)
176
+ assert_equal(3, vz["m3"].age)
177
+ assert_equal("Travis", vz["m4"].name)
178
+ assert_equal(10, vz["m4"].age)
179
+
180
+
162
181
  end
163
182
 
183
+ def test_big
184
+ s = random_string(1500)
185
+ @cache.put("s1", s)
186
+
187
+ s2 = @cache.get("s1")
188
+
189
+ assert_equal(s, s2)
190
+ end
191
+
192
+ def random_string(length=10)
193
+ chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789'
194
+ password = ''
195
+ length.times { password << chars[rand(chars.size)] }
196
+ password
197
+ end
198
+
199
+ def test_usage
200
+ usage = @cache.usage
201
+ assert_kind_of(Numeric, usage)
202
+ end
164
203
 
165
204
 
166
205
 
data/test/test_runner.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  require 'test/unit'
4
4
  require 'cache_tests'
5
5
 
6
- t = CacheTests.new("counterssdf")
6
+ t = CacheTests.new("test_get_multi")
7
7
  #Test::Unit::UI::Console::TestRunner.run(CacheTests)
8
8
  #t.setup
9
9
  #t.test_counters
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.1.4
4
+ version: 1.1.5
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-07-14 00:00:00 -07:00
12
+ date: 2009-07-22 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15