Skip to content

Commit 81d74cd

Browse files
yokozuna_rt additions for types and better testing w/ allow-mult=true extractors test
(cherry picked from commit 844ee9c)
1 parent 3601f87 commit 81d74cd

File tree

3 files changed

+35
-15
lines changed

3 files changed

+35
-15
lines changed

src/yokozuna_rt.erl

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
-include("yokozuna_rt.hrl").
2424

2525
-export([check_exists/2,
26+
clear_trees/1,
2627
commit/2,
2728
expire_trees/1,
2829
gen_keys/1,
@@ -225,6 +226,15 @@ expire_trees(Cluster) ->
225226
timer:sleep(100),
226227
ok.
227228

229+
%% @doc Expire YZ trees
230+
-spec clear_trees([node()]) -> ok.
231+
clear_trees(Cluster) ->
232+
lager:info("Expire all trees"),
233+
_ = [ok = rpc:call(Node, yz_entropy_mgr, clear_trees, [])
234+
|| Node <- Cluster],
235+
ok.
236+
237+
228238
%% @doc Remove index directories, removing the index.
229239
-spec remove_index_dirs([node()], index_name()) -> ok.
230240
remove_index_dirs(Nodes, IndexName) ->
@@ -364,20 +374,24 @@ create_and_set_index(Cluster, Pid, Bucket, Index) ->
364374
ok = riakc_pb_socket:create_search_index(Pid, Index),
365375
%% For possible legacy upgrade reasons, wrap create index in a wait
366376
wait_for_index(Cluster, Index),
367-
set_index(Pid, Bucket, Index).
377+
set_index(Pid, hd(Cluster), Bucket, Index).
368378
-spec create_and_set_index([node()], pid(), bucket(), index_name(),
369379
schema_name()) -> ok.
370380
create_and_set_index(Cluster, Pid, Bucket, Index, Schema) ->
371381
%% Create a search index and associate with a bucket
372382
lager:info("Create a search index ~s with a custom schema named ~s and " ++
373-
"associate it with bucket ~s", [Index, Schema, Bucket]),
383+
"associate it with bucket ~p", [Index, Schema, Bucket]),
374384
ok = riakc_pb_socket:create_search_index(Pid, Index, Schema, []),
375385
%% For possible legacy upgrade reasons, wrap create index in a wait
376386
wait_for_index(Cluster, Index),
377-
set_index(Pid, Bucket, Index).
378-
379-
-spec set_index(pid(), bucket(), index_name()) -> ok.
380-
set_index(Pid, Bucket, Index) ->
387+
set_index(Pid, hd(Cluster), Bucket, Index).
388+
389+
-spec set_index(pid(), node(), bucket(), index_name()) -> ok.
390+
set_index(_Pid, Node, {BucketType, _Bucket}, Index) ->
391+
lager:info("Create and activate map-based bucket type ~s and tie it to search_index ~s",
392+
[BucketType, Index]),
393+
rt:create_and_activate_bucket_type(Node, BucketType, [{search_index, Index}]);
394+
set_index(Pid, _Node, Bucket, Index) ->
381395
ok = riakc_pb_socket:set_search_index(Pid, Bucket, Index).
382396

383397
internal_solr_url(Host, Port, Index) ->

tests/yz_extractors.erl

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
-include_lib("riakc/include/riakc.hrl").
2929

3030
-define(FMT(S, Args), lists:flatten(io_lib:format(S, Args))).
31+
-define(TYPE1, <<"extractors_in_paradise">>).
32+
-define(TYPE2, <<"extractors_in_paradiso">>).
3133
-define(INDEX1, <<"test_idx1">>).
32-
-define(BUCKET1, <<"test_bkt1">>).
34+
-define(BUCKET1, {?TYPE1, <<"test_bkt1">>}).
3335
-define(INDEX2, <<"test_idx2">>).
34-
-define(BUCKET2, <<"test_bkt2">>).
36+
-define(BUCKET2, {?TYPE2, <<"test_bkt2">>}).
3537
-define(SCHEMANAME, <<"test">>).
3638
-define(TEST_SCHEMA,
3739
<<"<schema name=\"test\" version=\"1.5\">
@@ -278,9 +280,9 @@ get_map(Node) ->
278280
verify_extractor(Node, PacketData, Mod) ->
279281
rpc:call(Node, yz_extractor, run, [PacketData, Mod]).
280282

281-
bucket_url({Host,Port}, BName, Key) ->
282-
?FMT("http://~s:~B/buckets/~s/keys/~s",
283-
[Host, Port, BName, Key]).
283+
bucket_url({Host,Port}, {BType, BName}, Key) ->
284+
?FMT("http://~s:~B/types/~s/buckets/~s/keys/~s",
285+
[Host, Port, BType, BName, Key]).
284286

285287
test_extractor_works(Cluster, Packet) ->
286288
[rt_intercept:add(ANode, {yz_noop_extractor,
@@ -304,7 +306,7 @@ test_extractor_with_aae_expire(Cluster, Index, Bucket, Packet) ->
304306
{Host, Port} = rt:select_random(yokozuna_rt:host_entries(
305307
rt:connection_info(
306308
Cluster))),
307-
URL = bucket_url({Host, Port}, mochiweb_util:quote_plus(Bucket),
309+
URL = bucket_url({Host, Port}, Bucket,
308310
mochiweb_util:quote_plus(Key)),
309311

310312
CT = ?EXTRACTOR_CT,
@@ -326,8 +328,13 @@ test_extractor_with_aae_expire(Cluster, Index, Bucket, Packet) ->
326328
yokozuna_rt:override_schema(APid, Cluster, Index, ?SCHEMANAME,
327329
?TEST_SCHEMA_UPGRADE),
328330

331+
{ok, "200", RHeaders, _} = ibrowse:send_req(URL, [{"Content-Type", CT}], get,
332+
[], []),
333+
VC = proplists:get_value("X-Riak-Vclock", RHeaders),
334+
329335
{ok, "204", _, _} = ibrowse:send_req(
330-
URL, [{"Content-Type", CT}], put, Packet),
336+
URL, [{"Content-Type", CT}, {"X-Riak-Vclock", VC}],
337+
put, Packet),
331338
yokozuna_rt:commit(Cluster, Index),
332339

333340
yokozuna_rt:search_expect({Host, Port}, Index, <<"method">>,

tests/yz_handoff.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ confirm() ->
9999
join_node = Node1,
100100
admin_node = Node2}],
101101

102-
%% Run Shell Script to count/test # of replicas and leave/join
103-
%% nodes from the cluster
102+
%% Run set of leave/join trials and count/test #'s from the cluster
104103
[[begin
105104
check_data(Nodes, KeyCount, BucketURL, SearchURL, State),
106105
check_counts(Pid, KeyCount, BucketURL)

0 commit comments

Comments
 (0)