Skip to content

Commit

Permalink
Broken test flow for user_fn (mem_store)
Browse files Browse the repository at this point in the history
  • Loading branch information
blackmath86 committed Feb 4, 2013
1 parent 4802c50 commit 13042c3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/client/arakoon_remote_client_test.ml
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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);
]

11 changes: 11 additions & 0 deletions src/hope/mem_store.ml
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/hope/userdb.ml
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/hope/userdb.mli
Expand Up @@ -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.