|
|
@@ -56,6 +56,7 @@
|
|
|
).
|
|
|
|
|
|
all() -> [{group, transports}, {group, rest}].
|
|
|
+suite() -> [{timetrap, {minutes, 20}}].
|
|
|
|
|
|
groups() ->
|
|
|
ResourceSpecificTCs = [t_create_delete_bridge],
|
|
|
@@ -143,15 +144,19 @@ redis_checks() ->
|
|
|
end.
|
|
|
|
|
|
end_per_suite(_Config) ->
|
|
|
- ok = delete_all_bridges(),
|
|
|
+ ok = emqx_bridge_v2_SUITE:delete_all_bridges_and_connectors(),
|
|
|
ok = emqx_common_test_helpers:stop_apps([emqx_conf]),
|
|
|
ok = emqx_connector_test_helpers:stop_apps([emqx_rule_engine, emqx_bridge, emqx_resource]),
|
|
|
_ = application:stop(emqx_connector),
|
|
|
ok.
|
|
|
|
|
|
-init_per_testcase(_Testcase, Config) ->
|
|
|
+init_per_testcase(Testcase, Config0) ->
|
|
|
+ emqx_logger:set_log_level(debug),
|
|
|
ok = delete_all_rules(),
|
|
|
- ok = delete_all_bridges(),
|
|
|
+ ok = emqx_bridge_v2_SUITE:delete_all_bridges_and_connectors(),
|
|
|
+ UniqueNum = integer_to_binary(erlang:unique_integer()),
|
|
|
+ Name = <<(atom_to_binary(Testcase))/binary, UniqueNum/binary>>,
|
|
|
+ Config = [{bridge_name, Name} | Config0],
|
|
|
case {?config(connector_type, Config), ?config(batch_mode, Config)} of
|
|
|
{undefined, _} ->
|
|
|
Config;
|
|
|
@@ -165,7 +170,13 @@ init_per_testcase(_Testcase, Config) ->
|
|
|
IsBatch = (BatchMode =:= batch_on),
|
|
|
BridgeConfig0 = maps:merge(RedisConnConfig, ?COMMON_REDIS_OPTS),
|
|
|
BridgeConfig1 = BridgeConfig0#{<<"resource_opts">> => ResourceConfig},
|
|
|
- [{bridge_config, BridgeConfig1}, {is_batch, IsBatch} | Config]
|
|
|
+ BridgeType = list_to_atom(atom_to_list(RedisType) ++ "_producer"),
|
|
|
+ [
|
|
|
+ {bridge_type, BridgeType},
|
|
|
+ {bridge_config, BridgeConfig1},
|
|
|
+ {is_batch, IsBatch}
|
|
|
+ | Config
|
|
|
+ ]
|
|
|
end.
|
|
|
|
|
|
end_per_testcase(_Testcase, Config) ->
|
|
|
@@ -173,10 +184,18 @@ end_per_testcase(_Testcase, Config) ->
|
|
|
ProxyPort = ?config(proxy_port, Config),
|
|
|
ok = snabbkaffe:stop(),
|
|
|
emqx_common_test_helpers:reset_proxy(ProxyHost, ProxyPort),
|
|
|
- ok = delete_all_bridges().
|
|
|
+ ok = emqx_bridge_v2_SUITE:delete_all_bridges_and_connectors().
|
|
|
|
|
|
t_create_delete_bridge(Config) ->
|
|
|
- Name = <<"mybridge">>,
|
|
|
+ Pid = erlang:whereis(eredis_sentinel),
|
|
|
+ ct:pal("t_create_detele_bridge:~p~n", [
|
|
|
+ #{
|
|
|
+ config => Config,
|
|
|
+ sentinel => Pid,
|
|
|
+ eredis_sentinel => Pid =/= undefined andalso erlang:process_info(Pid)
|
|
|
+ }
|
|
|
+ ]),
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = ?config(connector_type, Config),
|
|
|
BridgeConfig = ?config(bridge_config, Config),
|
|
|
IsBatch = ?config(is_batch, Config),
|
|
|
@@ -184,13 +203,11 @@ t_create_delete_bridge(Config) ->
|
|
|
{ok, _},
|
|
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
|
|
),
|
|
|
-
|
|
|
ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
-
|
|
|
?WAIT(
|
|
|
{ok, connected},
|
|
|
emqx_resource:health_check(ResourceId),
|
|
|
- 5
|
|
|
+ 10
|
|
|
),
|
|
|
|
|
|
RedisType = atom_to_binary(Type),
|
|
|
@@ -244,7 +261,7 @@ t_check_values(_Config) ->
|
|
|
).
|
|
|
|
|
|
t_check_replay(Config) ->
|
|
|
- Name = <<"toxic_bridge">>,
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = <<"redis_single">>,
|
|
|
Topic = <<"local_topic/test">>,
|
|
|
ProxyName = "redis_single_tcp",
|
|
|
@@ -324,15 +341,15 @@ t_permanent_error(_Config) ->
|
|
|
),
|
|
|
ok = emqx_bridge:remove(Type, Name).
|
|
|
|
|
|
-t_auth_username_password(_Config) ->
|
|
|
- Name = <<"mybridge">>,
|
|
|
+t_auth_username_password(Config) ->
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = <<"redis_single">>,
|
|
|
- ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
BridgeConfig = username_password_redis_bridge_config(),
|
|
|
?assertMatch(
|
|
|
{ok, _},
|
|
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
|
|
),
|
|
|
+ ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
?WAIT(
|
|
|
{ok, connected},
|
|
|
emqx_resource:health_check(ResourceId),
|
|
|
@@ -340,16 +357,16 @@ t_auth_username_password(_Config) ->
|
|
|
),
|
|
|
ok = emqx_bridge:remove(Type, Name).
|
|
|
|
|
|
-t_auth_error_username_password(_Config) ->
|
|
|
- Name = <<"mybridge">>,
|
|
|
+t_auth_error_username_password(Config) ->
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = <<"redis_single">>,
|
|
|
- ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
BridgeConfig0 = username_password_redis_bridge_config(),
|
|
|
BridgeConfig = maps:merge(BridgeConfig0, #{<<"password">> => <<"wrong_password">>}),
|
|
|
?assertMatch(
|
|
|
{ok, _},
|
|
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
|
|
),
|
|
|
+ ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
?WAIT(
|
|
|
{ok, disconnected},
|
|
|
emqx_resource:health_check(ResourceId),
|
|
|
@@ -361,16 +378,16 @@ t_auth_error_username_password(_Config) ->
|
|
|
),
|
|
|
ok = emqx_bridge:remove(Type, Name).
|
|
|
|
|
|
-t_auth_error_password_only(_Config) ->
|
|
|
- Name = <<"mybridge">>,
|
|
|
+t_auth_error_password_only(Config) ->
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = <<"redis_single">>,
|
|
|
- ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
BridgeConfig0 = toxiproxy_redis_bridge_config(),
|
|
|
BridgeConfig = maps:merge(BridgeConfig0, #{<<"password">> => <<"wrong_password">>}),
|
|
|
?assertMatch(
|
|
|
{ok, _},
|
|
|
emqx_bridge:create(Type, Name, BridgeConfig)
|
|
|
),
|
|
|
+ ResourceId = emqx_bridge_resource:resource_id(Type, Name),
|
|
|
?assertEqual(
|
|
|
{ok, disconnected},
|
|
|
emqx_resource:health_check(ResourceId)
|
|
|
@@ -382,7 +399,7 @@ t_auth_error_password_only(_Config) ->
|
|
|
ok = emqx_bridge:remove(Type, Name).
|
|
|
|
|
|
t_create_disconnected(Config) ->
|
|
|
- Name = <<"toxic_bridge">>,
|
|
|
+ Name = ?config(bridge_name, Config),
|
|
|
Type = <<"redis_single">>,
|
|
|
|
|
|
?check_trace(
|
|
|
@@ -450,10 +467,8 @@ check_resource_queries(ResourceId, BaseTopic, IsBatch) ->
|
|
|
added_msgs(ResourceId, BaseTopic, Payload) ->
|
|
|
lists:flatmap(
|
|
|
fun(K) ->
|
|
|
- {ok, Results} = emqx_resource:simple_sync_query(
|
|
|
- ResourceId,
|
|
|
- {cmd, [<<"LRANGE">>, K, <<"0">>, <<"-1">>]}
|
|
|
- ),
|
|
|
+ Message = {cmd, [<<"LRANGE">>, K, <<"0">>, <<"-1">>]},
|
|
|
+ {ok, Results} = emqx_resource:simple_sync_query(ResourceId, Message),
|
|
|
[El || El <- Results, El =:= Payload]
|
|
|
end,
|
|
|
[format_redis_key(BaseTopic, S) || S <- lists:seq(0, ?KEYSHARDS - 1)]
|
|
|
@@ -482,14 +497,6 @@ delete_all_rules() ->
|
|
|
emqx_rule_engine:get_rules()
|
|
|
).
|
|
|
|
|
|
-delete_all_bridges() ->
|
|
|
- lists:foreach(
|
|
|
- fun(#{name := Name, type := Type}) ->
|
|
|
- emqx_bridge:remove(Type, Name)
|
|
|
- end,
|
|
|
- emqx_bridge:list()
|
|
|
- ).
|
|
|
-
|
|
|
all_test_hosts() ->
|
|
|
Confs = [
|
|
|
?REDIS_TOXYPROXY_CONNECT_CONFIG
|
|
|
@@ -554,12 +561,12 @@ redis_connect_configs() ->
|
|
|
tcp => #{
|
|
|
<<"servers">> => <<"redis-sentinel:26379">>,
|
|
|
<<"redis_type">> => <<"sentinel">>,
|
|
|
- <<"sentinel">> => <<"mymaster">>
|
|
|
+ <<"sentinel">> => <<"mytcpmaster">>
|
|
|
},
|
|
|
tls => #{
|
|
|
<<"servers">> => <<"redis-sentinel-tls:26380">>,
|
|
|
<<"redis_type">> => <<"sentinel">>,
|
|
|
- <<"sentinel">> => <<"mymaster">>,
|
|
|
+ <<"sentinel">> => <<"mytlsmaster">>,
|
|
|
<<"ssl">> => redis_connect_ssl_opts(redis_sentinel)
|
|
|
}
|
|
|
},
|