Skip to content

Commit 3601f87

Browse files
committed
Merge pull request #870 from basho/feature/yokozuna-rt-refactor
Refactor some Yokozuna tests to eliminate duplication
2 parents 4fa35d0 + 32bd9cf commit 3601f87

File tree

4 files changed

+58
-42
lines changed

4 files changed

+58
-42
lines changed

src/yokozuna_rt.erl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
-export([check_exists/2,
2626
commit/2,
2727
expire_trees/1,
28+
gen_keys/1,
2829
host_entries/1,
2930
override_schema/5,
3031
remove_index_dirs/2,
@@ -35,6 +36,7 @@
3536
search_expect/5,
3637
search_expect/6,
3738
search_expect/7,
39+
assert_search/6,
3840
verify_num_found_query/3,
3941
wait_for_aae/1,
4042
wait_for_full_exchange_round/2,
@@ -56,6 +58,14 @@
5658
host_entries(ClusterConnInfo) ->
5759
[riak_http(I) || {_,I} <- ClusterConnInfo].
5860

61+
%% @doc Generate `SeqMax' keys. Yokozuna supports only UTF-8 compatible keys.
62+
-spec gen_keys(pos_integer()) -> [binary()].
63+
gen_keys(SeqMax) ->
64+
[<<N:64/integer>> || N <- lists:seq(1, SeqMax),
65+
not lists:any(
66+
fun(E) -> E > 127 end,
67+
binary_to_list(<<N:64/integer>>))].
68+
5969
%% @doc Write `Keys' via the PB inteface to a `Bucket' and have them
6070
%% searchable in an `Index'.
6171
-spec write_data([node()], pid(), index_name(), bucket(), [binary()]) -> ok.
@@ -264,6 +274,24 @@ search_expect(solr, {Host, Port}, Index, Name0, Term0, Shards, Expect)
264274
{ok, "200", _, R} = ibrowse:send_req(URL, [], get, [], Opts),
265275
verify_count_http(Expect, R).
266276

277+
assert_search(Pid, Cluster, Index, Search, SearchExpect, Params) ->
278+
F = fun(_) ->
279+
lager:info("Searching ~p and asserting it exists",
280+
[SearchExpect]),
281+
case riakc_pb_socket:search(Pid, Index, Search, Params) of
282+
{ok,{search_results,[{_Index,Fields}], _Score, Found}} ->
283+
?assert(lists:member(SearchExpect, Fields)),
284+
case Found of
285+
1 -> true;
286+
0 -> false
287+
end;
288+
{ok, {search_results, [], _Score, 0}} ->
289+
lager:info("Search has not yet yielded data"),
290+
false
291+
end
292+
end,
293+
rt:wait_until(Cluster, F).
294+
267295
search(HP, Index, Name, Term) ->
268296
search(yokozuna, HP, Index, Name, Term).
269297

tests/yz_default_bucket_type_upgrade.erl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ confirm() ->
5959

6060
[rt:assert_capability(ANode, ?YZ_CAP, {unknown_capability, ?YZ_CAP}) || ANode <- Cluster],
6161

62-
%% Generate keys, YZ only supports UTF-8 compatible keys
63-
GenKeys = [<<N:64/integer>> || N <- lists:seq(1, ?SEQMAX),
64-
not lists:any(
65-
fun(E) -> E > 127 end,
66-
binary_to_list(<<N:64/integer>>))],
62+
GenKeys = yokozuna_rt:gen_keys(?SEQMAX),
6763
KeyCount = length(GenKeys),
6864
lager:info("KeyCount ~p", [KeyCount]),
6965

tests/yz_extractors.erl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ confirm() ->
163163

164164
OldPid = rt:pbc(Node),
165165

166-
%% Generate keys, YZ only supports UTF-8 compatible keys
167-
GenKeys = [<<N:64/integer>> || N <- lists:seq(1, ?SEQMAX),
168-
not lists:any(
169-
fun(E) -> E > 127 end,
170-
binary_to_list(<<N:64/integer>>))],
166+
GenKeys = yokozuna_rt:gen_keys(?SEQMAX),
171167
KeyCount = length(GenKeys),
172168

173169
rt:count_calls(Cluster, [?GET_MAP_RING_MFA, ?GET_MAP_MFA]),

tests/yz_schema_change_reset.erl

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,7 @@ confirm() ->
131131
[Node1|_RestNodes] = Cluster = rt:build_cluster(4, ?CFG),
132132
rt:wait_for_cluster_service(Cluster, yokozuna),
133133

134-
%% Generate keys, YZ only supports UTF-8 compatible keys
135-
GenKeys = [<<N:64/integer>> || N <- lists:seq(1, ?SEQMAX),
136-
not lists:any(
137-
fun(E) -> E > 127 end,
138-
binary_to_list(<<N:64/integer>>))],
134+
GenKeys = yokozuna_rt:gen_keys(?SEQMAX),
139135
KeyCount = length(GenKeys),
140136
lager:info("KeyCount ~p", [KeyCount]),
141137

@@ -170,8 +166,10 @@ confirm() ->
170166

171167
yokozuna_rt:verify_num_found_query(Cluster, ?INDEX, KeyCount + 2),
172168

173-
assert_search(Pid, Cluster, <<"age:26">>, {<<"age">>, <<"26">>}, []),
174-
assert_search(Pid, Cluster, <<"age:99">>, {<<"age">>, <<"99">>}, []),
169+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
170+
<<"age:26">>, {<<"age">>, <<"26">>}, []),
171+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
172+
<<"age:99">>, {<<"age">>, <<"99">>}, []),
175173

176174
Map1 = riakc_map:update(
177175
{<<"0_foo">>, register},
@@ -197,8 +195,10 @@ confirm() ->
197195
riakc_map:to_op(Map3)),
198196

199197
yokozuna_rt:commit(Cluster, ?INDEX),
200-
assert_search(Pid, Cluster, <<"0_foo_register:44ab">>, {<<"0_foo_register">>,
201-
<<"44ab">>}, []),
198+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
199+
<<"0_foo_register:44ab">>,
200+
{<<"0_foo_register">>, <<"44ab">>},
201+
[]),
202202

203203
lager:info("Expire and re-check count before updating schema"),
204204

@@ -219,7 +219,8 @@ confirm() ->
219219
yokozuna_rt:commit(Cluster, ?INDEX),
220220

221221
yokozuna_rt:verify_num_found_query(Cluster, ?INDEX, KeyCount + 4),
222-
assert_search(Pid, Cluster, <<"hello_i:36">>, {<<"hello_i">>, <<"36">>}, []),
222+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
223+
<<"hello_i:36">>, {<<"hello_i">>, <<"36">>}, []),
223224

224225
lager:info("Write and check age at string per schema update"),
225226

@@ -231,8 +232,9 @@ confirm() ->
231232
yokozuna_rt:commit(Cluster, ?INDEX),
232233

233234
yokozuna_rt:verify_num_found_query(Cluster, ?INDEX, KeyCount + 5),
234-
assert_search(Pid, Cluster, <<"age:3jlkjkl">>,
235-
{<<"age">>, <<"3jlkjkl">>}, []),
235+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
236+
<<"age:3jlkjkl">>, {<<"age">>, <<"3jlkjkl">>},
237+
[]),
236238

237239
lager:info("Expire and re-check count to make sure we're correctly indexed
238240
by the new schema"),
@@ -253,7 +255,8 @@ confirm() ->
253255
{ok, _Obj4} = riakc_pb_socket:put(Pid, NewObj1A, [return_head]),
254256
yokozuna_rt:commit(Cluster, ?INDEX),
255257

256-
assert_search(Pid, Cluster, <<"age:26">>, {<<"age">>, <<"26">>}, []),
258+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
259+
<<"age:26">>, {<<"age">>, <<"26">>}, []),
257260

258261
lager:info("Re-Put Map data by dec/inc counter to account for *change* and
259262
allow previously unindexed counter to be searchable"),
@@ -272,10 +275,14 @@ confirm() ->
272275
riakc_map:to_op(Map5)),
273276

274277
yokozuna_rt:commit(Cluster, ?INDEX),
275-
assert_search(Pid, Cluster, <<"0_foo_register:44ab">>, {<<"0_foo_register">>,
276-
<<"44ab">>}, []),
277-
assert_search(Pid, Cluster, <<"1_baz_counter:10">>, {<<"1_baz_counter">>,
278-
<<"10">>}, []),
278+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
279+
<<"0_foo_register:44ab">>,
280+
{<<"0_foo_register">>, <<"44ab">>},
281+
[]),
282+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
283+
<<"1_baz_counter:10">>,
284+
{<<"1_baz_counter">>, <<"10">>},
285+
[]),
279286

280287
lager:info("Test nested json searches w/ unsearched fields ignored"),
281288

@@ -286,23 +293,12 @@ confirm() ->
286293
{ok, _Obj5} = riakc_pb_socket:put(Pid, NewObj5, [return_head]),
287294

288295
yokozuna_rt:commit(Cluster, ?INDEX),
289-
assert_search(Pid, Cluster, <<"paths.quip:88">>,
290-
{<<"paths.quip">>, <<"88">>}, []),
296+
yokozuna_rt:assert_search(Pid, Cluster, ?INDEX,
297+
<<"paths.quip:88">>,
298+
{<<"paths.quip">>, <<"88">>},
299+
[]),
291300

292301
riakc_pb_socket:stop(Pid),
293302

294303
pass.
295304

296-
assert_search(Pid, Cluster, Search, SearchExpect, Params) ->
297-
F = fun(_) ->
298-
lager:info("Searching ~p and asserting it exists",
299-
[SearchExpect]),
300-
{ok,{search_results,[{_Index,Fields}], _Score, Found}} =
301-
riakc_pb_socket:search(Pid, ?INDEX, Search, Params),
302-
?assert(lists:member(SearchExpect, Fields)),
303-
case Found of
304-
1 -> true;
305-
0 -> false
306-
end
307-
end,
308-
rt:wait_until(Cluster, F).

0 commit comments

Comments
 (0)