"Fossies" - the Fresh Open Source Software Archive

Member "memcached-1.6.15/t/incrdecr.t" (16 Jul 2020, 2157 Bytes) of package /linux/www/memcached-1.6.15.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.

    1 #!/usr/bin/perl
    2 
    3 use strict;
    4 use Test::More tests => 23;
    5 use FindBin qw($Bin);
    6 use lib "$Bin/lib";
    7 use MemcachedTest;
    8 
    9 my $server = new_memcached();
   10 my $sock = $server->sock;
   11 
   12 # Bug 21
   13 print $sock "set bug21 0 0 19\r\n9223372036854775807\r\n";
   14 is(scalar <$sock>, "STORED\r\n", "stored text");
   15 print $sock "incr bug21 1\r\n";
   16 is(scalar <$sock>, "9223372036854775808\r\n", "bug21 incr 1");
   17 print $sock "incr bug21 1\r\n";
   18 is(scalar <$sock>, "9223372036854775809\r\n", "bug21 incr 2");
   19 print $sock "decr bug21 1\r\n";
   20 is(scalar <$sock>, "9223372036854775808\r\n", "bug21 decr");
   21 
   22 print $sock "set num 0 0 1\r\n1\r\n";
   23 is(scalar <$sock>, "STORED\r\n", "stored num");
   24 mem_get_is($sock, "num", 1, "stored 1");
   25 
   26 print $sock "incr num 1\r\n";
   27 is(scalar <$sock>, "2\r\n", "+ 1 = 2");
   28 mem_get_is($sock, "num", 2);
   29 
   30 print $sock "incr num 8\r\n";
   31 is(scalar <$sock>, "10\r\n", "+ 8 = 10");
   32 mem_get_is($sock, "num", 10);
   33 
   34 print $sock "decr num 1\r\n";
   35 is(scalar <$sock>, "9\r\n", "- 1 = 9");
   36 
   37 print $sock "decr num 9\r\n";
   38 is(scalar <$sock>, "0\r\n", "- 9 = 0");
   39 
   40 print $sock "decr num 5\r\n";
   41 is(scalar <$sock>, "0\r\n", "- 5 = 0");
   42 
   43 printf $sock "set num 0 0 10\r\n4294967296\r\n";
   44 is(scalar <$sock>, "STORED\r\n", "stored 2**32");
   45 
   46 print $sock "incr num 1\r\n";
   47 is(scalar <$sock>, "4294967297\r\n", "4294967296 + 1 = 4294967297");
   48 
   49 printf $sock "set num 0 0 %d\r\n18446744073709551615\r\n", length("18446744073709551615");
   50 is(scalar <$sock>, "STORED\r\n", "stored 2**64-1");
   51 
   52 print $sock "incr num 1\r\n";
   53 is(scalar <$sock>, "0\r\n", "(2**64 - 1) + 1 = 0");
   54 
   55 print $sock "decr bogus 5\r\n";
   56 is(scalar <$sock>, "NOT_FOUND\r\n", "can't decr bogus key");
   57 
   58 print $sock "decr incr 5\r\n";
   59 is(scalar <$sock>, "NOT_FOUND\r\n", "can't incr bogus key");
   60 
   61 print $sock "set bigincr 0 0 1\r\n0\r\n";
   62 is(scalar <$sock>, "STORED\r\n", "stored bigincr");
   63 print $sock "incr bigincr 18446744073709551610\r\n";
   64 is(scalar <$sock>, "18446744073709551610\r\n");
   65 
   66 print $sock "set text 0 0 2\r\nhi\r\n";
   67 is(scalar <$sock>, "STORED\r\n", "stored hi");
   68 print $sock "incr text 1\r\n";
   69 is(scalar <$sock>,
   70    "CLIENT_ERROR cannot increment or decrement non-numeric value\r\n",
   71    "hi - 1 = 0");