11-module (bucket_types ).
22
3- % % -behaviour(riak_test).
4-
5- -export ([properties /0 ,
6- confirm /1 ,
7- mapred_modfun /3 ,
8- mapred_modfun_type /3 ]).
3+ -behavior (riak_test ).
4+ -export ([confirm /0 , mapred_modfun /3 , mapred_modfun_type /3 ]).
95
106-include_lib (" eunit/include/eunit.hrl" ).
11- -include (" rt.hrl" ).
12-
13- -test_type ([bucket_types ]).
14-
15- properties () ->
16- CustomConfig = rt_cluster :augment_config (riak_core ,
17- {default_bucket_props , [{n_val , 2 }]},
18- rt_properties :default_config ()),
19- rt_properties :new ([{node_count , 4 },
20- {config , CustomConfig }]).
21-
22- -spec confirm (rt_properties :properties ()) -> pass | fail .
23- confirm (Properties ) ->
24- NodeIds = rt_properties :get (node_ids , Properties ),
25- NodeMap = rt_properties :get (node_map , Properties ),
26- Nodes = [rt_node :node_name (NodeId , NodeMap ) || NodeId <- NodeIds ],
27- Node = hd (Nodes ),
287
8+ confirm () ->
299 application :start (inets ),
10+ lager :info (" Deploy some nodes" ),
11+ Nodes = rt :build_cluster (4 , [], [
12+ {riak_core , [{default_bucket_props ,
13+ [{n_val , 2 }]}]}]),
14+ Node = hd (Nodes ),
3015
31- RMD = rt_properties : get ( metadata , Properties ),
16+ RMD = riak_test_runner : metadata ( ),
3217 HaveIndexes = case proplists :get_value (backend , RMD ) of
3318 undefined -> false ; % % default is da 'cask
3419 bitcask -> false ;
3520 _ -> true
3621 end ,
3722
38- {ok , [{" 127.0.0.1" , Port }]} = rpc :call (Node , application , get_env ,
39- [riak_api , pb ]),
40-
41- {ok , PB } = riakc_pb_socket :start_link (" 127.0.0.1" , Port , []),
23+ PB = rt :pbc (Node ),
4224
4325 lager :info (" default type get/put test" ),
4426 % % write explicitly to the default type
@@ -99,9 +81,13 @@ confirm(Properties) ->
9981 % % read from the default bucket explicitly
10082 {error , notfound } = riakc_pb_socket :get (PB , {<<" default" >>, <<" bucket" >>}, <<" key" >>),
10183
102- timer :sleep (5000 ), % % wait for delete_mode 3s to expire
84+ ? assertEqual (ok , rt :wait_until (fun () ->
85+ rt :pbc_really_deleted (PB ,
86+ <<" bucket" >>,
87+ [<<" key" >>])
88+ end )),
10389
104- % % now there shoyld be no buckets or keys to be listed...
90+ % % now there should be no buckets or keys to be listed...
10591 % %
10692 % % list keys
10793 ? assertEqual ({ok , []}, riakc_pb_socket :list_keys (PB , <<" bucket" >>)),
@@ -114,13 +100,20 @@ confirm(Properties) ->
114100
115101 lager :info (" custom type get/put test" ),
116102 Type = <<" mytype" >>,
117- rt_bucket_types :create_and_activate_bucket_type (Node , Type , [{n_val , 3 }]),
118- rt_bucket_types :wait_until_bucket_type_status (Type , active , Nodes ),
103+ TypeProps = [{n_val , 3 }],
104+ lager :info (" Create bucket type ~p , wait for propagation" , [Type ]),
105+ rt :create_and_activate_bucket_type (Node , Type , TypeProps ),
106+ rt :wait_until_bucket_type_status (Type , active , Nodes ),
107+ rt :wait_until_bucket_props (Nodes , {Type , <<" bucket" >>}, TypeProps ),
119108
120109 lager :info (" doing put" ),
121110 riakc_pb_socket :put (PB , riakc_obj :new ({Type , <<" bucket" >>},
122111 <<" key" >>, <<" newestvalue" >>)),
123112
113+ lager :info (" custom type list_keys test" ),
114+ ? assertEqual ({ok , []}, riakc_pb_socket :list_keys (PB , <<" bucket" >>)),
115+ ? assertEqual ({ok , [<<" key" >>]}, riakc_pb_socket :list_keys (PB , {Type ,
116+ <<" bucket" >>})),
124117 lager :info (" doing get" ),
125118 {ok , O5 } = riakc_pb_socket :get (PB , {Type , <<" bucket" >>}, <<" key" >>),
126119
@@ -130,15 +123,42 @@ confirm(Properties) ->
130123 % % this type is NOT aliased to the default buckey
131124 {error , notfound } = riakc_pb_socket :get (PB , <<" bucket" >>, <<" key" >>),
132125
133- lager :info (" custom type list_keys test" ),
134- ? assertEqual ({ok , []}, riakc_pb_socket :list_keys (PB , <<" bucket" >>)),
135- ? assertEqual ({ok , [<<" key" >>]}, riakc_pb_socket :list_keys (PB , {Type ,
136- <<" bucket" >>})),
137126 lager :info (" custom type list_buckets test" ),
138127 % % list buckets
139128 ? assertEqual ({ok , []}, riakc_pb_socket :list_buckets (PB )),
140129 ? assertEqual ({ok , [<<" bucket" >>]}, riakc_pb_socket :list_buckets (PB , Type )),
141130
131+ % %% Beginning of UTF-8 test
132+
133+ lager :info (" UTF-8 type get/put test" ),
134+ % % こんにちは - konnichiwa (Japanese)
135+ UnicodeType = unicode :characters_to_binary ([12371 ,12435 ,12395 ,12385 ,12399 ], utf8 ),
136+ % % سلام - Salam (Arabic)
137+ UnicodeBucket = unicode :characters_to_binary ([1587 ,1604 ,1575 ,1605 ], utf8 ),
138+ lager :info (" Create bucket type, wait for propagation" ),
139+ rt :create_and_activate_bucket_type (Node , UnicodeType , TypeProps ),
140+ rt :wait_until_bucket_type_status (UnicodeType , active , Nodes ),
141+ rt :wait_until_bucket_props (Nodes , {UnicodeType , UnicodeBucket }, TypeProps ),
142+
143+ lager :info (" doing put" ),
144+ riakc_pb_socket :put (PB , riakc_obj :new ({UnicodeType , UnicodeBucket },
145+ <<" key" >>, <<" yetanothervalue" >>)),
146+
147+ lager :info (" custom type list_keys test" ),
148+ ? assertEqual ({ok , [<<" key" >>]}, riakc_pb_socket :list_keys (PB ,
149+ {UnicodeType ,
150+ UnicodeBucket })),
151+ lager :info (" doing get" ),
152+ {ok , O6 } = riakc_pb_socket :get (PB , {UnicodeType , UnicodeBucket }, <<" key" >>),
153+
154+ ? assertEqual (<<" yetanothervalue" >>, riakc_obj :get_value (O6 )),
155+
156+ lager :info (" custom type list_buckets test" ),
157+ % % list buckets
158+ ? assertEqual ({ok , [UnicodeBucket ]}, riakc_pb_socket :list_buckets (PB , UnicodeType )),
159+
160+ % %% End of UTF-8 test
161+
142162 lager :info (" bucket properties tests" ),
143163 riakc_pb_socket :set_bucket (PB , {<<" default" >>, <<" mybucket" >>},
144164 [{n_val , 5 }]),
@@ -160,12 +180,38 @@ confirm(Properties) ->
160180 <<" mybucket" >>}),
161181 ? assertEqual (5 , proplists :get_value (n_val , BProps3 )),
162182
183+ % % Check our unicode brethren
184+ riakc_pb_socket :set_bucket (PB , {UnicodeType , UnicodeBucket },
185+ [{n_val , 4 }]),
186+ {ok , UBProps1 } = riakc_pb_socket :get_bucket (PB , {UnicodeType ,
187+ UnicodeBucket }),
188+ ? assertEqual (4 , proplists :get_value (n_val , UBProps1 )),
189+
163190 riakc_pb_socket :reset_bucket (PB , {Type , <<" mybucket" >>}),
164191
165192 {ok , BProps4 } = riakc_pb_socket :get_bucket (PB , {Type ,
166193 <<" mybucket" >>}),
167194 ? assertEqual (3 , proplists :get_value (n_val , BProps4 )),
168195
196+ riakc_pb_socket :reset_bucket (PB , {UnicodeType , UnicodeBucket }),
197+
198+ {ok , UBProps2 } = riakc_pb_socket :get_bucket (PB , {UnicodeType ,
199+ UnicodeBucket }),
200+
201+ ? assertEqual (3 , proplists :get_value (n_val , UBProps2 )),
202+
203+ {error , NTGR } = riakc_pb_socket :get_bucket (PB , {<<" nonexistent" >>, <<" mybucket" >>}),
204+
205+ lager :info (" GOT ERROR ~s " , [NTGR ]),
206+
207+ ? assertMatch (<<" No bucket-type named 'nonexistent'" , _ /binary >>, NTGR ),
208+
209+ {error , NTSR } = riakc_pb_socket :set_bucket (PB , {<<" nonexistent" >>, <<" mybucket" >>}, [{n_val , 3 }]),
210+
211+ lager :info (" GOT ERROR ~s " , [NTSR ]),
212+
213+ ? assertMatch (<<" No bucket-type named 'nonexistent'" , _ /binary >>, NTSR ),
214+
169215 lager :info (" bucket type properties test" ),
170216
171217 riakc_pb_socket :set_bucket_type (PB , Type ,
@@ -186,6 +232,27 @@ confirm(Properties) ->
186232
187233 ? assertEqual (3 , proplists :get_value (n_val , BProps7 )),
188234
235+ % % Repeat type checks for unicode type/bucket
236+
237+ riakc_pb_socket :set_bucket_type (PB , UnicodeType ,
238+ [{n_val , 5 }]),
239+
240+ {ok , UBProps3 } = riakc_pb_socket :get_bucket_type (PB , UnicodeType ),
241+
242+ ? assertEqual (5 , proplists :get_value (n_val , UBProps3 )),
243+
244+ % % check that the bucket inherits from its type
245+ {ok , UBProps4 } = riakc_pb_socket :get_bucket (PB , {UnicodeType ,
246+ UnicodeBucket }),
247+
248+ ? assertEqual (5 , proplists :get_value (n_val , UBProps4 )),
249+
250+ riakc_pb_socket :set_bucket_type (PB , UnicodeType , [{n_val , 3 }]),
251+
252+ {ok , UBProps5 } = riakc_pb_socket :get_bucket_type (PB , UnicodeType ),
253+
254+ ? assertEqual (3 , proplists :get_value (n_val , UBProps5 )),
255+
189256 % % make sure a regular bucket under the default type reflects app.config
190257 {ok , BProps8 } = riakc_pb_socket :get_bucket (PB , {<<" default" >>,
191258 <<" mybucket" >>}),
@@ -204,8 +271,8 @@ confirm(Properties) ->
204271 % % make sure a newly created type is not affected either
205272 % % create a new type
206273 Type2 = <<" mynewtype" >>,
207- rt_bucket_types :create_and_activate_bucket_type (Node , Type2 , []),
208- rt_bucket_types :wait_until_bucket_type_status (Type2 , active , Nodes ),
274+ rt :create_and_activate_bucket_type (Node , Type2 , []),
275+ rt :wait_until_bucket_type_status (Type2 , active , Nodes ),
209276
210277 {ok , BProps11 } = riakc_pb_socket :get_bucket_type (PB , Type2 ),
211278
@@ -296,6 +363,11 @@ confirm(Properties) ->
296363 {<<" baz" >>, <<" 4" >>, <<" a" >>, 4 },
297364 {<<" bam" >>, <<" 5" >>, <<" a" >>, 3 }]],
298365
366+ ? assertEqual ({ok , [{0 , [<<" 2" >>]}]},
367+ riakc_pb_socket :mapred (PB , {{Type , <<" MRbucket" >>},
368+ [[<<" starts_with" >>, <<" f" >>]]},
369+ [{map , {modfun , riak_kv_mapreduce , map_object_value }, none , true }])),
370+
299371 ? assertEqual ({ok , [{1 , [14 ]}]},
300372 riakc_pb_socket :mapred_bucket (PB , {Type , <<" MRbucket" >>},
301373 [{map , {jsfun , <<" Riak.mapValuesJson" >>}, undefined , false },
0 commit comments