@@ -12,7 +12,13 @@ open Kinetic
1212
1313let lwt_test name (f :unit -> unit Lwt.t ) : bool Lwt.t =
1414 Lwt_log. debug_f " starting:%s" name >> = fun () ->
15- let timeout = 60. (* Simulator isn't that fast (FLUSH | WRITETHROUGH) *) in
15+ let timeout = 300.
16+ (* overkill value, but:
17+ the simulator isn't that fast (FLUSH | WRITETHROUGH)
18+ and we sometimes need to test the real drives
19+ via ssh port forwarding.
20+ *)
21+ in
1622 Lwt. catch
1723 (fun () ->
1824 Lwt_unix. with_timeout timeout f
@@ -33,18 +39,36 @@ let test_get_non_existing session conn =
3339 assert (vo = None );
3440 Lwt. return ()
3541
42+ let test_put_no_tag session conn =
43+ let key = " test_put_no_tag" in
44+ let value = key in
45+ let synchronization = Some Kinetic. WRITEBACK in
46+ Lwt_io. printlf " drive[%S] <- Some %S%!" key value >> = fun () ->
47+ Kinetic. put session conn key value
48+ ~db_version: None
49+ ~new_version: None
50+ ~forced: None
51+ ~tag: None
52+ ~synchronization
53+ >> = fun () ->
54+ Lwt. return ()
55+
3656let test_noop session conn =
3757 Kinetic. noop session conn
3858
3959let batch_ops1 session conn : unit Lwt.t =
40- Kinetic. start_batch_operation session conn >> = fun batch ->
60+ Kinetic. start_batch_operation session conn
61+ >> = fun batch ->
62+ let v = " XXX" in
63+ let tag = Kinetic. make_sha1 v in
4164 let pe = Kinetic. make_entry
4265 ~key: " xxx"
4366 ~db_version: None
4467 ~new_version: None
45- (Some " XXX " )
68+ (Some (v, tag) )
4669 in
4770 Kinetic. batch_put batch pe ~forced: (Some true ) >> = fun () ->
71+
4872 let de = Kinetic. make_entry
4973 ~key: " xxx"
5074 ~db_version: None
@@ -57,11 +81,13 @@ let batch_ops1 session conn : unit Lwt.t=
5781
5882let batch_ops2 session conn =
5983 Kinetic. start_batch_operation session conn >> = fun batch ->
84+ let v = " ZZZ" in
85+ let tag = Kinetic. make_sha1 v in
6086 let pe = Kinetic. make_entry
6187 ~key: " zzz"
6288 ~db_version: None
6389 ~new_version: (Some " ZZZ" )
64- (Some " ZZZ " )
90+ (Some (v,tag) )
6591 in
6692 Kinetic. batch_put batch pe ~forced: (Some true ) >> = fun () ->
6793 Kinetic. end_batch_operation batch >> = fun conn ->
@@ -77,26 +103,49 @@ let batch_ops3 session conn =
77103 ~new_version: None
78104 None
79105 in
80- Kinetic. batch_delete batch de ~forced: None >> = fun () ->
81- Kinetic. end_batch_operation batch >> = fun conn ->
106+ Kinetic. batch_delete batch de ~forced: (Some true ) >> = fun () ->
107+ Lwt_log. debug_f " delete sent" >> = fun () ->
108+ Kinetic. end_batch_operation batch >> = fun (ok , conn ) ->
109+ assert (ok = true );
110+ Lwt_log. debug_f " end_batch sent" >> = fun () ->
111+ Lwt. return ()
112+
113+ let test_crc32 session conn =
114+ let key = " test_crc32_key" in
115+ let value = key in
116+ (* let tag = Kinetic.Crc32 0xEAE10D3Al in*)
117+ let tag = Kinetic. Crc32 0x0l in
118+ let synchronization = Some Kinetic. WRITEBACK in
119+ Kinetic. put session conn key value
120+ ~db_version: None
121+ ~new_version: None
122+ ~forced: None
123+ ~tag: (Some tag)
124+ ~synchronization
125+ >> = fun () ->
82126 Lwt. return ()
83127
128+
84129let test_put_get_delete session conn =
85130 let rec loop i =
86- if i = 1000
131+ if i = 400
87132 then Lwt. return ()
88133 else
89134 let key = Printf. sprintf " x_%05i" i in
90135 let value = Printf. sprintf " value_%05i" i in
91136 let synchronization = Some Kinetic. WRITEBACK in
137+ Lwt_io. printlf " drive[%S] <- Some %S%!" key value >> = fun () ->
138+ let tag = Kinetic. make_sha1 value in
139+
92140 Kinetic. put session conn key value
93141 ~db_version: None
94142 ~new_version: None
95143 ~forced: None
144+ ~tag: (Some tag)
96145 ~synchronization
97146 >> = fun () ->
98147 Kinetic. get session conn key >> = fun vco ->
99- Lwt_io. printlf " drive[%S]=%s" key (vco2s vco) >> = fun () ->
148+ Lwt_io. printlf " drive[%S]=%s%! " key (vco2s vco) >> = fun () ->
100149 let () = match vco with
101150 | None -> failwith " should be present"
102151 | Some (value2 , version ) ->
@@ -114,28 +163,49 @@ let test_put_get_delete session conn =
114163 in
115164 loop 0
116165
166+ let test_put_largish session conn =
167+ let key = " largish" in
168+ let value = Bytes. create 100_000 in
169+ let tag = Kinetic. make_sha1 value in
170+ let synchronization = Some Kinetic. FLUSH in
171+ Kinetic. put session conn key value
172+ ~new_version: None
173+ ~db_version: None
174+ ~forced: (Some true )
175+ ~synchronization
176+ ~tag: (Some tag)
177+ >> = fun () ->
178+ Kinetic. get session conn key >> = fun vco ->
179+ assert (vco <> None );
180+ Lwt. return ()
181+
117182let test_put_version session conn =
118183 let key = " with_version" in
119184 Kinetic. delete_forced session conn key >> = fun () ->
120185 let value = " the_value" in
186+ let tag = Kinetic. make_sha1 value in
121187 let version = Some " 0" in
122188 let synchronization = Some Kinetic. FLUSH in
123189 Kinetic. put session conn key value
124190 ~new_version: version
125191 ~db_version: None
126192 ~forced: (Some true )
127193 ~synchronization
194+ ~tag: (Some tag)
128195 >> = fun () ->
129196 Kinetic. get session conn key >> = fun vco ->
130197 Lwt_io. printlf " vco=%s" (vco2s vco) >> = fun () ->
131198 begin
132199 Lwt. catch
133200 (fun () ->
134201 let new_version = Some " 1" in
135- Kinetic. put session conn key " next_value"
202+ let value2 = " next_value" in
203+ let tag2 = Kinetic. make_sha1 value2 in
204+ Kinetic. put session conn key value2
136205 ~db_version: new_version ~new_version
137206 ~forced: None
138207 ~synchronization
208+ ~tag: (Some tag2)
139209 >> = fun () ->
140210 Lwt. return false
141211 )
@@ -156,12 +226,18 @@ let fill session conn n =
156226 else
157227 let key = Printf. sprintf " x_%05i" i in
158228 let v = Printf. sprintf " value_%05i" i in
229+ let tag = Kinetic. make_sha1 v in
230+ begin
231+ if i mod 100 = 0 then Lwt_io. printlf " i:%i" i else Lwt. return ()
232+ end
233+ >> = fun () ->
159234 Kinetic. put
160235 session conn key v
161236 ~db_version: None
162237 ~new_version: None
163238 ~forced: (Some true )
164239 ~synchronization
240+ ~tag: (Some tag)
165241 >> = fun () ->
166242 loop (i+ 1 )
167243 in
@@ -173,13 +249,23 @@ let range_test session conn =
173249 fill session conn 1000 >> = fun () ->
174250 Kinetic. get_key_range
175251 session conn
176- " x" true " y" true true 20
252+ " x" true " y" true false 20
177253 >> = fun keys ->
178- Lwt_io. printlf " [%s]\n " (String. concat " ; " keys) >> = fun () ->
254+ Lwt_io. printlf " [%s]\n %! " (String. concat " ; " keys) >> = fun () ->
179255 assert (List. length keys = 20 );
180- assert (List. hd keys= " x_00999 " );
256+ assert (List. hd keys= " x_00000 " );
181257 Lwt. return ()
182258
259+ let range_test_reverse session conn =
260+ fill session conn 1000 >> = fun () ->
261+ Kinetic. get_key_range
262+ session conn
263+ " y" true " x" true true 20
264+ >> = fun keys ->
265+ Lwt_io. printlf " [%s]\n %!" (String. concat " ; " keys) >> = fun () ->
266+ assert (List. length keys = 20 );
267+ assert (List. hd keys= " x_00999" );
268+ Lwt. return ()
183269(*
184270let peer2peer_test session conn =
185271 let peer = "192.168.11.102", 8000, false in
@@ -195,13 +281,24 @@ let peer2peer_test session conn =
195281
196282let () =
197283 let make_socket_address h p = Unix. ADDR_INET (Unix. inet_addr_of_string h, p) in
198- let sa = make_socket_address " 127.0.0.1" 11000 in
284+ if Array. length Sys. argv < 4
285+ then
286+ begin
287+ Printf. printf " %s (ip:string) (port:int) (trace:bool)\n %!" Sys. argv.(0 );
288+ exit (- 1 );
289+ end ;
290+ let ip = Sys. argv.(1 )
291+ and port = int_of_string (Sys. argv.(2 ))
292+ and trace = bool_of_string (Sys. argv.(3 ))
293+ in
294+
295+ let sa = make_socket_address ip port in
199296 let t =
200297 let secret = " asdfasdf" in
201298 let cluster_version = 0L in
202299 Lwt_io. with_connection sa
203300 (fun conn ->
204- Kinetic. handshake secret cluster_version conn >> = fun session ->
301+ Kinetic. handshake secret cluster_version conn ~trace >> = fun session ->
205302 let config = Kinetic. get_config session in
206303 let open Config in
207304 Lwt_io. printlf " Config:" >> = fun () ->
@@ -224,16 +321,21 @@ let () =
224321 in
225322 run_tests
226323 [
227- " get_non_existing" ,test_get_non_existing;
228- " noop" , test_noop;
229- " put_get_delete" , test_put_get_delete;
230-
231- " put_version" , test_put_version;
232- " range_test" , range_test;
233- " batch_ops1" , batch_ops1;
234- " batch_ops2" , batch_ops2;
235- " batch_ops3" , batch_ops3;
236- (* "peer2peer", peer2peer_test;*)
324+
325+ " get_non_existing" ,test_get_non_existing;
326+ " noop" , test_noop;
327+ " put_get_delete" , test_put_get_delete;
328+ " put_version" , test_put_version;
329+ " put_largish" , test_put_largish;
330+ " range_test" , range_test;
331+ " range_test_reverse" , range_test_reverse;
332+ " batch_ops1" , batch_ops1;
333+ " batch_ops2" , batch_ops2;
334+ " batch_ops3" , batch_ops3;
335+ " crc32" , test_crc32;
336+ " put_no_tag" , test_put_no_tag;
337+
338+ (* "peer2peer", peer2peer_test;*)
237339 ]
238340 >> = fun results ->
239341 Lwt_list. iter_s
0 commit comments