1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: arrays assocs calendar io io.encodings.binary io.sockets
5 io.timeouts kernel math math.functions memcached
6 memcached.private namespaces present sequences sorting system
11 ! Use a version of with-memcached that sets a timeout
12 : with-memcached ( quot -- )
13 [ 5 seconds input-stream get set-timeout ] prepose
14 memcached:with-memcached ; inline
18 : not-found? ( quot -- )
19 [ key-not-found? ] must-fail-with ;
21 : x ( -- str ) cpu present "-x" append ;
22 : y ( -- str ) cpu present "-y" append ;
23 : z ( -- str ) cpu present "-z" append ;
28 { t } [ [ m/version ] with-memcached length 0 > ] unit-test
31 [ m/flush ] with-memcached
32 [ "valuex" x m/set ] with-memcached
33 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
36 [ m/flush ] with-memcached
37 [ "valuex" x m/set "valuey" y m/set ] with-memcached
38 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
39 { "valuey" } [ [ y m/get ] with-memcached ] unit-test
40 [ m/flush ] with-memcached
41 [ [ x m/get ] with-memcached ] not-found?
42 [ [ y m/get ] with-memcached ] not-found?
45 [ m/noop ] with-memcached
48 [ m/flush ] with-memcached
49 [ "valuex" x m/set ] with-memcached
50 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
51 [ x m/delete ] with-memcached
52 [ [ x m/get ] with-memcached ] not-found?
55 [ m/flush ] with-memcached
56 [ [ x m/get ] with-memcached ] not-found?
57 [ [ "ex" x m/replace ] with-memcached ] not-found?
58 [ "ex" x m/add ] with-memcached
59 { "ex" } [ [ x m/get ] with-memcached ] unit-test
60 [ "ex2" x m/replace ] with-memcached
61 { "ex2" } [ [ x m/get ] with-memcached ] unit-test
64 [ m/flush ] with-memcached
65 { 0 } [ [ x m/incr ] with-memcached ] unit-test
66 { 1 } [ [ x m/incr ] with-memcached ] unit-test
67 { 212 } [ [ 211 x m/incr-val ] with-memcached ] unit-test
68 { 8589934804 } [ [ 2 33 ^ x m/incr-val ] with-memcached ] unit-test
71 [ m/flush ] with-memcached
72 [ "5" x m/set ] with-memcached
73 { 4 } [ [ x m/decr ] with-memcached ] unit-test
74 { 0 } [ [ 211 x m/decr-val ] with-memcached ] unit-test
76 ! test timebombed flush
77 [ m/flush ] with-memcached
78 [ [ x m/get ] with-memcached ] not-found?
79 [ "valuex" x m/set ] with-memcached
80 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
81 [ 2 m/flush-later ] with-memcached
82 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
84 [ [ x m/get ] with-memcached ] not-found?
87 [ m/flush ] with-memcached
88 [ "some" x m/set ] with-memcached
89 [ "thing" x m/append ] with-memcached
90 { "something" } [ [ x m/get ] with-memcached ] unit-test
93 [ m/flush ] with-memcached
94 [ "some" x m/set ] with-memcached
95 [ "thing" x m/prepend ] with-memcached
96 { "thingsome" } [ [ x m/get ] with-memcached ] unit-test
99 [ m/flush ] with-memcached
100 { H{ } } [ [ x y z 3array m/getseq ] with-memcached ] unit-test
101 [ "5" x m/set ] with-memcached
102 [ "valuex" y m/set ] with-memcached
103 { { "5" "valuex" } } [
104 [ x y z 3array m/getseq values natural-sort ] with-memcached