Ready for 7.10.29 development.

This commit is contained in:
Colin Kuskie 2013-03-20 21:38:23 -07:00
commit c806f99b7b
4236 changed files with 1217679 additions and 0 deletions

50
t/Cache/CHI.t Normal file
View file

@ -0,0 +1,50 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Test the CHI cache driver
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 3; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
use_ok( 'WebGUI::Cache::CHI' );
WebGUI::Test->originalConfig('cacheType');
WebGUI::Test->originalConfig('cache');
$session->config->set('cacheType', 'WebGUI::Cache::CHI');
$session->config->set('cache', { driver => 'FastMmap', });
my $cache = WebGUI::Cache::CHI->new($session, "this", "that");
my $testValue = "a rock that has no earthly business in that field";
$cache->set($testValue);
is($cache->get, $testValue, "set/get works");
$cache->delete;
is($cache->get, undef, "delete works");
#vim:ft=perl

79
t/Cache/Database.t Normal file
View file

@ -0,0 +1,79 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Storable qw(freeze thaw);
use Test::More;
use Time::HiRes;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Cache::Database;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
# presupposes that there are cached items to test
my $cacheEntries = $session->db->buildArrayRefOfHashRefs("select expires,cachekey,namespace,content from cache order by rand() limit 100");
#----------------------------------------------------------------------------
# Tests
plan tests => 2 + scalar(@{$cacheEntries}); # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
my $cache = WebGUI::Cache::Database->new($session, "this", "that");
my $testValue = "a rock that has no earthly business in that field";
$cache->set($testValue);
is($cache->get, $testValue, "set/get works");
$cache->delete;
is($cache->get, undef, "delete works");
# performance tests
my $numTests = 0;
my $totalTime = 0;
foreach my $entry (@{$cacheEntries}) {
my $start = [Time::HiRes::gettimeofday];
my $cache = WebGUI::Cache::Database->new($session, $entry->{cachekey}, $entry->{namespace});
$cache->{_key} = $entry->{cachekey}; # evil: don't do this at home kids
my $value = $cache->get;
if ($entry->{expires} > time()) {
my $entryValue = $entry->{content};
eval { $entryValue = thaw($entryValue); };
$entryValue = ($entryValue && ref $entryValue) ? $$entryValue : undef;
is_deeply($value, $entryValue, "cache entry is valid");
}
else {
is($value, undef, "cache entry has timed out");
}
$numTests++;
$totalTime += Time::HiRes::tv_interval($start);
}
print "\nTime to run $numTests cache tests is $totalTime seconds. Average time per test is ".($totalTime/$numTests)." seconds.\n" if ($numTests > 0);
# end performance tests
#----------------------------------------------------------------------------
# Cleanup
END {
}

115
t/Cache/FileCache.t Normal file
View file

@ -0,0 +1,115 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::Deep;
use Path::Class;
use File::Path;
use File::Basename qw(basename);
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Cache;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 14;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
# put your tests here
my $origCacheType = $session->config->get('cacheType');
$session->config->set('cacheType', 'WebGUI::Cache::FileCache');
my $origCacheRoot = $session->config->get('fileCacheRoot');
$session->config->delete('fileCacheRoot');
my $loaded = use_ok('WebGUI::Cache::FileCache');
SKIP: {
skip 'Unable to load module WebGUI::Cache::FileCache', $tests unless $loaded;
my $cacher = WebGUI::Cache->new($session, 'ReservedForTests');
isa_ok($cacher, 'WebGUI::Cache::FileCache', 'WebGUI::Cache creates the correct object type');
isa_ok($cacher->session, 'WebGUI::Session', 'session method returns a session object');
cmp_deeply(
$cacher,
noclass({
_session => ignore(),
_namespace => basename(WebGUI::Test->file),
_key => re('[a-zA-Z0-9+\-]{22}'),
}),
'New FileCache object has correct defaults',
);
$cacher = WebGUI::Cache->new($session, 'ReservedForTests', 'ReservedForTests');
cmp_deeply(
$cacher,
noclass({
_session => ignore(),
_namespace => 'ReservedForTests',
_key => re('[a-zA-Z0-9+\-]{22}'),
}),
'Second fileCache object was recreated with custom namespace',
);
my $root = '/tmp'; ##Default for Unix testing. Need to extend this for Windows someday...
my $namespace = Path::Class::Dir->new($root, qw/WebGUICache ReservedForTests/);
is($cacher->getNamespaceRoot, $namespace->stringify, 'getNamespaceRoot returns the correct path');
ok(! -e $cacher->getNamespaceRoot, 'The namespace does not exist in the filesystem');
my $folder = $namespace->subdir($cacher->{_key});
is($cacher->getFolder, $folder->stringify, 'getFolder returns the correct path, which is the namespace with a key subdirectory');
ok(! -e $cacher->getFolder, 'The folder does not exist in the filesystem');
$cacher->set('Some value');
ok( -e $namespace->stringify, 'setting data into the cache creates the namespace dir');
ok( -e $folder->stringify, 'setting data into the cache creates the folder dir');
ok( -e $folder->file('expires')->stringify, 'expiry file was created');
ok( -e $folder->file('cache')->stringify, 'cache file was created');
$cacher->delete();
ok(! -e $cacher->getFolder, 'delete removes the cache folder');
$cacher->flush();
ok(! -e $cacher->getNamespaceRoot, 'purge removes the namespace folder');
undef $cacher;
}
#----------------------------------------------------------------------------
# Cleanup
END {
$session->config->set('cacheType', $origCacheType);
if ($origCacheRoot) {
$session->config->get('fileCacheRoot', $origCacheRoot);
}
}