forked from riak-ripple/ripple
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_store_spec.rb
154 lines (125 loc) · 4.37 KB
/
cache_store_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
151
152
153
154
require File.expand_path("../../spec_helper", File.dirname(__FILE__))
require 'riak/cache_store'
describe Riak::CacheStore do
before :all do
if $test_server
@web_port = 9000
$test_server.start
end
end
before do
@web_port ||= 8098
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :http_port => @web_port)
@cleanup = true
end
after do
if @cleanup
if $test_server
$test_server.recycle
Thread.current[:curl_easy_handle] = nil
else
@cache.bucket.keys(:force => true).each do |k|
@cache.bucket.delete(k, :rw => 1) unless k.blank?
end
end
end
end
describe "Riak integration" do
before do
@cleanup = false
end
it "should have a client" do
@cache.should respond_to(:client)
@cache.client.should be_kind_of(Riak::Client)
end
it "should have a bucket to store entries in" do
@cache.bucket.should be_kind_of(Riak::Bucket)
end
it "should configure the client according to the initialized options" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :http_port => 10000)
@cache.client.http_port.should == 10000
end
it "should choose the bucket according to the initializer option" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :bucket => "foobar", :http_port => @web_port)
@cache.bucket.name.should == "foobar"
end
it "should set the N value to 2 by default" do
@cache.bucket.n_value.should == 2
end
it "should set the N value to the specified value" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :n_value => 1, :http_port => @web_port)
@cache.bucket.n_value.should == 1
end
it "should set the bucket R value to 1 by default" do
@cache.bucket.r.should == 1
end
it "should set the bucket R default to the specified value" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :r => "quorum", :http_port => @web_port)
@cache.bucket.r.should == "quorum"
end
it "should set the bucket W value to 1 by default" do
@cache.bucket.w.should == 1
end
it "should set the bucket W default to the specified value" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :w => "all", :http_port => @web_port)
@cache.bucket.w.should == "all"
end
it "should set the bucket DW value to 0 by default" do
@cache.bucket.dw.should == 0
end
it "should set the bucket DW default to the specified value" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :dw => "quorum", :http_port => @web_port)
@cache.bucket.dw.should == "quorum"
end
it "should set the bucket RW value to quorum by default" do
@cache.bucket.rw.should == "quorum"
end
it "should set the bucket RW default to the specified value" do
@cache = ActiveSupport::Cache.lookup_store(:riak_store, :rw => "all", :http_port => @web_port)
@cache.bucket.rw.should == "all"
end
end
it "should read and write strings" do
@cache.write('foo', 'bar')
@cache.read('foo').should == 'bar'
end
it "should read and write hashes" do
@cache.write('foo', {:a => "b"})
@cache.read('foo').should == {:a => "b"}
end
it "should read and write integers" do
@cache.write('foo', 1)
@cache.read('foo').should == 1
end
it "should read and write nil" do
@cache.write('foo', nil)
@cache.read('foo').should be_nil
end
it "should return the stored value when fetching on hit" do
@cache.write('foo', 'bar')
@cache.fetch('foo'){'baz'}.should == 'bar'
end
it "should return the default value when fetching on miss" do
@cache.fetch('foo'){ 'baz' }.should == 'baz'
end
it "should return the default value when forcing a miss" do
@cache.fetch('foo', :force => true){'bar'}.should == 'bar'
end
it "should detect if a value exists in the cache" do
@cache.write('foo', 'bar')
@cache.exist?('foo').should be_true
end
it "should delete matching keys from the cache" do
@cache.write('foo', 'bar')
@cache.write('green', 'thumb')
@cache.delete_matched(/foo/)
@cache.read('foo').should be_nil
@cache.read('green').should == 'thumb'
end
it "should delete a single key from the cache" do
@cache.write('foo', 'bar')
@cache.read('foo').should == 'bar'
@cache.delete('foo')
@cache.read('foo').should be_nil
end
end