diff --git a/src/client/arakoon_remote_client_test.ml b/src/client/arakoon_remote_client_test.ml index 47025a27..c66b397b 100644 --- a/src/client/arakoon_remote_client_test.ml +++ b/src/client/arakoon_remote_client_test.ml @@ -29,6 +29,11 @@ open Statistics open Pq open OUnit +(* +open Baardskeerder +open Unix +open Interval +*) module MyStore = (MemStore :STORE) module MyDispatcher = Dispatcher.ADispatcher(MyStore) @@ -295,6 +300,19 @@ let _test_sequence_inside_sequence (client: Arakoon_client.client) = OUnit.assert_bool "XXX3 should not be there" (not exists2); Lwt.return () + +let _test_user_fn (client: Arakoon_client.client) = + let myFn (ts:(Core.k, Core.v) Hashtbl.t) (vo) = + let () = Hashtbl.replace ts "user_fn" "user_fn" in + Lwt.return None + in + let () = Userdb.Registry.register2 "myFn" myFn in + client # user_function "myFn" (Some "user_fn") >>= fun ro -> + client # get "user_fn" >>= fun res -> + OUnit.assert_equal res "user_fn"; + Lwt.return () + + let wrap f = (fun () -> __client_server_wrapper__ _CLUSTER f) let map_wrap = List.map (fun (name, inner) -> name >:: (wrap inner)) @@ -309,5 +327,6 @@ let suite = "remote_client" >::: ("assert_confirm" , _test_confirm); ("assert_sequence" , _test_sequence); ("assert_sequence_rec" , _test_sequence_inside_sequence); + ("assert_user_fn" , _test_user_fn); ] diff --git a/src/hope/mem_store.ml b/src/hope/mem_store.ml index 5403ea15..7282b37b 100644 --- a/src/hope/mem_store.ml +++ b/src/hope/mem_store.ml @@ -12,7 +12,17 @@ module MemStore = (struct begin let _ok = Lwt.return (Baardskeerder.OK None) in match u with + | SET (k,v) -> let () = Hashtbl.replace t.store k v in _ok + | USER_FUNCTION (name,po) -> + let f = Userdb.Registry.lookup2 name in + f t.store po >>= fun ro -> + Lwtc.log "Mstore.returning %s" (Log_extra.string_option_to_string ro) >>= fun () -> + let a = match ro with + | None -> (Baardskeerder.OK None) + | Some v -> (Baardskeerder.NOK (Arakoon_exc.E_NOT_FOUND,v)) + in + Lwt.return a | DELETE k -> if Hashtbl.mem t.store k then let () = Hashtbl.remove t.store k in _ok @@ -30,6 +40,7 @@ module MemStore = (struct if Hashtbl.mem t.store k then _ok else Lwt.return (Baardskeerder.NOK (Arakoon_exc.E_ASSERTION_FAILED,k)) + | SEQUENCE s -> let rec _loop = function | [] -> _ok diff --git a/src/hope/userdb.ml b/src/hope/userdb.ml index f973d26f..50c71e9d 100644 --- a/src/hope/userdb.ml +++ b/src/hope/userdb.ml @@ -28,7 +28,12 @@ end module Registry = struct type f = UserDB.tx -> string option -> (string option) Lwt.t + type f2 = (Core.k, Core.v) Hashtbl.t -> string option -> (string option) Lwt.t + (*type f2 = (string, string) Hashtbl.t -> string option -> (string option) Lwt.t*) let _r = Hashtbl.create 42 + let _r2 = Hashtbl.create 42 let register (name:string) (f:f) = Hashtbl.replace _r name f + let register2 (name:string) (f2:f2) = Hashtbl.replace _r2 name f2 let lookup (name:string) = Hashtbl.find _r name + let lookup2 (name:string) = Hashtbl.find _r2 name end diff --git a/src/hope/userdb.mli b/src/hope/userdb.mli index 3c089d90..dfbc2aab 100644 --- a/src/hope/userdb.mli +++ b/src/hope/userdb.mli @@ -12,7 +12,10 @@ end module Registry: sig type f = UserDB.tx -> string option -> (string option) Lwt.t + type f2 = (Core.k,Core.v) Hashtbl.t -> string option -> (string option) Lwt.t + val register2: string -> f2 ->unit val register: string -> f -> unit val lookup: string -> f + val lookup2: string -> f2 end