"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.9/t/stats.t" (21 Nov 2020, 5685 Bytes) of package /linux/www/memcached-1.6.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "stats.t": 1.6.8_vs_1.6.9.

    1 #!/usr/bin/perl
    2 
    3 use strict;
    4 use Test::More tests => 108;
    5 use FindBin qw($Bin);
    6 use lib "$Bin/lib";
    7 use MemcachedTest;
    8 
    9 my $server = new_memcached("-o no_lru_crawler,no_lru_maintainer");
   10 my $sock = $server->sock;
   11 
   12 
   13 ## Output looks like this:
   14 ##
   15 ## STAT pid 22969
   16 ## STAT uptime 13
   17 ## STAT time 1259170891
   18 ## STAT version 1.4.3
   19 ## STAT libevent 1.4.13-stable.
   20 ## see doc/protocol.txt for others
   21 # note that auth stats are tested in auth specific tests
   22 
   23 
   24 my $stats = mem_stats($sock);
   25 
   26 # Test number of keys
   27 if (MemcachedTest::enabled_tls_testing()) {
   28     # when TLS is enabled, stats contains additional keys:
   29     #   - ssl_handshake_errors
   30     #   - time_since_server_cert_refresh
   31     is(scalar(keys(%$stats)), 82, "expected count of stats values");
   32 } else {
   33     is(scalar(keys(%$stats)), 80, "expected count of stats values");
   34 }
   35 
   36 # Test initial state
   37 foreach my $key (qw(curr_items total_items bytes cmd_get cmd_set get_hits evictions get_misses get_expired
   38                  bytes_written delete_hits delete_misses incr_hits incr_misses decr_hits get_flushed
   39                  decr_misses listen_disabled_num lrutail_reflocked time_in_listen_disabled_us)) {
   40     is($stats->{$key}, 0, "initial $key is zero");
   41 }
   42 is($stats->{accepting_conns}, 1, "initial accepting_conns is one");
   43 
   44 # Do some operations
   45 
   46 print $sock "set foo 0 0 6\r\nfooval\r\n";
   47 is(scalar <$sock>, "STORED\r\n", "stored foo");
   48 mem_get_is($sock, "foo", "fooval");
   49 
   50 my $stats = mem_stats($sock);
   51 
   52 foreach my $key (qw(total_items curr_items cmd_get cmd_set get_hits)) {
   53     is($stats->{$key}, 1, "after one set/one get $key is 1");
   54 }
   55 
   56 my $cache_dump = mem_stats($sock, " cachedump 1 100");
   57 ok(defined $cache_dump->{'foo'}, "got foo from cachedump");
   58 
   59 print $sock "delete foo\r\n";
   60 is(scalar <$sock>, "DELETED\r\n", "deleted foo");
   61 
   62 my $stats = mem_stats($sock);
   63 is($stats->{delete_hits}, 1);
   64 is($stats->{delete_misses}, 0);
   65 
   66 print $sock "delete foo\r\n";
   67 is(scalar <$sock>, "NOT_FOUND\r\n", "shouldn't delete foo again");
   68 
   69 my $stats = mem_stats($sock);
   70 is($stats->{delete_hits}, 1);
   71 is($stats->{delete_misses}, 1);
   72 
   73 # incr stats
   74 
   75 sub check_incr_stats {
   76     my ($ih, $im, $dh, $dm) = @_;
   77     my $stats = mem_stats($sock);
   78 
   79     is($stats->{incr_hits}, $ih);
   80     is($stats->{incr_misses}, $im);
   81     is($stats->{decr_hits}, $dh);
   82     is($stats->{decr_misses}, $dm);
   83 }
   84 
   85 print $sock "incr i 1\r\n";
   86 is(scalar <$sock>, "NOT_FOUND\r\n", "shouldn't incr a missing thing");
   87 check_incr_stats(0, 1, 0, 0);
   88 
   89 print $sock "decr d 1\r\n";
   90 is(scalar <$sock>, "NOT_FOUND\r\n", "shouldn't decr a missing thing");
   91 check_incr_stats(0, 1, 0, 1);
   92 
   93 print $sock "set n 0 0 1\r\n0\r\n";
   94 is(scalar <$sock>, "STORED\r\n", "stored n");
   95 
   96 print $sock "incr n 3\r\n";
   97 is(scalar <$sock>, "3\r\n", "incr works");
   98 check_incr_stats(1, 1, 0, 1);
   99 
  100 print $sock "decr n 1\r\n";
  101 is(scalar <$sock>, "2\r\n", "decr works");
  102 check_incr_stats(1, 1, 1, 1);
  103 
  104 # cas stats
  105 
  106 sub check_cas_stats {
  107     my ($ch, $cm, $cb) = @_;
  108     my $stats = mem_stats($sock);
  109 
  110     is($stats->{cas_hits}, $ch);
  111     is($stats->{cas_misses}, $cm);
  112     is($stats->{cas_badval}, $cb);
  113 }
  114 
  115 check_cas_stats(0, 0, 0);
  116 
  117 print $sock "cas c 0 0 1 99999999\r\nz\r\n";
  118 is(scalar <$sock>, "NOT_FOUND\r\n", "missed cas");
  119 check_cas_stats(0, 1, 0);
  120 
  121 print $sock "set c 0 0 1\r\nx\r\n";
  122 is(scalar <$sock>, "STORED\r\n", "stored c");
  123 my ($id, $v) = mem_gets($sock, 'c');
  124 is('x', $v, 'got the expected value');
  125 
  126 print $sock "cas c 0 0 1 99999999\r\nz\r\n";
  127 is(scalar <$sock>, "EXISTS\r\n", "missed cas");
  128 check_cas_stats(0, 1, 1);
  129 my ($newid, $v) = mem_gets($sock, 'c');
  130 is('x', $v, 'got the expected value');
  131 
  132 print $sock "cas c 0 0 1 $id\r\nz\r\n";
  133 is(scalar <$sock>, "STORED\r\n", "good cas");
  134 check_cas_stats(1, 1, 1);
  135 my ($newid, $v) = mem_gets($sock, 'c');
  136 is('z', $v, 'got the expected value');
  137 
  138 my $settings = mem_stats($sock, ' settings');
  139 is(1024, $settings->{'maxconns'});
  140 # we run SSL tests over TCP; hence the domain_socket
  141 # is expected to be NULL.
  142 if (enabled_tls_testing() || !supports_unix_socket()) {
  143     is('NULL', $settings->{'domain_socket'});
  144 } else {
  145     isnt('NULL', $settings->{'domain_socket'});
  146 }
  147 is('on', $settings->{'evictions'});
  148 is('yes', $settings->{'cas_enabled'});
  149 is('no', $settings->{'auth_enabled_sasl'});
  150 
  151 print $sock "stats reset\r\n";
  152 is(scalar <$sock>, "RESET\r\n", "good stats reset");
  153 
  154 my $stats = mem_stats($sock);
  155 is(0, $stats->{'cmd_get'});
  156 is(0, $stats->{'cmd_set'});
  157 is(0, $stats->{'get_hits'});
  158 is(0, $stats->{'get_misses'});
  159 is(0, $stats->{'get_expired'});
  160 is(0, $stats->{'get_flushed'});
  161 is(0, $stats->{'delete_misses'});
  162 is(0, $stats->{'delete_hits'});
  163 is(0, $stats->{'incr_misses'});
  164 is(0, $stats->{'incr_hits'});
  165 is(0, $stats->{'decr_misses'});
  166 is(0, $stats->{'decr_hits'});
  167 is(0, $stats->{'cas_misses'});
  168 is(0, $stats->{'cas_hits'});
  169 is(0, $stats->{'cas_badval'});
  170 is(0, $stats->{'evictions'});
  171 is(0, $stats->{'reclaimed'});
  172 is(0, $stats->{'lrutail_reflocked'});
  173 
  174 # item expired
  175 print $sock "set should_expire 0 2678400 6\r\nfooval\r\n"; #2678400 = 31 days in seconds
  176 is(scalar <$sock>, "STORED\r\n", "set item to expire");
  177 print $sock "get should_expire\r\n";
  178 is(scalar <$sock>, "END\r\n", "item not returned");
  179 my $stats = mem_stats($sock);
  180 is(1, $stats->{'get_expired'}, "get_expired counter is 1");
  181 
  182 print $sock "set should_be_flushed 0 0 6\r\nbooval\r\n";
  183 is(scalar <$sock>, "STORED\r\n", "set item to flush");
  184 print $sock "flush_all\r\n";
  185 is(scalar <$sock>, "OK\r\n", "flushed");
  186 print $sock "get should_be_flushed\r\n";
  187 is(scalar <$sock>, "END\r\n", "flushed item not returned");
  188 
  189 my $stats = mem_stats($sock);
  190 is($stats->{cmd_flush}, 1, "after one flush cmd_flush is 1");
  191 is($stats->{get_flushed}, 1, "after flush and a get, get_flushed is 1");