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
|
# Setup test and strictness
use Test::More tests => 1 + ( 4 * 5 ) + 1 + 5;
use strict;
use warnings;
use lib '.';
# initializations
my $class= 'Cache::Memcached::Managed';
my $memcached_class= $ENV{CACHE_MEMCACHED} || 'Cache::Memcached';
my $base_config= "127.0.0.1";
# Make sure we have all the support routines
require 'testlib';
# Make sure class is loaded
use_ok($class);
# simple string config
my $port= anyport();
check_config( $port, "$base_config:$port",
'simple string config' );
# simple listref config
$port= anyport();
check_config( $port, [ "$base_config:$port" ],
'simple listref config' );
# hashref/string config
$port= anyport();
check_config( $port, { servers => "$base_config:$port" },
'hashref/string config' );
# hashref/listref config
$port= anyport();
check_config( $port, { servers => [ "$base_config:$port" ] },
'hashref/listref config' );
# object config
$port= anyport();
my $memcached= $memcached_class->new(
servers => [ "$base_config:$port" ],
);
isa_ok( $memcached, $memcached_class, "Check whether memcached object ok" );
check_config( $port, $memcached,
'object config' );
#-------------------------------------------------------------------------------
# check_config
#
# Check given port / config. Good for 5 tests.
#
# IN: 1 port
# 2 config
# 3 test message
sub check_config {
my ( $port, $config, $message )= @_;
ok( $port, "Check whether we have a port to work on for $message" );
# Create a cache object
my $cache= $class->new(
data => $config,
memcached_class => $memcached_class,
);
isa_ok( $cache, $class, "Check whether object ok for $message" );
# Start the server, skip further tests if failed
SKIP: {
skip( "Memcached server not started", 3 ) if !$cache->start;
sleep 2; # let the server warm up
diag("\nStarted memcached server for $message");
# Set/Get simple value here
my $value= 'value';
ok( $cache->set($value), "Check if simple set is ok for $message" );
is( $cache->get,$value, "Check if simple get is ok for $message" );
# Stop the server
ok( $cache->stop, "Check if all servers have stopped for $message" );
diag("\nStopped memcached server for $message");
} #SKIP
} #check_config
#-------------------------------------------------------------------------------
|