|
@@ -13,8 +13,13 @@
|
|
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
|
|
|
|
|
|
|
% SQL definitions
|
|
% SQL definitions
|
|
|
--define(STREAM, "stream").
|
|
|
|
|
|
|
+
|
|
|
|
|
+-define(STREAM, "demo_stream").
|
|
|
|
|
+%% could not be "stream" in Production Environment
|
|
|
|
|
+%% especially not in hstreamdb_sql CLI client
|
|
|
|
|
+
|
|
|
-define(REPLICATION_FACTOR, 1).
|
|
-define(REPLICATION_FACTOR, 1).
|
|
|
|
|
+
|
|
|
%% in seconds
|
|
%% in seconds
|
|
|
-define(BACKLOG_RETENTION_SECOND, (24 * 60 * 60)).
|
|
-define(BACKLOG_RETENTION_SECOND, (24 * 60 * 60)).
|
|
|
-define(SHARD_COUNT, 1).
|
|
-define(SHARD_COUNT, 1).
|
|
@@ -146,16 +151,23 @@ t_setup_via_config_and_publish(Config) ->
|
|
|
begin
|
|
begin
|
|
|
?wait_async_action(
|
|
?wait_async_action(
|
|
|
?assertEqual(ok, send_message(Config, Data)),
|
|
?assertEqual(ok, send_message(Config, Data)),
|
|
|
- #{?snk_kind := hstreamdb_connector_query_return},
|
|
|
|
|
|
|
+ #{?snk_kind := hstreamdb_connector_query_append_return},
|
|
|
10_000
|
|
10_000
|
|
|
),
|
|
),
|
|
|
ok
|
|
ok
|
|
|
end,
|
|
end,
|
|
|
fun(Trace0) ->
|
|
fun(Trace0) ->
|
|
|
- Trace = ?of_kind(hstreamdb_connector_query_return, Trace0),
|
|
|
|
|
|
|
+ Trace = ?of_kind(hstreamdb_connector_query_append_return, Trace0),
|
|
|
lists:foreach(
|
|
lists:foreach(
|
|
|
fun(EachTrace) ->
|
|
fun(EachTrace) ->
|
|
|
- ?assertMatch(#{result := #{streamName := <<?STREAM>>}}, EachTrace)
|
|
|
|
|
|
|
+ case ?config(enable_batch, Config) of
|
|
|
|
|
+ true ->
|
|
|
|
|
+ ?assertMatch(#{result := ok, is_batch := true}, EachTrace);
|
|
|
|
|
+ false ->
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ #{result := #{'batchId' := _}, is_batch := false}, EachTrace
|
|
|
|
|
+ )
|
|
|
|
|
+ end
|
|
|
end,
|
|
end,
|
|
|
Trace
|
|
Trace
|
|
|
),
|
|
),
|
|
@@ -181,16 +193,26 @@ t_setup_via_http_api_and_publish(Config) ->
|
|
|
begin
|
|
begin
|
|
|
?wait_async_action(
|
|
?wait_async_action(
|
|
|
?assertEqual(ok, send_message(Config, Data)),
|
|
?assertEqual(ok, send_message(Config, Data)),
|
|
|
- #{?snk_kind := hstreamdb_connector_query_return},
|
|
|
|
|
|
|
+ #{?snk_kind := hstreamdb_connector_query_append_return},
|
|
|
10_000
|
|
10_000
|
|
|
),
|
|
),
|
|
|
ok
|
|
ok
|
|
|
end,
|
|
end,
|
|
|
fun(Trace) ->
|
|
fun(Trace) ->
|
|
|
- ?assertMatch(
|
|
|
|
|
- [#{result := #{streamName := <<?STREAM>>}}],
|
|
|
|
|
- ?of_kind(hstreamdb_connector_query_return, Trace)
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ lists:foreach(
|
|
|
|
|
+ fun(EachTrace) ->
|
|
|
|
|
+ case ?config(enable_batch, Config) of
|
|
|
|
|
+ true ->
|
|
|
|
|
+ ?assertMatch(#{result := ok, is_batch := true}, EachTrace);
|
|
|
|
|
+ false ->
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ #{result := #{'batchId' := _}, is_batch := false}, EachTrace
|
|
|
|
|
+ )
|
|
|
|
|
+ end
|
|
|
|
|
+ end,
|
|
|
|
|
+ ?of_kind(hstreamdb_connector_query_append_return, Trace)
|
|
|
|
|
+ ),
|
|
|
|
|
+ ok
|
|
|
end
|
|
end
|
|
|
),
|
|
),
|
|
|
ok.
|
|
ok.
|
|
@@ -240,6 +262,7 @@ t_write_failure(Config) ->
|
|
|
ProxyPort = ?config(proxy_port, Config),
|
|
ProxyPort = ?config(proxy_port, Config),
|
|
|
ProxyHost = ?config(proxy_host, Config),
|
|
ProxyHost = ?config(proxy_host, Config),
|
|
|
QueryMode = ?config(query_mode, Config),
|
|
QueryMode = ?config(query_mode, Config),
|
|
|
|
|
+ EnableBatch = ?config(enable_batch, Config),
|
|
|
Data = rand_data(),
|
|
Data = rand_data(),
|
|
|
{{ok, _}, {ok, _}} =
|
|
{{ok, _}, {ok, _}} =
|
|
|
?wait_async_action(
|
|
?wait_async_action(
|
|
@@ -251,10 +274,16 @@ t_write_failure(Config) ->
|
|
|
health_check_resource_down(Config),
|
|
health_check_resource_down(Config),
|
|
|
case QueryMode of
|
|
case QueryMode of
|
|
|
sync ->
|
|
sync ->
|
|
|
- ?assertMatch(
|
|
|
|
|
- {error, {resource_error, #{msg := "call resource timeout", reason := timeout}}},
|
|
|
|
|
- send_message(Config, Data)
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ case EnableBatch of
|
|
|
|
|
+ true ->
|
|
|
|
|
+ %% append to batch always returns ok
|
|
|
|
|
+ ?assertMatch(ok, send_message(Config, Data));
|
|
|
|
|
+ false ->
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ {error, {cannot_list_shards, {<<?STREAM>>, econnrefused}}},
|
|
|
|
|
+ send_message(Config, Data)
|
|
|
|
|
+ )
|
|
|
|
|
+ end;
|
|
|
async ->
|
|
async ->
|
|
|
%% TODO: async mode is not supported yet,
|
|
%% TODO: async mode is not supported yet,
|
|
|
%% but it will return ok if calling emqx_resource_buffer_worker:async_query/3,
|
|
%% but it will return ok if calling emqx_resource_buffer_worker:async_query/3,
|
|
@@ -282,17 +311,23 @@ t_simple_query(Config) ->
|
|
|
end,
|
|
end,
|
|
|
Requests
|
|
Requests
|
|
|
),
|
|
),
|
|
|
- #{?snk_kind := hstreamdb_connector_query_return},
|
|
|
|
|
|
|
+ #{?snk_kind := hstreamdb_connector_query_append_return},
|
|
|
10_000
|
|
10_000
|
|
|
)
|
|
)
|
|
|
end,
|
|
end,
|
|
|
- fun(Trace0) ->
|
|
|
|
|
- Trace = ?of_kind(hstreamdb_connector_query_return, Trace0),
|
|
|
|
|
|
|
+ fun(Trace) ->
|
|
|
lists:foreach(
|
|
lists:foreach(
|
|
|
fun(EachTrace) ->
|
|
fun(EachTrace) ->
|
|
|
- ?assertMatch(#{result := #{streamName := <<?STREAM>>}}, EachTrace)
|
|
|
|
|
|
|
+ case ?config(enable_batch, Config) of
|
|
|
|
|
+ true ->
|
|
|
|
|
+ ?assertMatch(#{result := ok, is_batch := true}, EachTrace);
|
|
|
|
|
+ false ->
|
|
|
|
|
+ ?assertMatch(
|
|
|
|
|
+ #{result := #{'batchId' := _}, is_batch := false}, EachTrace
|
|
|
|
|
+ )
|
|
|
|
|
+ end
|
|
|
end,
|
|
end,
|
|
|
- Trace
|
|
|
|
|
|
|
+ ?of_kind(hstreamdb_connector_query_append_return, Trace)
|
|
|
),
|
|
),
|
|
|
ok
|
|
ok
|
|
|
end
|
|
end
|
|
@@ -432,7 +467,7 @@ client(Name, Config, N) ->
|
|
|
try
|
|
try
|
|
|
_ = hstreamdb:stop_client(Name),
|
|
_ = hstreamdb:stop_client(Name),
|
|
|
{ok, Client} = hstreamdb:start_client(Name, default_options(Config)),
|
|
{ok, Client} = hstreamdb:start_client(Name, default_options(Config)),
|
|
|
- {ok, echo} = hstreamdb:echo(Client),
|
|
|
|
|
|
|
+ ok = hstreamdb_client:echo(Client),
|
|
|
Client
|
|
Client
|
|
|
catch
|
|
catch
|
|
|
Class:Error ->
|
|
Class:Error ->
|
|
@@ -509,7 +544,7 @@ health_check_resource_down(Config) ->
|
|
|
% These funs start and then stop the hstreamdb connection
|
|
% These funs start and then stop the hstreamdb connection
|
|
|
connect_and_create_stream(Config) ->
|
|
connect_and_create_stream(Config) ->
|
|
|
?WITH_CLIENT(
|
|
?WITH_CLIENT(
|
|
|
- _ = hstreamdb:create_stream(
|
|
|
|
|
|
|
+ _ = hstreamdb_client:create_stream(
|
|
|
Client, ?STREAM, ?REPLICATION_FACTOR, ?BACKLOG_RETENTION_SECOND, ?SHARD_COUNT
|
|
Client, ?STREAM, ?REPLICATION_FACTOR, ?BACKLOG_RETENTION_SECOND, ?SHARD_COUNT
|
|
|
)
|
|
)
|
|
|
),
|
|
),
|
|
@@ -531,7 +566,7 @@ connect_and_create_stream(Config) ->
|
|
|
|
|
|
|
|
connect_and_delete_stream(Config) ->
|
|
connect_and_delete_stream(Config) ->
|
|
|
?WITH_CLIENT(
|
|
?WITH_CLIENT(
|
|
|
- _ = hstreamdb:delete_stream(Client, ?STREAM)
|
|
|
|
|
|
|
+ _ = hstreamdb_client:delete_stream(Client, ?STREAM)
|
|
|
).
|
|
).
|
|
|
|
|
|
|
|
%%--------------------------------------------------------------------
|
|
%%--------------------------------------------------------------------
|