2016-01-29 13:54:36 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2015 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(ts_simple_batch).
|
|
|
|
|
|
|
|
-behavior(riak_test).
|
|
|
|
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
|
|
|
|
|
|
-export([confirm/0]).
|
|
|
|
|
2016-03-04 20:32:37 +00:00
|
|
|
%% 900000 is a quantum boundary. Sample records are around 80 bytes.
|
|
|
|
%% Try to create 3 batches: one below 900000, and two above. (Batches
|
|
|
|
%% are constrained to roughly 1MB in size, so ~13k records per batch;
|
|
|
|
%% the batch below 900000 will be terminated by the quantum boundary).
|
2016-01-29 13:54:36 +00:00
|
|
|
-define(LOWER_DATA, 899000).
|
|
|
|
-define(LOWER_QRY, 899990).
|
2016-03-04 20:32:37 +00:00
|
|
|
-define(UPPER_DATA, 920000).
|
2016-01-29 13:54:36 +00:00
|
|
|
-define(UPPER_QRY, 900050).
|
|
|
|
|
|
|
|
confirm() ->
|
2016-11-01 14:03:48 +00:00
|
|
|
DDL = ts_data:get_ddl(),
|
|
|
|
Qry = ts_data:get_valid_qry(?LOWER_QRY, ?UPPER_QRY),
|
|
|
|
Data = ts_data:get_valid_select_data(fun() -> lists:seq(?LOWER_DATA,?UPPER_DATA) end),
|
2016-01-29 13:54:36 +00:00
|
|
|
Expected =
|
2016-11-01 14:03:48 +00:00
|
|
|
{ts_data:get_cols(small),
|
|
|
|
ts_data:exclusive_result_from_data(Data, ?LOWER_QRY-?LOWER_DATA+2, (?LOWER_QRY-?LOWER_DATA)+(?UPPER_QRY-?LOWER_QRY))},
|
|
|
|
|
|
|
|
[Node] = ts_setup:start_cluster(1),
|
|
|
|
Pid = ts_setup:conn([Node]),
|
2016-06-15 20:49:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
rt_intercept:add(Node, {riak_kv_eleveldb_backend,
|
|
|
|
[{{batch_put, 4}, batch_put}]}),
|
|
|
|
|
2016-11-01 14:03:48 +00:00
|
|
|
%% Buried in the bowels of the code path behind ts_ops:ts_put/4
|
2016-06-16 18:49:50 +00:00
|
|
|
%% is a calculation that n_val is the same as the cluster size. I
|
|
|
|
%% want a single node cluster for this test, but n_val of 4, so
|
|
|
|
%% I'll duplicate the path here
|
2016-11-01 14:03:48 +00:00
|
|
|
Bucket = ts_data:get_default_bucket(),
|
|
|
|
{ok,_} = ts_setup:create_bucket_type([Node], DDL, Bucket, 4),
|
|
|
|
ok = ts_setup:activate_bucket_type([Node], Bucket),
|
2016-06-16 18:49:50 +00:00
|
|
|
|
|
|
|
riakc_ts:put(Pid, Bucket, Data),
|
|
|
|
|
|
|
|
Tallies = rpc:call(Node, riak_core_metadata, to_list,
|
|
|
|
[{riak_test, backend_intercept}]),
|
|
|
|
FullTally = lists:foldl(fun tally_tallies/2, 0, Tallies),
|
|
|
|
|
2016-06-16 18:52:20 +00:00
|
|
|
%% 3 batches, n_val=4, 12 total writes to eleveldb
|
|
|
|
?assertEqual(12, FullTally),
|
2016-06-16 18:49:50 +00:00
|
|
|
|
|
|
|
{ok, Got} = riakc_ts:query(Pid, Qry),
|
2016-01-29 13:54:36 +00:00
|
|
|
?assertEqual(Expected, Got),
|
2016-06-15 20:49:51 +00:00
|
|
|
|
2016-01-29 13:54:36 +00:00
|
|
|
pass.
|
2016-06-15 20:49:51 +00:00
|
|
|
|
|
|
|
tally_tallies({_Pid, Vals}, Acc) when is_list(Vals) ->
|
|
|
|
Acc + lists:sum(Vals);
|
|
|
|
tally_tallies({_Pid, Val}, Acc) ->
|
|
|
|
Acc + Val.
|