2016-07-26 18:56:11 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2016 Basho Technologies, Inc.
|
|
|
|
%%
|
|
|
|
%% This file is provided to you under the Apache License,
|
|
|
|
%% Version 2.0 (the "License"); you may not use this file
|
|
|
|
%% except in compliance with the License. You may obtain
|
|
|
|
%% a copy of the License at
|
|
|
|
%%
|
|
|
|
%% http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
%%
|
|
|
|
%% Unless required by applicable law or agreed to in writing,
|
|
|
|
%% software distributed under the License is distributed on an
|
|
|
|
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
%% KIND, either express or implied. See the License for the
|
|
|
|
%% specific language governing permissions and limitations
|
|
|
|
%% under the License.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
2016-07-28 13:04:29 +00:00
|
|
|
%% Verify functionality of async job enable/disable flags in advanced.config.
|
|
|
|
-module(verify_job_enable_ac).
|
2016-07-26 18:56:11 +00:00
|
|
|
|
|
|
|
-behavior(riak_test).
|
2016-07-27 18:24:34 +00:00
|
|
|
-compile(export_all).
|
2016-07-26 18:56:11 +00:00
|
|
|
-export([confirm/0]).
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
2016-07-29 13:56:37 +00:00
|
|
|
-include("job_enable_common.hrl").
|
2016-07-26 18:56:11 +00:00
|
|
|
|
|
|
|
%% Start with all job classes disabled - we'll slowly enable
|
|
|
|
%% and verify all the flags over the course of the test
|
2016-09-02 22:13:09 +00:00
|
|
|
-define(CFG, [{riak_core, [{?APP_CONFIG_KEY, []}]}]).
|
2016-07-27 17:50:58 +00:00
|
|
|
-define(ALL_BUCKETS, [<<"2i_test">>, <<"basic_test">>]).
|
2016-07-26 19:58:40 +00:00
|
|
|
-define(BASIC_TEST_KEYS, [<<"1">>, <<"2">>, <<"3">>]).
|
2016-08-15 17:50:18 +00:00
|
|
|
-define(JOB_CLASSES,
|
|
|
|
[Class || {Class, Enabled} <- ?JOB_CLASS_DEFAULTS, Enabled]).
|
2016-07-26 18:56:11 +00:00
|
|
|
|
|
|
|
confirm() ->
|
|
|
|
lager:info("Deploying 1 node"),
|
2016-07-26 20:52:57 +00:00
|
|
|
rt:set_backend(eleveldb),
|
|
|
|
[Node] = rt:build_cluster(1, ?CFG),
|
2016-07-26 18:56:11 +00:00
|
|
|
|
2016-07-26 19:21:11 +00:00
|
|
|
HttpClient = rt:httpc(Node),
|
|
|
|
PbClient = rt:pbc(Node),
|
2016-07-26 18:56:11 +00:00
|
|
|
|
2016-07-26 19:21:11 +00:00
|
|
|
lager:info("Writing test data via protocol buffers"),
|
|
|
|
write_test_data(PbClient),
|
2016-07-26 18:56:11 +00:00
|
|
|
|
2016-07-27 18:24:34 +00:00
|
|
|
run_tests(HttpClient, [verify_list_buckets_disabled_http,
|
|
|
|
verify_list_keys_disabled_http,
|
|
|
|
verify_secondary_index_disabled_http,
|
|
|
|
verify_mapred_disabled_http]),
|
|
|
|
run_tests(PbClient, [verify_list_buckets_disabled_pb,
|
|
|
|
verify_list_keys_disabled_pb,
|
|
|
|
verify_secondary_index_disabled_pb,
|
|
|
|
verify_mapred_disabled_pb]),
|
2016-07-26 19:21:11 +00:00
|
|
|
|
|
|
|
lager:info("Enabling all job classes"),
|
2016-07-29 13:56:37 +00:00
|
|
|
ok = rpc:call(Node, application, set_env,
|
2016-09-02 22:13:09 +00:00
|
|
|
[riak_core, ?APP_CONFIG_KEY, ?JOB_CLASSES]),
|
2016-07-26 19:21:11 +00:00
|
|
|
|
2016-07-27 18:24:34 +00:00
|
|
|
run_tests(HttpClient, [verify_list_buckets_enabled_http,
|
|
|
|
verify_list_keys_enabled_http,
|
|
|
|
verify_secondary_index_enabled_http,
|
|
|
|
verify_mapred_enabled_http]),
|
|
|
|
run_tests(PbClient, [verify_list_buckets_enabled_pb,
|
|
|
|
verify_list_keys_enabled_pb,
|
|
|
|
verify_secondary_index_enabled_pb,
|
|
|
|
verify_mapred_enabled_pb]),
|
2016-07-26 18:56:11 +00:00
|
|
|
|
|
|
|
pass.
|
|
|
|
|
|
|
|
write_test_data(Client) ->
|
|
|
|
BasicObjs = make_objs(<<"basic_test">>),
|
|
|
|
|
|
|
|
[O1, O2, O3] = make_objs(<<"2i_test">>),
|
|
|
|
MD1 = riakc_obj:get_update_metadata(O2),
|
|
|
|
MD2 = riakc_obj:set_secondary_index(MD1, [{{integer_index, "test_idx"}, [42]}]),
|
|
|
|
O2WithIdx = riakc_obj:update_metadata(O2, MD2),
|
|
|
|
SecIdxObjs = [O1, O2WithIdx, O3],
|
|
|
|
|
2016-07-27 17:50:58 +00:00
|
|
|
[ok = riakc_pb_socket:put(Client, O) || O <- BasicObjs ++ SecIdxObjs].
|
2016-07-26 18:56:11 +00:00
|
|
|
|
|
|
|
make_objs(Bucket) ->
|
|
|
|
[riakc_obj:new(Bucket,
|
|
|
|
list_to_binary([N + $1]), %% Keys = ["1", "2", "3"]
|
|
|
|
list_to_binary([N + $A])) %% Vals = ["A", "B", "C"]
|
|
|
|
|| N <- lists:seq(0, 2)].
|
|
|
|
|
2016-07-27 18:24:34 +00:00
|
|
|
run_tests(Client, TestList) ->
|
|
|
|
lists:foreach(fun(Test) -> run_test(Client, Test) end, TestList).
|
|
|
|
|
|
|
|
run_test(Client, Test) ->
|
|
|
|
lager:info("Running test ~p", [Test]),
|
|
|
|
?MODULE:Test(Client).
|
2016-07-26 18:56:11 +00:00
|
|
|
|
2016-07-27 18:04:33 +00:00
|
|
|
verify_list_buckets_disabled_pb(Client) ->
|
2016-08-15 17:50:18 +00:00
|
|
|
Expected = {error, ?ERRMSG_BIN(?TOKEN_LIST_BUCKETS_S)},
|
2016-07-26 18:56:11 +00:00
|
|
|
?assertEqual(Expected, riakc_pb_socket:list_buckets(Client)).
|
|
|
|
|
2016-07-27 18:04:33 +00:00
|
|
|
verify_list_keys_disabled_pb(Client) ->
|
2016-08-15 17:50:18 +00:00
|
|
|
Expected = {error, ?ERRMSG_BIN(?TOKEN_LIST_KEYS_S)},
|
2016-07-26 19:58:40 +00:00
|
|
|
?assertEqual(Expected, riakc_pb_socket:list_keys(Client, <<"basic_test">>)).
|
|
|
|
|
2016-07-27 18:04:33 +00:00
|
|
|
verify_secondary_index_disabled_pb(Client) ->
|
2016-08-04 19:57:41 +00:00
|
|
|
Expected = {error, ?ERRMSG_BIN(?TOKEN_SEC_INDEX)},
|
2016-07-26 20:52:57 +00:00
|
|
|
?assertEqual(Expected, riakc_pb_socket:get_index(Client, <<"2i_test">>,
|
|
|
|
{integer_index, "test_idx"}, 42)).
|
2016-07-26 19:58:40 +00:00
|
|
|
|
2016-07-27 18:04:33 +00:00
|
|
|
verify_mapred_disabled_pb(Client) ->
|
2016-08-04 19:57:41 +00:00
|
|
|
Expected = {error, ?ERRMSG_BIN(?TOKEN_MAP_REDUCE)},
|
2016-07-27 18:04:33 +00:00
|
|
|
?assertEqual(Expected, riakc_pb_socket:mapred(Client, <<"basic_test">>, [])).
|
|
|
|
|
2016-07-26 19:21:11 +00:00
|
|
|
verify_list_buckets_enabled_pb(Client) ->
|
2016-07-26 18:56:11 +00:00
|
|
|
{ok, Buckets} = riakc_pb_socket:list_buckets(Client),
|
|
|
|
SortedBuckets = lists:sort(Buckets),
|
2016-07-26 19:44:55 +00:00
|
|
|
?assertEqual(SortedBuckets, ?ALL_BUCKETS).
|
|
|
|
|
2016-07-26 19:58:40 +00:00
|
|
|
verify_list_keys_enabled_pb(Client) ->
|
|
|
|
{ok, Keys} = riakc_pb_socket:list_keys(Client, <<"basic_test">>),
|
|
|
|
SortedKeys = lists:sort(Keys),
|
|
|
|
?assertEqual(SortedKeys, ?BASIC_TEST_KEYS).
|
|
|
|
|
2016-07-26 20:52:57 +00:00
|
|
|
verify_secondary_index_enabled_pb(Client) ->
|
|
|
|
Result = riakc_pb_socket:get_index_eq(Client, <<"2i_test">>, {integer_index, "test_idx"}, 42),
|
|
|
|
?assertMatch({ok, {index_results_v1, [<<"2">>], _, _}}, Result).
|
|
|
|
|
2016-07-27 18:16:22 +00:00
|
|
|
verify_mapred_enabled_pb(Client) ->
|
|
|
|
{ok, [{_, Results}]} = riakc_pb_socket:mapred(Client, <<"basic_test">>, []),
|
|
|
|
SortedResults = lists:sort(Results),
|
|
|
|
Expected = [{<<"basic_test">>, integer_to_binary(K)} || K <- lists:seq(1, 3)],
|
|
|
|
?assertEqual(Expected, SortedResults).
|
|
|
|
|
2016-07-26 19:44:55 +00:00
|
|
|
verify_list_buckets_disabled_http(Client) ->
|
|
|
|
Result = rhc:list_buckets(Client),
|
|
|
|
?assertMatch({error, {"403", _}}, Result).
|
|
|
|
|
2016-07-26 19:58:40 +00:00
|
|
|
verify_list_keys_disabled_http(Client) ->
|
|
|
|
Result = rhc:list_keys(Client, <<"basic_test">>),
|
|
|
|
?assertMatch({error, {"403", _}}, Result).
|
|
|
|
|
2016-07-26 20:52:57 +00:00
|
|
|
verify_secondary_index_disabled_http(Client) ->
|
|
|
|
Result = rhc:get_index(Client, <<"2i_test">>, {integer_index, "test_idx"}, 42),
|
|
|
|
?assertMatch({error, {"403", _}}, Result).
|
|
|
|
|
2016-07-27 17:50:58 +00:00
|
|
|
verify_mapred_disabled_http(Client) ->
|
|
|
|
Result = rhc:mapred(Client, <<"basic_test">>, []),
|
|
|
|
?assertMatch({error, {"403", _}}, Result).
|
|
|
|
|
2016-07-26 19:44:55 +00:00
|
|
|
verify_list_buckets_enabled_http(Client) ->
|
|
|
|
{ok, Buckets} = rhc:list_buckets(Client),
|
|
|
|
SortedBuckets = lists:sort(Buckets),
|
|
|
|
?assertEqual(SortedBuckets, ?ALL_BUCKETS).
|
2016-07-26 19:58:40 +00:00
|
|
|
|
|
|
|
verify_list_keys_enabled_http(Client) ->
|
|
|
|
{ok, Keys} = rhc:list_keys(Client, <<"basic_test">>),
|
|
|
|
SortedKeys = lists:sort(Keys),
|
|
|
|
?assertEqual(SortedKeys, ?BASIC_TEST_KEYS).
|
2016-07-26 20:52:57 +00:00
|
|
|
|
|
|
|
verify_secondary_index_enabled_http(Client) ->
|
|
|
|
Result = rhc:get_index(Client, <<"2i_test">>, {integer_index, "test_idx"}, 42),
|
|
|
|
?assertMatch({ok, {index_results_v1, [<<"2">>], _, _}}, Result).
|
2016-07-27 17:50:58 +00:00
|
|
|
|
|
|
|
verify_mapred_enabled_http(Client) ->
|
|
|
|
{ok, [{_, Results}]} = rhc:mapred(Client, <<"basic_test">>, []),
|
|
|
|
SortedResults = lists:sort(Results),
|
|
|
|
Expected = [[<<"basic_test">>, integer_to_binary(K)] || K <- lists:seq(1, 3)],
|
|
|
|
?assertEqual(Expected, SortedResults).
|