3030-include_lib (" riak_pb/include/riak_pb_kv_codec.hrl" ).
3131-include_lib (" eunit/include/eunit.hrl" ).
3232
33+ listing_is_blocked_test () ->
34+ application :set_env (riakc , allow_listing , false ),
35+ E = <<" Bucket and key list operations are expensive and should not be used in production." >>,
36+ ? assertMatch ({error , E }, riakc_pb_socket :list_buckets (self ())),
37+ ? assertMatch ({error , E }, riakc_pb_socket :list_keys (self (), <<" b" >>)),
38+ application :set_env (riakc , allow_listing , true ).
39+
40+ mapred_over_bucket_is_blocked_test () ->
41+ application :set_env (riakc , allow_listing , false ),
42+ Pid = self (),
43+ Input1 = <<" bucket" >>,
44+ Input2 = {<<" type" >>, <<" bucket" >>},
45+ E = <<" Bucket list operations are expensive and should not be used in production." >>,
46+ ? assertMatch ({error , E }, riakc_pb_socket :mapred (Pid , Input1 , [])),
47+ ? assertMatch ({error , E }, riakc_pb_socket :mapred (Pid , Input2 , [])),
48+ application :set_env (riakc , allow_listing , true ).
49+
3350bad_connect_test () ->
3451 % % Start with an unlikely port number
35- ? assertEqual ({error , {tcp , econnrefused }}, riakc_pb_socket :start ({127 ,0 ,0 ,1 }, 65535 )).
52+ ? assertMatch ({error , {tcp , econnrefused }}, riakc_pb_socket :start ({127 ,0 ,0 ,1 }, 65535 )).
3653
3754queue_disconnected_test () ->
55+ application :set_env (riakc , allow_listing , true ),
3856 % % Start with an unlikely port number
3957 {ok , Pid } = riakc_pb_socket :start ({127 ,0 ,0 ,1 }, 65535 , [queue_if_disconnected ]),
40- ? assertEqual ({error , timeout }, riakc_pb_socket :ping (Pid , 10 )),
41- ? assertEqual ({error , timeout }, riakc_pb_socket :list_keys (Pid , <<" b" >>, 10 )),
42- riakc_pb_socket :stop (Pid ).
58+ ? assertMatch ({error , timeout }, riakc_pb_socket :ping (Pid , 10 )),
59+ ? assertMatch ({error , timeout }, riakc_pb_socket :list_keys (Pid , <<" b" >>, 10 )),
60+ riakc_pb_socket :stop (Pid ),
61+ application :set_env (riakc , allow_listing , false ).
4362
4463auto_reconnect_bad_connect_test () ->
64+ application :set_env (riakc , allow_listing , true ),
4565 % % Start with an unlikely port number
4666 {ok , Pid } = riakc_pb_socket :start ({127 ,0 ,0 ,1 }, 65535 , [auto_reconnect ]),
47- ? assertEqual ({false , []}, riakc_pb_socket :is_connected (Pid )),
48- ? assertEqual ({error , disconnected }, riakc_pb_socket :ping (Pid )),
49- ? assertEqual ({error , disconnected }, riakc_pb_socket :list_keys (Pid , <<" b" >>)),
50- riakc_pb_socket :stop (Pid ).
67+ ? assertMatch ({false , []}, riakc_pb_socket :is_connected (Pid )),
68+ ? assertMatch ({error , disconnected }, riakc_pb_socket :ping (Pid )),
69+ ? assertMatch ({error , disconnected }, riakc_pb_socket :list_keys (Pid , <<" b" >>)),
70+ riakc_pb_socket :stop (Pid ),
71+ application :set_env (riakc , allow_listing , false ).
5172
5273server_closes_socket_test () ->
5374 % % Silence SASL junk when socket closes.
@@ -69,7 +90,7 @@ server_closes_socket_test() ->
6990 ok = gen_tcp :close (Listen ),
7091 receive
7192 Msg1 -> % result of ping from spawned process above
72- ? assertEqual ({error , disconnected }, Msg1 )
93+ ? assertMatch ({error , disconnected }, Msg1 )
7394 end ,
7495 % % Wait for spawned process to exit
7596 Mref = erlang :monitor (process , Pid ),
@@ -96,7 +117,7 @@ auto_reconnect_server_closes_socket_test() ->
96117 ok = gen_tcp :close (Listen ),
97118 receive
98119 Msg ->
99- ? assertEqual ({error , disconnected }, Msg )
120+ ? assertMatch ({error , disconnected }, Msg )
100121 end ,
101122 % % Server will not have had a chance to reconnect yet, reason counters empty.
102123 ? assertMatch ({false , []}, riakc_pb_socket :is_connected (Pid )),
@@ -139,8 +160,8 @@ integration_tests() ->
139160 [{" ping" ,
140161 ? _test ( begin
141162 {ok , Pid } = riakc_test_utils :start_link (),
142- ? assertEqual (pong , riakc_pb_socket :ping (Pid )),
143- ? assertEqual (true , riakc_pb_socket :is_connected (Pid )),
163+ ? assertMatch (pong , riakc_pb_socket :ping (Pid )),
164+ ? assertMatch (true , riakc_pb_socket :is_connected (Pid )),
144165 riakc_pb_socket :stop (Pid )
145166 end )},
146167
@@ -1453,9 +1474,13 @@ integration_test_() ->
14531474 SetupFun = fun () ->
14541475 % % Grab the riakclient_pb.proto file
14551476 code :add_pathz (" ../ebin" ),
1456- ok = riakc_test_utils :maybe_start_network ()
1477+ ok = riakc_test_utils :maybe_start_network (),
1478+ application :set_env (riakc , allow_listing , true )
14571479 end ,
1458- CleanupFun = fun (_ ) -> net_kernel :stop () end ,
1480+ CleanupFun = fun (_ ) ->
1481+ net_kernel :stop (),
1482+ application :set_env (riakc , allow_listing , false )
1483+ end ,
14591484 GenFun = fun () ->
14601485 case catch net_adm :ping (riakc_test_utils :test_riak_node ()) of
14611486 pong -> integration_tests ();
0 commit comments