]> gitweb.factorcode.org Git - factor.git/commitdiff
memcached: change tests to key based on cpu architecture.
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 2 Sep 2011 04:26:09 +0000 (21:26 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 2 Sep 2011 04:26:09 +0000 (21:26 -0700)
extra/memcached/memcached-tests.factor
extra/memcached/memcached.factor

index 17c93c281a259d636cfb50afd4ed0474a8ac996e..81986f5865d41c555761f7cef5530511888a673d 100644 (file)
@@ -1,15 +1,20 @@
 ! Copyright (C) 2010 John Benediktsson
 ! See http://factorcode.org/license.txt for BSD license
 
-USING: calendar math math.functions memcached memcached.private
-kernel sequences threads tools.test ;
+USING: arrays assocs calendar math math.functions memcached
+memcached.private kernel present sequences system threads
+tools.test ;
 
 IN: memcached.tests
 
 <PRIVATE
 
 : not-found? ( quot -- )
-    [ "key not found" = ] must-fail-with ;
+    [ key-not-found? ] must-fail-with ;
+
+: x ( -- str ) cpu present "-x" append ;
+: y ( -- str ) cpu present "-y" append ;
+: z ( -- str ) cpu present "-z" append ;
 
 PRIVATE>
 
@@ -18,79 +23,80 @@ PRIVATE>
 
 ! test simple set get
 [ m/flush ] with-memcached
-[ "valuex" "x" m/set ] with-memcached
-[ "valuex" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ "valuex" x m/set ] with-memcached
+[ "valuex" ] [ [ x m/get ] with-memcached ] unit-test
 
 ! test flush
 [ m/flush ] with-memcached
-[ "valuex" "x" m/set "valuey" "y" m/set ] with-memcached
-[ "valuex" ] [ [ "x" m/get ] with-memcached ] unit-test
-[ "valuey" ] [ [ "y" m/get ] with-memcached ] unit-test
+[ "valuex" x m/set "valuey" y m/set ] with-memcached
+[ "valuex" ] [ [ x m/get ] with-memcached ] unit-test
+[ "valuey" ] [ [ y m/get ] with-memcached ] unit-test
 [ m/flush ] with-memcached
-[ [ "x" m/get ] with-memcached ] not-found?
-[ [ "y" m/get ] with-memcached ] not-found?
+[ [ x m/get ] with-memcached ] not-found?
+[ [ y m/get ] with-memcached ] not-found?
 
 ! test noop
 [ m/noop ] with-memcached
 
 ! test delete
 [ m/flush ] with-memcached
-[ "valuex" "x" m/set ] with-memcached
-[ "valuex" ] [ [ "x" m/get ] with-memcached ] unit-test
-[ "x" m/delete ] with-memcached
-[ [ "x" m/get ] with-memcached ] not-found?
+[ "valuex" x m/set ] with-memcached
+[ "valuex" ] [ [ x m/get ] with-memcached ] unit-test
+[ x m/delete ] with-memcached
+[ [ x m/get ] with-memcached ] not-found?
 
 ! test replace
 [ m/flush ] with-memcached
-[ [ "x" m/get ] with-memcached ] not-found?
-[ [ "ex" "x" m/replace ] with-memcached ] not-found?
-[ "ex" "x" m/add ] with-memcached
-[ "ex" ] [ [ "x" m/get ] with-memcached ] unit-test
-[ "ex2" "x" m/replace ] with-memcached
-[ "ex2" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ [ x m/get ] with-memcached ] not-found?
+[ [ "ex" x m/replace ] with-memcached ] not-found?
+[ "ex" x m/add ] with-memcached
+[ "ex" ] [ [ x m/get ] with-memcached ] unit-test
+[ "ex2" x m/replace ] with-memcached
+[ "ex2" ] [ [ x m/get ] with-memcached ] unit-test
 
 ! test incr
 [ m/flush ] with-memcached
-[ 0 ] [ [ "x" m/incr ] with-memcached ] unit-test
-[ 1 ] [ [ "x" m/incr ] with-memcached ] unit-test
-[ 212 ] [ [ 211 "x" m/incr-val ] with-memcached ] unit-test
-[ 8589934804 ] [ [ 2 33 ^ "x" m/incr-val ] with-memcached ] unit-test
+[ 0 ] [ [ x m/incr ] with-memcached ] unit-test
+[ 1 ] [ [ x m/incr ] with-memcached ] unit-test
+[ 212 ] [ [ 211 x m/incr-val ] with-memcached ] unit-test
+[ 8589934804 ] [ [ 2 33 ^ x m/incr-val ] with-memcached ] unit-test
 
 ! test decr
 [ m/flush ] with-memcached
-[ "5" "x" m/set ] with-memcached
-[ 4 ] [ [ "x" m/decr ] with-memcached ] unit-test
-[ 0 ] [ [ 211 "x" m/decr-val ] with-memcached ] unit-test
+[ "5" x m/set ] with-memcached
+[ 4 ] [ [ x m/decr ] with-memcached ] unit-test
+[ 0 ] [ [ 211 x m/decr-val ] with-memcached ] unit-test
 
 ! test timebombed flush
 [ m/flush ] with-memcached
-[ [ "x" m/get ] with-memcached ] not-found?
-[ "valuex" "x" m/set ] with-memcached
-[ "valuex" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ [ x m/get ] with-memcached ] not-found?
+[ "valuex" x m/set ] with-memcached
+[ "valuex" ] [ [ x m/get ] with-memcached ] unit-test
 [ 2 m/flush-later ] with-memcached
-[ "valuex" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ "valuex" ] [ [ x m/get ] with-memcached ] unit-test
 3 seconds sleep
-[ [ "x" m/get ] with-memcached ] not-found?
+[ [ x m/get ] with-memcached ] not-found?
 
 ! test append
 [ m/flush ] with-memcached
-[ "some" "x" m/set ] with-memcached
-[ "thing" "x" m/append ] with-memcached
-[ "something" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ "some" x m/set ] with-memcached
+[ "thing" x m/append ] with-memcached
+[ "something" ] [ [ x m/get ] with-memcached ] unit-test
 
 ! test prepend
 [ m/flush ] with-memcached
-[ "some" "x" m/set ] with-memcached
-[ "thing" "x" m/prepend ] with-memcached
-[ "thingsome" ] [ [ "x" m/get ] with-memcached ] unit-test
+[ "some" x m/set ] with-memcached
+[ "thing" x m/prepend ] with-memcached
+[ "thingsome" ] [ [ x m/get ] with-memcached ] unit-test
 
 ! test multi-get
 [ m/flush ] with-memcached
-[ H{ } ] [ [ { "x" "y" "z" } m/getseq ] with-memcached ] unit-test
-[ "5" "x" m/set ] with-memcached
-[ "valuex" "y" m/set ] with-memcached
-[ H{ { "x" "5" } { "y" "valuex" } } ]
-[ [ { "x" "y" "z" } m/getseq ] with-memcached ] unit-test
+[ H{ } ] [ [ x y z 3array m/getseq ] with-memcached ] unit-test
+[ "5" x m/set ] with-memcached
+[ "valuex" y m/set ] with-memcached
+[ { "5" "valuex" } ] [
+    [ x y z 3array m/getseq values ] with-memcached
+] unit-test
 
 
 
index 12bf28b4801e5bf289f37302e30c675f09b9a25c..5604332f11d46fb5b107d514117a2ec156fa3e24 100644 (file)
@@ -21,6 +21,15 @@ SYMBOL: memcached-server
     memcached-server get-global
     binary [ call ] with-client ; inline
 
+ERROR: key-not-found ;
+ERROR: key-exists ;
+ERROR: value-too-large ;
+ERROR: invalid-arguments ;
+ERROR: item-not-stored ;
+ERROR: value-not-numeric ;
+ERROR: unknown-command ;
+ERROR: out-of-memory ;
+
 <PRIVATE
 
 ! Commands
@@ -103,14 +112,14 @@ TUPLE: request cmd key val extra opaque cas ;
 
 : check-status ( header -- )
     [ 5 ] dip nth {
-        { NOT_FOUND    [ "key not found" throw     ] }
-        { EXISTS       [ "key exists" throw        ] }
-        { TOO_LARGE    [ "value too large" throw   ] }
-        { INVALID_ARGS [ "invalid arguments" throw ] }
-        { NOT_STORED   [ "item not stored" throw   ] }
-        { NOT_NUMERIC  [ "value not numeric" throw ] }
-        { UNKNOWN_CMD  [ "unknown command" throw   ] }
-        { MEMORY       [ "out of memory" throw     ] }
+        { NOT_FOUND    [ key-not-found     ] }
+        { EXISTS       [ key-exists        ] }
+        { TOO_LARGE    [ value-too-large   ] }
+        { INVALID_ARGS [ invalid-arguments ] }
+        { NOT_STORED   [ item-not-stored   ] }
+        { NOT_NUMERIC  [ value-not-numeric ] }
+        { UNKNOWN_CMD  [ unknown-command   ] }
+        { MEMORY       [ out-of-memory     ] }
         [ drop ]
     } case ;