Skip to content

Commit aa4b672

Browse files
committed
ts_simple_invdist_funs: also test on tables with desc keys
1 parent 958e628 commit aa4b672

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

tests/ts_simple_invdist_funs_SUITE.erl

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
-include_lib("eunit/include/eunit.hrl").
3737
-include("ts_qbuf_util.hrl").
3838

39+
-define(TABLE_A, "table_with_regular_keys").
40+
-define(TABLE_D, "table_with_descending_keys").
3941

4042
suite() ->
4143
[{timetrap, {minutes, 5}}].
@@ -44,8 +46,10 @@ init_per_suite(Cfg) ->
4446
Cluster = ts_setup:start_cluster(1),
4547
C = rt:pbc(hd(Cluster)),
4648
Data = make_data(),
47-
ok = create_table(C, ?TABLE),
48-
ok = insert_data(C, ?TABLE, Data),
49+
ok = create_table(C, ?TABLE_A),
50+
ok = create_table_desc(C, ?TABLE_D),
51+
ok = insert_data(C, ?TABLE_A, Data),
52+
ok = insert_data(C, ?TABLE_D, Data),
4953
[{cluster, Cluster},
5054
{data, Data} | Cfg].
5155

@@ -185,7 +189,7 @@ query_invdist_mode(Cfg) ->
185189
query_invdist_errors(Cfg) ->
186190
lists:foreach(
187191
fun({Select, Extra, ErrPat}) ->
188-
Qry = make_query(Select, Extra),
192+
Qry = make_query(?TABLE_A, Select, Extra),
189193
?assertEqual(
190194
ok,
191195
ts_qbuf_util:ack_query_error(Cfg, Qry, ?E_SUBMIT, ErrPat))
@@ -289,6 +293,18 @@ create table " ++ Table ++ "
289293
{ok, {[], []}} = riakc_ts:query(Client, DDL),
290294
ok.
291295

296+
create_table_desc(Client, Table) ->
297+
DDL = "
298+
create table " ++ Table ++ "
299+
(a timestamp not null,
300+
b double,
301+
c sint64,
302+
d sint64,
303+
e sint64,
304+
primary key ((quantum(a, 10, h)), a desc))",
305+
{ok, {[], []}} = riakc_ts:query(Client, DDL),
306+
ok.
307+
292308
data_generator(I) ->
293309
{?TIMEBASE + (I + 1) * 1000,
294310
100 * math:cos(float(I) / 10 * math:pi()),
@@ -313,10 +329,12 @@ insert_data(C, Table, Data) ->
313329
end.
314330

315331
make_query(Select) ->
316-
make_query(Select, "").
317-
make_query(Select, Extra) ->
332+
make_query(?TABLE_A, Select, "").
333+
make_query(Table, Select) ->
334+
make_query(Table, Select, "").
335+
make_query(Table, Select, Extra) ->
318336
fmt("select ~s from ~s where a >= ~b and a <= ~b~s",
319-
[Select, ?TABLE,
337+
[Select, Table,
320338
?TIMEBASE, ?TIMEBASE * 1000,
321339
[" " ++ Extra || Extra /= []]]).
322340

@@ -334,19 +352,23 @@ check_column(C, Col, Data) ->
334352
{0.36, "(3.6/10)"},
335353
{0.40, "0.5 - 1 * 0.1"}],
336354
PercentileVariety <- [percentile_cont, percentile_disc]],
355+
Checker =
356+
fun(Q, Need) ->
357+
ct:log("Query \"~s\"", [Q]),
358+
{ok, {_Cols, [{Got}]}} =
359+
riakc_ts:query(C, Q, [], undefined, []),
360+
case Got == Need of
361+
true ->
362+
ok;
363+
false ->
364+
ct:fail("Got ~p, Need ~p\n", [Got, Need])
365+
end
366+
end,
337367
ok == lists:foreach(
338368
fun({PercentileFun, Pc, Pc_s}) ->
339-
Query = make_query(fmt("~s(~s, ~s)", [PercentileFun, Col, Pc_s])),
340-
ct:log("Query \"~s\"", [Query]),
341-
{ok, {_Cols, [{Got}]}} =
342-
riakc_ts:query(C, Query, [], undefined, []),
343369
Need = apply(?MODULE, PercentileFun, [Col, Pc, SortedData]),
344-
case Got == Need of
345-
true ->
346-
ok;
347-
false ->
348-
ct:fail("Got ~p, Need ~p\n", [Got, Need])
349-
end
370+
ok = Checker(make_query(?TABLE_A, fmt("~s(~s, ~s)", [PercentileFun, Col, Pc_s])), Need),
371+
ok = Checker(make_query(?TABLE_D, fmt("~s(~s, ~s)", [PercentileFun, Col, Pc_s])), Need)
350372
end,
351373
Combos).
352374

@@ -370,7 +392,7 @@ load_intercept(Node, C, Intercept) ->
370392
wait_until_qbuf_mgr_reinit(C).
371393

372394
wait_until_qbuf_mgr_reinit(C) ->
373-
ProbingQuery = make_query("*", ""),
395+
ProbingQuery = make_query("*"),
374396
case riakc_ts:query(C, ProbingQuery, [], undefined, []) of
375397
{ok, _Data} ->
376398
ok;

0 commit comments

Comments
 (0)