forked from dyoder/waves
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
currently working on threaded unit tests.
- Loading branch information
ab5tract
committed
Sep 24, 2008
1 parent
efd87cc
commit 6219596
Showing
7 changed files
with
84 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
module Waves | ||
|
||
module Cache | ||
|
||
# Looks barebones in here, huh? | ||
# That's because the Waves::Cache API is implemented in a separate file. | ||
require 'cache/cache-ipi' # iPi stands for Implemented Programming Interface, aka inherently interchangeable. | ||
|
||
|
||
# Waves::Cache module also has some... | ||
# Exception classes | ||
class KeyMissing < StandardError; end | ||
class KeyExpired < StandardError; end | ||
|
||
# ...and a class method to initiate the iPi seamlessly. (see layers/cache/file* for an example of a layered iPi) | ||
def self.new | ||
Waves::Cache::IPI.new | ||
end | ||
|
||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,85 @@ | ||
# require 'test_helper' because RubyMate needs help | ||
require File.join(File.dirname(__FILE__) , "helpers") | ||
|
||
Waves::Console.load( :mode => 'development', :startup => "#{File.dirname(__FILE__)}/../../app/startup.rb") | ||
|
||
describe "An instance of Waves::Cache::IPI" do | ||
|
||
before do | ||
@cache = Waves::Cache::IPI.new | ||
end | ||
|
||
it "can store and retrieve a value using a key" do | ||
@cache[:key1] = "value1" | ||
@cache[:key1].should == "value1" | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
@cache[:key1] = "value1" | ||
@cache[:key1].should == "value1" | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
end | ||
|
||
feature "can retrieve multiple items" do | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache.values_at( :a, :b ) | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
Thread.stop | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache.values_at( :a, :b ) | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
end | ||
|
||
it "can set a time-to-live in seconds for an item" do | ||
@cache.store(:key1,"value3", 0.01) | ||
@cache.store(:key2,"value3", 0.03) | ||
sleep( 0.02 ) | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == true | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
Thread.stop | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache.store(:key1,"value3", 0.01) | ||
@cache.store(:key2,"value3", 0.03) | ||
sleep( 0.02 ) | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == true | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
|
||
lambda { @cache.store(:a, :b, "3") }.should.raise TypeError | ||
end | ||
|
||
it "can delete a value from the cache" do | ||
@cache[:key1] = "value0" | ||
@cache.delete( :key1 ) | ||
@cache.exists?( :key1 ).should == false | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
Thread.stop | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache[:key1] = "value0" | ||
@cache.delete( :key1 ) | ||
@cache.exists?( :key1 ).should == false | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
end | ||
|
||
it "can delete multiple values from the cache" do | ||
@cache[:key1], @cache[:key2] = "value1", "value2" | ||
@cache.delete :key1, :key2 | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == false | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
Thread.stop | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache[:key1], @cache[:key2] = "value1", "value2" | ||
@cache.delete :key1, :key2 | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == false | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
end | ||
|
||
it "can clear the cache" do | ||
@cache[:key1], @cache[:key2] = "value1", "value2" | ||
@cache.clear | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == false | ||
threads =[]; 5.times do | ||
threads << Thread.new do | ||
Thread.stop | ||
@cache[:a], @cache[:b], @cache[:c] = 1, 2, 3 | ||
@cache[:key1], @cache[:key2] = "value1", "value2" | ||
@cache.clear | ||
@cache.exists?(:key1).should == false | ||
@cache.exists?(:key2).should == false | ||
end; end | ||
threads.each {|t| t.run; t.join } | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Helpers for testing cache | ||
require "#{File.dirname(__FILE__)}/../helpers" | ||
require 'cache/cache-ipi.rb' | ||
require 'cache/cache' |