2013-04-20 17:22:34 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2013 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.
|
|
|
|
%%
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
-module(verify_2i_limit).
|
|
|
|
-behavior(riak_test).
|
|
|
|
-export([confirm/0]).
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
2013-07-12 19:34:08 +00:00
|
|
|
-include_lib("riakc/include/riakc.hrl").
|
2013-07-27 15:21:14 +00:00
|
|
|
-import(secondary_index_tests, [put_an_object/2, put_an_object/4, int_to_key/1,
|
2013-08-07 20:06:33 +00:00
|
|
|
stream_pb/3, http_query/3, pb_query/3, http_stream/3]).
|
2013-04-20 17:22:34 +00:00
|
|
|
-define(BUCKET, <<"2ibucket">>).
|
|
|
|
-define(FOO, <<"foo">>).
|
|
|
|
-define(MAX_RESULTS, 50).
|
|
|
|
|
|
|
|
confirm() ->
|
|
|
|
inets:start(),
|
|
|
|
|
|
|
|
Nodes = rt:build_cluster(3),
|
|
|
|
?assertEqual(ok, (rt:wait_until_nodes_ready(Nodes))),
|
|
|
|
|
|
|
|
RiakHttp = rt:http_url(hd(Nodes)),
|
|
|
|
PBPid = rt:pbc(hd(Nodes)),
|
|
|
|
|
|
|
|
[put_an_object(PBPid, N) || N <- lists:seq(0, 100)],
|
|
|
|
|
|
|
|
ExpectedKeys = lists:sort([int_to_key(N) || N <- lists:seq(0, 100)]),
|
|
|
|
{FirstHalf, Rest} = lists:split(?MAX_RESULTS, ExpectedKeys),
|
|
|
|
Q = {<<"$key">>, int_to_key(0), int_to_key(999)},
|
|
|
|
|
|
|
|
%% PB
|
|
|
|
{ok, PBRes} = stream_pb(PBPid, Q, [{max_results, ?MAX_RESULTS}]),
|
|
|
|
?assertEqual(FirstHalf, proplists:get_value(keys, PBRes, [])),
|
|
|
|
PBContinuation = proplists:get_value(continuation, PBRes),
|
|
|
|
|
|
|
|
{ok, PBKeys2} = stream_pb(PBPid, Q, [{continuation, PBContinuation}]),
|
|
|
|
?assertEqual(Rest, proplists:get_value(keys, PBKeys2, [])),
|
|
|
|
|
|
|
|
%% HTTP
|
2013-08-07 20:06:33 +00:00
|
|
|
HttpRes = http_stream(RiakHttp, Q, [{max_results, ?MAX_RESULTS}]),
|
2013-04-20 17:22:34 +00:00
|
|
|
?assertEqual(FirstHalf, proplists:get_value(<<"keys">>, HttpRes, [])),
|
|
|
|
HttpContinuation = proplists:get_value(<<"continuation">>, HttpRes),
|
|
|
|
?assertEqual(PBContinuation, HttpContinuation),
|
|
|
|
|
|
|
|
HttpRes2 = http_query(RiakHttp, Q, [{continuation, HttpContinuation}]),
|
|
|
|
?assertEqual(Rest, proplists:get_value(<<"keys">>, HttpRes2, [])),
|
|
|
|
|
2013-05-23 09:35:56 +00:00
|
|
|
%% Multiple indexes for single key
|
|
|
|
O1 = riakc_obj:new(?BUCKET, <<"bob">>, <<"1">>),
|
|
|
|
Md = riakc_obj:get_metadata(O1),
|
|
|
|
Md2 = riakc_obj:set_secondary_index(Md, {{integer_index, "i1"}, [300, 301, 302]}),
|
|
|
|
O2 = riakc_obj:update_metadata(O1, Md2),
|
|
|
|
riakc_pb_socket:put(PBPid, O2),
|
|
|
|
|
|
|
|
MQ = {"i1_int", 300, 302},
|
2013-07-16 20:20:49 +00:00
|
|
|
{ok, ?INDEX_RESULTS{terms=Terms, continuation=RTContinuation}} = pb_query(PBPid, MQ, [{max_results, 2}, return_terms]),
|
2013-05-23 09:35:56 +00:00
|
|
|
|
|
|
|
?assertEqual([{<<"300">>, <<"bob">>},
|
2013-07-12 19:34:08 +00:00
|
|
|
{<<"301">>, <<"bob">>}], Terms),
|
2013-05-23 09:35:56 +00:00
|
|
|
|
2013-07-16 20:20:49 +00:00
|
|
|
{ok, ?INDEX_RESULTS{terms=Terms2}} = pb_query(PBPid, MQ, [{max_results, 2}, return_terms,
|
2013-07-12 19:34:08 +00:00
|
|
|
{continuation, RTContinuation}]),
|
2013-05-23 09:35:56 +00:00
|
|
|
|
2013-07-12 19:34:08 +00:00
|
|
|
?assertEqual([{<<"302">>,<<"bob">>}], Terms2),
|
2013-05-23 09:35:56 +00:00
|
|
|
|
2013-07-27 15:21:14 +00:00
|
|
|
%% gh611 - equals query pagination
|
2013-07-31 14:40:47 +00:00
|
|
|
riakc_pb_socket:delete(PBPid, ?BUCKET, <<"bob">>),
|
|
|
|
rt:wait_until(fun() -> rt:pbc_really_deleted(PBPid, ?BUCKET, [<<"bob">>]) end),
|
2013-07-27 15:21:14 +00:00
|
|
|
|
2013-07-31 14:40:47 +00:00
|
|
|
[put_an_object(PBPid, int_to_key(N), 1000, <<"myval">>) || N <- lists:seq(0, 100)],
|
2013-07-27 15:21:14 +00:00
|
|
|
|
2013-07-31 14:40:47 +00:00
|
|
|
[ verify_eq_pag(PBPid, RiakHttp, EqualsQuery, FirstHalf, Rest) ||
|
|
|
|
EqualsQuery <- [{"field1_bin", <<"myval">>},
|
|
|
|
{"field2_int", 1000},
|
|
|
|
{"$bucket", ?BUCKET}]],
|
|
|
|
|
|
|
|
riakc_pb_socket:stop(PBPid),
|
|
|
|
pass.
|
|
|
|
|
|
|
|
verify_eq_pag(PBPid, RiakHttp, EqualsQuery, FirstHalf, Rest) ->
|
2013-07-27 15:21:14 +00:00
|
|
|
HTTPEqs = http_query(RiakHttp, EqualsQuery, [{max_results, ?MAX_RESULTS}]),
|
2013-07-31 14:40:47 +00:00
|
|
|
?assertEqual({EqualsQuery, FirstHalf},
|
|
|
|
{EqualsQuery, proplists:get_value(<<"keys">>, HTTPEqs, [])}),
|
2013-07-27 15:21:14 +00:00
|
|
|
EqualsHttpContinuation = proplists:get_value(<<"continuation">>, HTTPEqs),
|
|
|
|
|
2013-07-31 14:40:47 +00:00
|
|
|
HTTPEqs2 = http_query(RiakHttp, EqualsQuery,
|
|
|
|
[{continuation, EqualsHttpContinuation}]),
|
|
|
|
?assertEqual({EqualsQuery, Rest},
|
|
|
|
{EqualsQuery, proplists:get_value(<<"keys">>, HTTPEqs2, [])}),
|
2013-07-27 15:21:14 +00:00
|
|
|
|
|
|
|
%% And PB
|
|
|
|
|
2013-07-31 14:40:47 +00:00
|
|
|
{ok, EqPBRes} = stream_pb(PBPid, EqualsQuery,
|
|
|
|
[{max_results, ?MAX_RESULTS}]),
|
|
|
|
?assertEqual({EqualsQuery, FirstHalf},
|
|
|
|
{EqualsQuery, proplists:get_value(keys, EqPBRes, [])}),
|
2013-07-27 15:21:14 +00:00
|
|
|
EqPBContinuation = proplists:get_value(continuation, EqPBRes),
|
|
|
|
|
2013-07-31 14:40:47 +00:00
|
|
|
{ok, EqPBKeys2} = stream_pb(PBPid, EqualsQuery,
|
|
|
|
[{continuation, EqPBContinuation}]),
|
|
|
|
?assertEqual({EqualsQuery, Rest},
|
|
|
|
{EqualsQuery, proplists:get_value(keys, EqPBKeys2, [])}).
|