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