]> gitweb.factorcode.org Git - factor.git/blob - extra/memcached/memcached-tests.factor
git: fix tests
[factor.git] / extra / memcached / memcached-tests.factor
1 ! Copyright (C) 2010 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3
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
7 threads tools.test ;
8
9 IN: memcached.tests
10
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
15
16 <PRIVATE
17
18 : not-found? ( quot -- )
19     [ key-not-found? ] must-fail-with ;
20
21 : x ( -- str ) cpu present "-x" append ;
22 : y ( -- str ) cpu present "-y" append ;
23 : z ( -- str ) cpu present "-z" append ;
24
25 PRIVATE>
26
27 ! test version
28 { t } [ [ m/version ] with-memcached length 0 > ] unit-test
29
30 ! test simple set get
31 [ m/flush ] with-memcached
32 [ "valuex" x m/set ] with-memcached
33 { "valuex" } [ [ x m/get ] with-memcached ] unit-test
34
35 ! test flush
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?
43
44 ! test noop
45 [ m/noop ] with-memcached
46
47 ! test delete
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?
53
54 ! test replace
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
62
63 ! test incr
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
69
70 ! test decr
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
75
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
83 3 seconds sleep
84 [ [ x m/get ] with-memcached ] not-found?
85
86 ! test append
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
91
92 ! test prepend
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
97
98 ! test multi-get
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
105 ] unit-test