Changing the Cacher.invalidate method to Cacher.expire.

Signed-off-by: Luke Kanies <luke@madstop.com>
This commit is contained in:
Luke Kanies 2008-11-11 10:47:32 -06:00
Родитель 99a0770a30
Коммит 14af971bc6
30 изменённых файлов: 54 добавлений и 56 удалений

Просмотреть файл

@ -28,7 +28,7 @@ module Puppet::Network::HttpPool
http_cache.each do |name, connection|
connection.finish if connection.started?
end
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
# Make sure we set the driver up when we read the cert in.

Просмотреть файл

@ -2,11 +2,11 @@ module Puppet::Util::Cacher
# It's basically not possible to test that this is set,
# but we need to start with a value so that all initial values
# start out valid -- that is, everything's valid until the
# first call to 'invalidate'.
# first call to 'expire'.
@timestamp = Time.now
# Cause all cached values to be considered expired.
def self.invalidate
def self.expire
@timestamp = Time.now
end
@ -70,6 +70,11 @@ module Puppet::Util::Cacher
class Cache
attr_accessor :caches, :timestamp
def clear
caches.clear
self.timestamp = Time.now
end
def initialize
@caches = {}
@timestamp = Time.now
@ -90,8 +95,7 @@ module Puppet::Util::Cacher
# clear other cached values, too (if this instance is caching more
# than one value).
if expired?
caches.clear
self.timestamp = Time.now
clear
end
# Generate a new value if we don't have one. Use 'include?' here

Просмотреть файл

@ -10,7 +10,7 @@ require 'puppet/file_serving/configuration'
describe Puppet::FileServing::Configuration, " when finding files with Puppet::FileServing::Mount" do
before do
# Just in case it already exists.
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
@mount = Puppet::FileServing::Mount.new("mymount")
FileTest.stubs(:exists?).with("/my/path").returns(true)
@ -38,6 +38,6 @@ describe Puppet::FileServing::Configuration, " when finding files with Puppet::F
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -16,5 +16,5 @@ describe Puppet::FileServing::Content, " when finding files" do
@indirection = Puppet::FileServing::Content.indirection
end
after { Puppet::Util::Cacher.invalidate }
after { Puppet::Util::Cacher.expire }
end

Просмотреть файл

@ -16,5 +16,5 @@ describe Puppet::FileServing::Metadata, " when finding files" do
@indirection = Puppet::FileServing::Metadata.indirection
end
after { Puppet::Util::Cacher.invalidate }
after { Puppet::Util::Cacher.expire }
end

Просмотреть файл

@ -21,7 +21,7 @@ describe "Certificate REST Terminus" do
Puppet.settings[:masterport] = "34343"
Puppet.settings[:http_enable_post_connection_check] = false
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet[:servertype] = 'webrick'
Puppet[:server] = '127.0.0.1'

Просмотреть файл

@ -8,7 +8,7 @@ require 'puppet/network/http/webrick/rest'
describe "Certificate Request REST Terminus" do
before do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet[:masterport] = 34343
Puppet[:server] = "localhost"

Просмотреть файл

@ -21,7 +21,7 @@ describe "Certificate REST Terminus" do
Puppet.settings[:masterport] = "34343"
Puppet.settings[:http_enable_post_connection_check] = false
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet[:servertype] = 'webrick'
Puppet[:server] = '127.0.0.1'
@ -59,7 +59,7 @@ describe "Certificate REST Terminus" do
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet.settings.clear
@server.unlisten
end

Просмотреть файл

@ -57,7 +57,7 @@ describe Puppet::Indirector::REST do
describe "when using webrick" do
before :each do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet[:servertype] = 'webrick'
Puppet[:server] = '127.0.0.1'

Просмотреть файл

@ -30,7 +30,7 @@ describe Puppet::Network::Server do
system("rm -rf %s" % @dir)
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
describe "before listening" do

Просмотреть файл

@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Catalog do
describe "when using the indirector" do
after { Puppet::Util::Cacher.invalidate }
after { Puppet::Util::Cacher.expire }
before do
# This is so the tests work w/out networking.
Facter.stubs(:to_hash).returns({"hostname" => "foo.domain.com"})

Просмотреть файл

@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Node::Facts do
describe "when using the indirector" do
after { Puppet::Util::Cacher.invalidate }
after { Puppet::Util::Cacher.expire }
it "should expire any cached node instances when it is saved" do
Puppet::Node::Facts.indirection.stubs(:terminus_class).returns :yaml

Просмотреть файл

@ -28,7 +28,7 @@ describe Puppet::SSL::CertificateAuthority do
system("rm -rf %s" % @dir)
Puppet.settings.clear
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet::SSL::CertificateAuthority.instance_variable_set("@instance", nil)
}

Просмотреть файл

@ -30,7 +30,7 @@ describe Puppet::SSL::CertificateRequest do
Puppet.settings.clear
# This is necessary so the terminus instances don't lie around.
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
it "should be able to generate CSRs" do

Просмотреть файл

@ -28,7 +28,7 @@ describe Puppet::SSL::CertificateRevocationList do
Puppet.settings.clear
# This is necessary so the terminus instances don't lie around.
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
}
it "should be able to read in written out CRLs with no revoked certificates" do

Просмотреть файл

@ -29,7 +29,7 @@ describe Puppet::SSL::Host do
system("rm -rf %s" % @dir)
Puppet.settings.clear
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
}
it "should be considered a CA host if its name is equal to 'ca'" do

Просмотреть файл

@ -7,7 +7,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Transaction::Report do
describe "when using the indirector" do
after { Puppet::Util::Cacher.invalidate }
after { Puppet::Util::Cacher.expire }
it "should be able to delegate to the :processor terminus" do
Puppet::Transaction::Report.indirection.stubs(:terminus_class).returns :processor

Просмотреть файл

@ -7,7 +7,7 @@ describe "Puppet::Indirector::FileServerTerminus", :shared => true do
# This only works if the shared behaviour is included before
# the 'before' block in the including context.
before do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
FileTest.stubs(:exists?).returns true
FileTest.stubs(:exists?).with(Puppet[:fileserverconfig]).returns(true)

Просмотреть файл

@ -15,12 +15,12 @@ describe Puppet::FileServing::Configuration do
it "should have a method for removing the current configuration instance" do
old = Puppet::FileServing::Configuration.create
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet::FileServing::Configuration.create.should_not equal(old)
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end
@ -32,7 +32,7 @@ describe Puppet::FileServing::Configuration do
end
after :each do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
describe Puppet::FileServing::Configuration, "when initializing" do

Просмотреть файл

@ -13,7 +13,7 @@ end
describe Puppet::FileServing::Mount do
it "should provide a method for clearing its cached host information" do
old = Puppet::FileServing::Mount.localmap
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet::FileServing::Mount.localmap.should_not equal(old)
end
end
@ -106,7 +106,7 @@ describe Puppet::FileServing::Mount, " when finding files" do
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -104,7 +104,7 @@ end
describe Puppet::Indirector::Indirection do
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
describe "when initializing" do
# (LAK) I've no idea how to test this, really.
@ -513,7 +513,7 @@ describe Puppet::Indirector::Indirection do
after :each do
@indirection.delete
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -8,7 +8,7 @@ require 'puppet/network/http_pool'
describe Puppet::Network::HttpPool do
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet::Network::HttpPool.clear_http_instances
Puppet::Network::HttpPool.instance_variable_set("@ssl_host", nil)
end

Просмотреть файл

@ -128,7 +128,7 @@ describe Puppet::Node, "when indirecting" do
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -860,7 +860,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
before do
@indirection = stub 'indirection', :name => :catalog
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
it "should redirect to the indirection for retrieval" do
@ -874,7 +874,7 @@ describe Puppet::Node::Catalog, " when indirecting" do
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -10,7 +10,7 @@ describe Puppet::Node::Facts, " when indirecting" do
# We have to clear the cache so that the facts ask for our indirection stub,
# instead of anything that might be cached.
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
@facts = Puppet::Node::Facts.new("me", "one" => "two")
end

Просмотреть файл

@ -6,7 +6,7 @@ require 'puppet/ssl/certificate_authority'
describe Puppet::SSL::CertificateAuthority do
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
Puppet.settings.clearused
end

Просмотреть файл

@ -35,6 +35,6 @@ describe Puppet::Transaction::Report, " when being indirect" do
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
end

Просмотреть файл

@ -46,51 +46,45 @@ describe "a cacher user using cached values", :shared => true do
@object.sa_cache.should equal(@object.sa_cache)
end
it "should use the block to generate new values if the cached values are invalid" do
it "should use the block to generate new values if the cached values are expired" do
Puppet::Util::Cacher.stubs(:valid?).returns false
@object.sa_cache.should_not equal(@object.sa_cache)
end
it "should still cache values after an invalidation" do
it "should still cache values after an expiration" do
# Load the cache
@object.sa_cache
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
@object.sa_cache.should equal(@object.sa_cache)
end
end
describe Puppet::Util::Cacher do
before do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
after do
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
it "should have a method for invalidating caches" do
Puppet::Util::Cacher.should respond_to(:invalidate)
it "should have a method for expiring caches" do
Puppet::Util::Cacher.should respond_to(:expire)
end
it "should have a method for determining whether a cached value is valid" do
Puppet::Util::Cacher.should respond_to(:valid?)
end
it "should consider cached values valid if the cached value was created and there was never an invalidation" do
Puppet::Util::Cacher.instance_variable_set("@timestamp", nil)
Puppet::Util::Cacher.should be_valid(Time.now)
end
it "should consider cached values valid if the cached value was created since the last invalidation" do
Puppet::Util::Cacher.invalidate
it "should consider cached values valid if the cached value was created since the last expiration" do
Puppet::Util::Cacher.expire
Puppet::Util::Cacher.should be_valid(Time.now + 1)
end
it "should consider cached values invalid if the cache was invalidated after the cached value was created" do
Puppet::Util::Cacher.invalidate
it "should consider cached values expired if the cache was expired after the cached value was created" do
Puppet::Util::Cacher.expire
Puppet::Util::Cacher.should_not be_valid(Time.now - 1)
end

Просмотреть файл

@ -302,7 +302,7 @@ module PuppetTest
Puppet::Util::Storage.clear
Puppet.clear
Puppet.settings.clear
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
@memoryatend = Puppet::Util.memory
diff = @memoryatend - @memoryatstart

Просмотреть файл

@ -18,7 +18,7 @@ class TestMaster < Test::Unit::TestCase
def teardown
super
Puppet::Util::Cacher.invalidate
Puppet::Util::Cacher.expire
end
def test_freshness_is_always_now