| 1 | package CHI::Driver::MemcachedFast::t::CHIDriverTests; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use CHI::Test; | ||
| 5 | use CHI::Driver::MemcachedFast::Test::Driver; | ||
| 6 | use base qw(CHI::t::Driver); | ||
| 7 | |||
| 8 | my $testaddr = "127.0.0.1:11211"; | ||
| 9 | |||
| 10 | sub required_modules { | ||
| 11 | return { 'Cache::Memcached' => undef, 'IO::Socket::INET' => undef }; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub connect_to_memcached : Test(startup) { | ||
| 15 | my $self = shift; | ||
| 16 | require IO::Socket::INET; | ||
| 17 | my $msock = IO::Socket::INET->new( | ||
| 18 | PeerAddr => $testaddr, | ||
| 19 | Timeout => 3 | ||
| 20 | ); | ||
| 21 | if ( !$msock ) { | ||
| 22 | $self->SKIP_ALL("No memcached instance running at $testaddr"); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | sub clear_memcached : Test(setup) { | ||
| 27 | my ($self) = @_; | ||
| 28 | |||
| 29 | my $cache = $self->new_cache(); | ||
| 30 | $cache->memd->flush_all(); | ||
| 31 | } | ||
| 32 | |||
| 33 | sub new_cache_options { | ||
| 34 | my $self = shift; | ||
| 35 | |||
| 36 | # CHI::Driver::Memcached::Test::Driver defines get_keys for testing purposes | ||
| 37 | return ( | ||
| 38 | $self->SUPER::new_cache_options(), | ||
| 39 | driver => undef, | ||
| 40 | driver_class => 'CHI::Driver::Memcached::Test::Driver', | ||
| 41 | servers => [$testaddr] | ||
| 42 | ); | ||
| 43 | } | ||
| 44 | |||
| 45 | sub set_standard_keys_and_values { | ||
| 46 | my ($self) = @_; | ||
| 47 | |||
| 48 | my ( $keys, $values ) = $self->SUPER::set_standard_keys_and_values(); | ||
| 49 | |||
| 50 | # memcached keys have max length of 250, plus we're adding namespace | ||
| 51 | $keys->{'large'} = scalar( 'ab' x 100 ); | ||
| 52 | |||
| 53 | # memcached keys must not include control characters or whitespace | ||
| 54 | $keys->{'space'} = 'space'; | ||
| 55 | $keys->{'mixed'} = 'mixed'; | ||
| 56 | |||
| 57 | return ( $keys, $values ); | ||
| 58 | } | ||
| 59 | |||
| 60 | sub test_get_keys : Test(1) { | ||
| 61 | my $self = shift; | ||
| 62 | |||
| 63 | # Make sure we get a 'not supported' error with regular memcached driver | ||
| 64 | my $cache = | ||
| 65 | $self->SUPER::new_cache( driver => 'Memcached', servers => [$testaddr] ); | ||
| 66 | throws_ok( | ||
| 67 | sub { $cache->get_keys() }, | ||
| 68 | qr/not supported/, | ||
| 69 | "get_keys not supported" | ||
| 70 | ); | ||
| 71 | } | ||
| 72 | |||
| 73 | 1; |