Skip to content
Browse files

Broken test flow for user_fn (mem_store)

  • Loading branch information...
1 parent 4802c50 commit 13042c3dc573cb1e9ec8982c4105a7744784077d @blackmath86 blackmath86 committed
Showing with 38 additions and 0 deletions.
  1. +19 −0 src/client/arakoon_remote_client_test.ml
  2. +11 −0 src/hope/mem_store.ml
  3. +5 −0 src/hope/userdb.ml
  4. +3 −0 src/hope/userdb.mli
View
19 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);
]
View
11 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
View
5 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
View
3 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

0 comments on commit 13042c3

Please sign in to comment.
Something went wrong with that request. Please try again.