Skip to content
Browse files

Specs

  • Loading branch information...
1 parent 9f6873d commit 66fd5ed6ea32ea4bc9e34b3e25fbda1d470e6601 @winton committed Oct 10, 2011
Showing with 98 additions and 6 deletions.
  1. +2 −2 lib/execache.rb
  2. +2 −0 lib/execache/client.rb
  3. +94 −4 spec/execache_spec.rb
View
4 lib/execache.rb
@@ -26,7 +26,7 @@ def initialize(yaml)
while true
request = redis.lpop('execache:request')
if request
- #Thread.new do
+ Thread.new do
request = Yajl::Parser.parse(request)
channel = request.delete('channel')
commands = []
@@ -93,7 +93,7 @@ def initialize(yaml)
"execache:response:#{channel}",
Yajl::Encoder.encode(response)
)
- #end
+ end
end
sleep(1.0 / 1000.0)
end
View
2 lib/execache/client.rb
@@ -1,6 +1,8 @@
class Execache
class Client
+ attr_reader :redis_1, :redis_2
+
def initialize(redis_url)
@redis_1 = Redis.connect(:url => "redis://#{redis_url}")
@redis_2 = Redis.connect(:url => "redis://#{redis_url}")
View
98 spec/execache_spec.rb
@@ -2,32 +2,122 @@
describe Execache do
+ def client_exec
+ @client.exec(
+ :some_binary => {
+ :args => 'preliminary_arg',
+ :groups => [
+ {
+ :args => 'arg1a arg1b',
+ :ttl => 60
+ },
+ {
+ :args => 'arg2a arg2b',
+ :ttl => 60
+ }
+ ]
+ }
+ )
+ end
+
before(:all) do
@thread = Thread.new do
Execache.new("#{$root}/spec/fixtures/execache.yml")
end
@client = Execache::Client.new("localhost:6379/0")
+ @client.redis_1.keys("execache:cache:*").each do |key|
+ @client.redis_1.del(key)
+ end
end
after(:all) do
@thread.kill
end
- it "should" do
- puts @client.exec(
+ it "should return proper results" do
+ client_exec.should == {
+ "some_binary" => [
+ ["arg1_result_1", "arg1_result_2"],
+ ["arg2_result_1", "arg2_result_2"]
+ ]
+ }
+ end
+
+ it "should write to cache" do
+ keys = @client.redis_1.keys("execache:cache:*")
+ keys.length.should == 2
+ end
+
+ it "should read from cache" do
+ keys = @client.redis_1.keys("execache:cache:*")
+ @client.redis_1.set(keys[0], "[\"cached!\"]")
+ @client.redis_1.set(keys[1], "[\"cached!\"]")
+ client_exec.should == {
+ "some_binary" => [
+ ["cached!"],
+ ["cached!"]
+ ]
+ }
+ end
+
+ it "should read from cache for individual groups" do
+ @client.exec(
+ :some_binary => {
+ :args => 'preliminary_arg',
+ :groups => [
+ {
+ :args => 'arg2a arg2b',
+ :ttl => 60
+ }
+ ]
+ }
+ ).should == {
+ "some_binary" => [
+ ["cached!"]
+ ]
+ }
+
+ @client.exec(
:some_binary => {
:args => 'preliminary_arg',
:groups => [
{
:args => 'arg1a arg1b',
:ttl => 60
- },
+ }
+ ]
+ }
+ ).should == {
+ "some_binary" => [
+ ["cached!"]
+ ]
+ }
+ end
+
+ it "should not read cache if preliminary arg changes" do
+ @client.exec(
+ :some_binary => {
+ :args => 'preliminary_arg2',
+ :groups => [
{
:args => 'arg2a arg2b',
:ttl => 60
}
]
}
- ).inspect
+ ).should == {
+ "some_binary" => [
+ ["arg1_result_1", "arg1_result_2"]
+ ]
+ }
+ end
+
+ it "should still read from original cache" do
+ client_exec.should == {
+ "some_binary" => [
+ ["cached!"],
+ ["cached!"]
+ ]
+ }
end
end

0 comments on commit 66fd5ed

Please sign in to comment.
Something went wrong with that request. Please try again.