quetzall-cloud_cache 1.1.0 → 1.1.3

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.
@@ -50,6 +50,7 @@ module ActiveSupport
50
50
 
51
51
 
52
52
  uri = URI.parse(url)
53
+ #puts 'body=' + body.to_s
53
54
  if (http_method == :put)
54
55
  req = Net::HTTP::Put.new(uri.path)
55
56
  req.body = body unless body.nil?
@@ -98,21 +99,43 @@ module ActiveSupport
98
99
  else
99
100
  data = (Marshal.dump(val))
100
101
  end
101
- puts 'putting=' + data.to_s
102
+ #puts 'putting=' + data.to_s
102
103
  extra_headers = seconds_to_store > 0 ? {"ttl"=>seconds_to_store} : nil
103
104
  run_http(:put, "PUT", key, data, nil, extra_headers)
104
105
  end
105
106
 
106
107
 
107
- def get_multi(keys)
108
+ def get_multi(keys, raw=false)
108
109
  kj = keys.to_json
109
- puts "keys.to_json = " + kj
110
+ #puts "keys.to_json = " + kj
110
111
  extra_headers = {"keys" => kj }
111
- puts "get_multi, extra_headers keys = " + extra_headers.keys.to_s
112
- puts "get_multi, extra_headers vals = " + extra_headers.values.to_s
112
+ #puts "get_multi, extra_headers keys = " + extra_headers.keys.to_s
113
+ #puts "get_multi, extra_headers vals = " + extra_headers.values.to_s
113
114
  body = run_http(:get, "GET", "getmulti", nil, nil, extra_headers)
114
- vals = ActiveSupport::JSON.decode body
115
- vals
115
+ #puts 'body=' + body.to_s
116
+ # todo: should try to stream the body in
117
+ #vals = ActiveSupport::JSON.decode body
118
+ # New response format is:
119
+ # VALUE <key> <bytes> \r\n
120
+ # <data block>\r\n
121
+ # VALUE <key> <bytes> \r\n
122
+ # <data block>\r\n
123
+ # END
124
+ values = {}
125
+ curr_key = nil
126
+ data_length = 0
127
+ body.each_line do |line|
128
+ break if line == "END\r\n"
129
+ if line =~ /^VALUE (.+) (.+)/ then # (key) (bytes)
130
+ curr_key, data_length = $1, $2
131
+ #raise CloudCacheError, "Unexpected response #{line.inspect}"
132
+ else
133
+ # data block
134
+ values[curr_key] = raw ? line.strip : Marshal.load(line.strip)
135
+ end
136
+ end
137
+ #puts 'values=' + values.inspect
138
+ values
116
139
  end
117
140
 
118
141
  def get(key, raw=false)
@@ -131,6 +154,13 @@ module ActiveSupport
131
154
  end
132
155
  end
133
156
 
157
+ # returns the value as an int.
158
+ def get_i(key)
159
+ val = get(key, true)
160
+ return nil if val.nil?
161
+ return val.to_i
162
+ end
163
+
134
164
  def list_keys
135
165
  body = run_http(:get, "listkeys", "listkeys")
136
166
  keys = ActiveSupport::JSON.decode body # body[1..-2].split(',').collect! {|n| n.to_i}
@@ -175,12 +205,8 @@ module ActiveSupport
175
205
  end
176
206
 
177
207
  def exist?(key, options = nil)
178
- x = get(key)
179
- r = true
180
- if (x == nil)
181
- r = false
182
- end
183
- r
208
+ x = get(key, true)
209
+ return !x.nil?
184
210
  end
185
211
 
186
212
  def fetch(key, options = {})
@@ -223,6 +249,10 @@ module ActiveSupport
223
249
  my_b64_hmac_digest = Base64.encode64(my_sha_hmac).strip
224
250
  return my_b64_hmac_digest
225
251
  end
252
+
253
+ class CloudCacheError < RuntimeError
254
+
255
+ end
226
256
  end
227
257
  end
228
258
  end
@@ -1,5 +1,5 @@
1
- require 'mini/test'
2
- require '../lib/cloudcache'
1
+ require 'test/unit'
2
+ require '../lib/cloud_cache'
3
3
 
4
4
  #
5
5
  # You'll need make a cloudcache.yml file in this directory that contains:
@@ -9,135 +9,156 @@ require '../lib/cloudcache'
9
9
  #
10
10
  class CacheTests < Test::Unit::TestCase
11
11
 
12
- def test_for_truth
13
- assert true
14
- end
15
-
16
- def setup
17
- puts("Setting up cache...")
18
- props = nil
19
- begin
20
- props = YAML::load(File.read('cloudcache.yml'))
21
- rescue
22
- puts "Couldn't find cloudcache.yml file. " + $!.message
23
- return
12
+ #def initialize(*params)
13
+ # super(*params)
14
+ #end
15
+
16
+ def test_for_truth
17
+ assert true
24
18
  end
25
- @cache = ActiveSupport::Cache::CloudCache.new("cloudcache-ruby-tests", props['amazon']['access_key'], props['amazon']['secret_key'])
26
- end
27
19
 
20
+ def setup
21
+ puts("Setting up cache...")
22
+ props = nil
23
+ begin
24
+ props = YAML::load(File.read('cloudcache.yml'))
25
+ rescue
26
+ raise "Couldn't find cloudcache.yml file. " + $!.message
27
+ end
28
+ @cache = ActiveSupport::Cache::CloudCache.new(props['access_key'], props['secret_key'])
29
+ end
28
30
 
29
- def teardown
30
- @cache.shutdown unless @cache.nil?
31
- end
32
31
 
33
- def test_auth
34
- @cache.auth()
35
- end
32
+ def teardown
33
+ @cache.shutdown unless @cache.nil?
34
+ end
36
35
 
37
- def test_bad_auth
36
+ def test_auth
37
+ @cache.auth()
38
+ end
38
39
 
39
- temp = @cache.secret_key
40
- @cache.secret_key = "badkey"
40
+ def test_bad_auth
41
41
 
42
- assert_raise Net::HTTPServerException do
43
- test_basic_ops
42
+ temp = @cache.secret_key
43
+ @cache.secret_key = "badkey"
44
+
45
+ assert_raise Net::HTTPServerException do
46
+ test_basic_ops
47
+ end
48
+
49
+ @cache.secret_key = temp
44
50
  end
45
51
 
46
- @cache.secret_key = temp
47
- end
52
+ def test_basic_ops
53
+ to_put = "I am a testing string. Take me apart and put me back together again."
54
+ @cache.put("s1", to_put, 0);
48
55
 
49
- def test_basic_ops
50
- to_put = "I am a testing string. Take me apart and put me back together again."
51
- @cache.put("s1", to_put, 0);
56
+ sleep(1)
52
57
 
53
- sleep(5)
58
+ response = @cache.get("s1")
59
+ assert_equal(to_put, response)
54
60
 
55
- response = @cache.get("s1")
56
- assert_equal(to_put, response)
61
+ end
57
62
 
58
- end
63
+ def test_not_exists
64
+ assert_nil @cache.get("does_not_exist")
65
+ end
66
+
67
+ def test_delete
68
+ to_put = "I am a testing string. Take me apart and put me back together again."
69
+ @cache.put("s1", to_put, 0)
70
+
71
+ sleep(1)
59
72
 
60
- def test_not_exists
61
- assert_nil @cache.get("does_not_exist")
62
- end
73
+ response = @cache.get("s1")
74
+ assert_equal(to_put, response)
63
75
 
64
- def test_delete
65
- to_put = "I am a testing string. Take me apart and put me back together again."
66
- @cache.put("s1", to_put, 0)
76
+ @cache.delete("s1");
67
77
 
68
- sleep(5)
78
+ response = @cache.get("s1")
79
+ assert_nil(response)
80
+ end
69
81
 
70
- response = @cache.get("s1")
71
- assert_equal(to_put, response)
82
+ def test_expiry
83
+ to_put = "I am a testing string. Take me apart and put me back together again."
84
+ @cache.put("s1", to_put, 2);
72
85
 
73
- @cache.delete("s1");
86
+ sleep(4)
74
87
 
75
- response = @cache.get("s1")
76
- assert_nil(response)
77
- end
88
+ response = @cache.get("s1")
89
+ assert_nil(response)
90
+ end
78
91
 
79
- def test_expiry
80
- to_put = "I am a testing string. Take me apart and put me back together again."
81
- @cache.put("s1", to_put, 5);
92
+ def test_list_keys
93
+ @cache.put("k1", "v2")
94
+ sleep 1
95
+ keys = @cache.list_keys
96
+ puts("PRINTING KEYS:")
97
+ for key in keys
98
+ puts key
99
+ end
100
+ haskey = keys.index("k1")
101
+ assert_not_nil(haskey)
102
+ end
82
103
 
83
- sleep(10)
104
+ def test_counters
105
+ val = 0
106
+ key = "counter1"
107
+ @cache.put(key, val, 50000, true)
108
+ 10.times do
109
+ val = @cache.increment(key)
110
+ end
111
+ assert_equal(10, val)
84
112
 
85
- response = @cache.get("s1")
86
- assert_nil(response)
87
- end
113
+ # get as normal int now
114
+ get_val = @cache.get_i(key)
115
+ assert_equal(10, get_val)
88
116
 
89
- def test_list_keys
90
- @cache.put("k1","v2")
91
- sleep 1
92
- keys = @cache.list_keys
93
- puts("PRINTING KEYS:")
94
- for key in keys
95
- puts key
117
+ 10.times do
118
+ val = @cache.decrement(key)
119
+ end
120
+ assert_equal(0, val)
121
+
122
+ # One more to make sure it stays at 0
123
+ val = @cache.decrement(key)
124
+ assert_equal(0, val)
125
+
126
+ end
127
+
128
+ def test_flush
129
+ x = @cache.flush
130
+ assert_equal('[]', x)
131
+ end
132
+
133
+ def test_stats
134
+ x = @cache.stats
135
+ puts x
96
136
  end
97
- haskey = keys.index("k1")
98
- assert_not_nil(haskey)
99
- end
100
-
101
- def test_counters
102
- val = 0;
103
- key = "counter1";
104
- @cache.put(key, val, 50000, true);
105
- 10.times do
106
- val = @cache.increment(key)
137
+
138
+ def test_get_multi_raw
139
+ @cache.put("m1", "v1", 500, true)
140
+ @cache.put("m2", "v2", 500, true)
141
+
142
+ kz = Array["m1", "m2", "m3"]
143
+ vz = @cache.get_multi(kz, true)
144
+
145
+ assert_equal("v1", vz["m1"]);
146
+ assert_equal("v2", vz["m2"]);
147
+ assert_nil(vz["m3"]);
107
148
  end
108
- assert_equal(10, val)
109
149
 
110
- 10.times do
111
- val = @cache.decrement(key)
150
+ def test_get_multi
151
+ @cache.put("m1", "v1", 500, false)
152
+ @cache.put("m2", "v2", 500, false)
153
+
154
+ kz = Array["m1", "m2", "m3"]
155
+ vz = @cache.get_multi(kz)
156
+
157
+ assert_equal("v1", vz["m1"]);
158
+ assert_equal("v2", vz["m2"]);
159
+ assert_nil(vz["m3"]);
112
160
  end
113
- assert_equal(0, val);
114
-
115
- # One more to make sure it stays at 0
116
- val = @cache.decrement(key);
117
- assert_equal(0, val);
118
-
119
- end
120
-
121
- def test_flush
122
- x = @cache.flush
123
- assert_equal('[]', x)
124
- end
125
-
126
- def test_stats
127
- x = @cache.stats
128
- puts x
129
- end
130
- def test_get_multi
131
- @cache.put("m1","v1")
132
- @cache.put("m2","v2")
133
-
134
- kz = Array["m1" , "m2", "m3"]
135
- vz = @cache.get_multi(kz)
136
-
137
- assert_equal("v1",vz["m1"]);
138
- assert_equal("v2",vz["m2"]);
139
- assert_nil(vz["m3"]);
140
- end
161
+
141
162
 
142
163
 
143
164
 
@@ -0,0 +1,10 @@
1
+ # temporary until rubymine supports ruby 1.i
2
+
3
+ require 'test/unit'
4
+ require 'cache_tests'
5
+
6
+ t = CacheTests.new("counterssdf")
7
+ #Test::Unit::UI::Console::TestRunner.run(CacheTests)
8
+ #t.setup
9
+ #t.test_counters
10
+ #t.teardown
metadata CHANGED
@@ -1,23 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quetzall-cloud_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Reeder
8
- - Marc Byrd
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
11
 
13
- date: 2009-06-23 00:00:00 -07:00
14
- default_executable: cloud_cache
12
+ date: 2009-06-30 00:00:00 -07:00
13
+ default_executable:
15
14
  dependencies: []
16
15
 
17
16
  description: Client library for Quetzall's CloudCache service.
18
17
  email: travis@appoxy.com
19
- executables:
20
- - cloud_cache
18
+ executables: []
19
+
21
20
  extensions: []
22
21
 
23
22
  extra_rdoc_files:
@@ -56,3 +55,4 @@ summary: Client library for Quetzall's CloudCache service.
56
55
  test_files:
57
56
  - test/cache_tests.rb
58
57
  - test/test_cloud_cache.rb
58
+ - test/test_runner.rb
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- abort "you need to write me"