root/trunk/server/t/incrdecr.t @ 619

Revision 619, 1.5 kB (checked in by plindner, 2 years ago)

Switch to unsigned 64-bit increment/decrement counters from Evan Miller and Dusgtin Sallings.

  • Property svn:executable set to *
Line 
1#!/usr/bin/perl
2
3use strict;
4use Test::More tests => 17;
5use FindBin qw($Bin);
6use lib "$Bin/lib";
7use MemcachedTest;
8
9my $server = new_memcached();
10my $sock = $server->sock;
11
12print $sock "set num 0 0 1\r\n1\r\n";
13is(scalar <$sock>, "STORED\r\n", "stored num");
14mem_get_is($sock, "num", 1, "stored 1");
15
16print $sock "incr num 1\r\n";
17is(scalar <$sock>, "2\r\n", "+ 1 = 2");
18mem_get_is($sock, "num", 2);
19
20print $sock "incr num 8\r\n";
21is(scalar <$sock>, "10\r\n", "+ 8 = 10");
22mem_get_is($sock, "num", 10);
23
24print $sock "decr num 1\r\n";
25is(scalar <$sock>, "9\r\n", "- 1 = 9");
26
27print $sock "decr num 9\r\n";
28is(scalar <$sock>, "0\r\n", "- 9 = 0");
29
30print $sock "decr num 5\r\n";
31is(scalar <$sock>, "0\r\n", "- 5 = 0");
32
33printf $sock "set num 0 0 10\r\n4294967296\r\n";
34is(scalar <$sock>, "STORED\r\n", "stored 2**32");
35
36print $sock "incr num 1\r\n";
37is(scalar <$sock>, "4294967297\r\n", "4294967296 + 1 = 4294967297");
38
39printf $sock "set num 0 0 %d\r\n18446744073709551615\r\n", length("18446744073709551615");
40is(scalar <$sock>, "STORED\r\n", "stored 2**64-1");
41
42print $sock "incr num 1\r\n";
43is(scalar <$sock>, "0\r\n", "(2**64 - 1) + 1 = 0");
44
45print $sock "decr bogus 5\r\n";
46is(scalar <$sock>, "NOT_FOUND\r\n", "can't decr bogus key");
47
48print $sock "decr incr 5\r\n";
49is(scalar <$sock>, "NOT_FOUND\r\n", "can't incr bogus key");
50
51print $sock "set text 0 0 2\r\nhi\r\n";
52is(scalar <$sock>, "STORED\r\n", "stored text");
53print $sock "incr text 1\r\n";
54is(scalar <$sock>, "1\r\n", "hi - 1 = 0");
Note: See TracBrowser for help on using the browser.