Mercurial > hg > Cache-Memcached
comparison t/03_stats.t @ 0:17fc6afc155e CACHE_MEMCACHED_1_24
Cache::Memcached 1.24
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 30 Sep 2007 16:23:31 +0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:17fc6afc155e |
---|---|
1 # -*-perl-*- | |
2 | |
3 use strict; | |
4 use Test::More; | |
5 use Cache::Memcached; | |
6 use IO::Socket::INET; | |
7 | |
8 my $testaddr = "127.0.0.1:11211"; | |
9 my $msock = IO::Socket::INET->new(PeerAddr => $testaddr, | |
10 Timeout => 3); | |
11 | |
12 my @misc_stats_keys = qw/ bytes bytes_read bytes_written | |
13 cmd_get cmd_set connection_structures curr_items | |
14 get_hits get_misses | |
15 total_connections total_items | |
16 /; | |
17 | |
18 if ($msock) { | |
19 plan tests => 24 + scalar(@misc_stats_keys); | |
20 } else { | |
21 plan skip_all => "No memcached instance running at $testaddr\n"; | |
22 exit 0; | |
23 } | |
24 | |
25 my $memd = Cache::Memcached->new({ | |
26 servers => [ $testaddr ], | |
27 namespace => "Cache::Memcached::t/$$/" . (time() % 100) . "/", | |
28 }); | |
29 | |
30 my $misc_stats = $memd->stats('misc'); | |
31 ok($misc_stats, 'got misc stats'); | |
32 isa_ok($misc_stats, 'HASH', 'misc stats'); | |
33 isa_ok($misc_stats->{'total'}, 'HASH', 'misc stats total'); | |
34 isa_ok($misc_stats->{'hosts'}, 'HASH', 'misc stats hosts'); | |
35 isa_ok($misc_stats->{'hosts'}{$testaddr}, 'HASH', | |
36 "misc stats hosts $testaddr"); | |
37 | |
38 foreach my $stat_key (@misc_stats_keys) { | |
39 ok(exists $misc_stats->{'total'}{$stat_key}, | |
40 "misc stats total contains $stat_key"); | |
41 ok(exists $misc_stats->{'hosts'}{$testaddr}{'misc'}{$stat_key}, | |
42 "misc stats hosts $testaddr misc contains $stat_key"); | |
43 } | |
44 | |
45 my $got_malloc = 0; | |
46 foreach my $stat_key (keys %{$misc_stats->{'total'}}) { | |
47 if ($stat_key =~ /^malloc/) { | |
48 $got_malloc = 1; | |
49 last; | |
50 } | |
51 } | |
52 ok(! $got_malloc, 'no malloc stats in misc stats'); | |
53 | |
54 my $malloc_stats = $memd->stats('malloc'); | |
55 ok($malloc_stats, 'got malloc stats'); | |
56 isa_ok($malloc_stats, 'HASH', 'malloc stats'); | |
57 isa_ok($malloc_stats->{'total'}, 'HASH', 'malloc stats total'); | |
58 isa_ok($misc_stats->{'hosts'}, 'HASH', 'malloc stats hosts'); | |
59 isa_ok($misc_stats->{'hosts'}{$testaddr}, 'HASH', | |
60 "malloc stats host $testaddr"); | |
61 | |
62 $got_malloc = 0; | |
63 foreach my $stat_key (keys %{$malloc_stats->{'total'}}) { | |
64 if ($stat_key =~ /^malloc/) { | |
65 $got_malloc = 1; | |
66 last; | |
67 } | |
68 } | |
69 ok($got_malloc, 'malloc stats in malloc stats'); | |
70 | |
71 my $got_misc = 0; | |
72 foreach my $stat_key (@misc_stats_keys) { | |
73 if (exists $malloc_stats->{'total'}{$stat_key}) { | |
74 $got_misc = 1; | |
75 last; | |
76 } | |
77 } | |
78 ok(! $got_misc, 'no misc stats in malloc stats'); |