ci: add env vars to run cassandra tests locally
This commit is contained in:
parent
186e1591df
commit
497e735bf4
|
@ -39,6 +39,10 @@ services:
|
||||||
- 19042:9042
|
- 19042:9042
|
||||||
# Cassandra TLS
|
# Cassandra TLS
|
||||||
- 19142:9142
|
- 19142:9142
|
||||||
|
# Cassandra No Auth
|
||||||
|
- 19043:9043
|
||||||
|
# Cassandra TLS No Auth
|
||||||
|
- 19143:9143
|
||||||
# S3
|
# S3
|
||||||
- 19000:19000
|
- 19000:19000
|
||||||
# S3 TLS
|
# S3 TLS
|
||||||
|
|
|
@ -96,6 +96,18 @@
|
||||||
"upstream": "cassandra:9142",
|
"upstream": "cassandra:9142",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "cassa_no_auth_tcp",
|
||||||
|
"listen": "0.0.0.0:9043",
|
||||||
|
"upstream": "cassandra_noauth:9042",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "cassa_no_auth_tls",
|
||||||
|
"listen": "0.0.0.0:9143",
|
||||||
|
"upstream": "cassandra_noauth:9142",
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "sqlserver",
|
"name": "sqlserver",
|
||||||
"listen": "0.0.0.0:1433",
|
"listen": "0.0.0.0:1433",
|
||||||
|
|
|
@ -11,6 +11,14 @@
|
||||||
-include_lib("common_test/include/ct.hrl").
|
-include_lib("common_test/include/ct.hrl").
|
||||||
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
|
||||||
|
|
||||||
|
%% To run this test locally:
|
||||||
|
%% ./scripts/ct/run.sh --app apps/emqx_bridge_cassandra --only-up
|
||||||
|
%% PROFILE=emqx-enterprise PROXY_HOST=localhost CASSA_TLS_HOST=localhost \
|
||||||
|
%% CASSA_TLS_PORT=19142 CASSA_TCP_HOST=localhost CASSA_TCP_NO_AUTH_HOST=localhost \
|
||||||
|
%% CASSA_TCP_PORT=19042 CASSA_TCP_NO_AUTH_PORT=19043 \
|
||||||
|
%% ./rebar3 ct --name 'test@127.0.0.1' -v --suite \
|
||||||
|
%% apps/emqx_bridge_cassandra/test/emqx_bridge_cassandra_SUITE
|
||||||
|
|
||||||
% SQL definitions
|
% SQL definitions
|
||||||
-define(SQL_BRIDGE,
|
-define(SQL_BRIDGE,
|
||||||
"insert into mqtt_msg_test(topic, payload, arrived) "
|
"insert into mqtt_msg_test(topic, payload, arrived) "
|
||||||
|
|
|
@ -14,20 +14,20 @@
|
||||||
-include_lib("emqx/include/emqx.hrl").
|
-include_lib("emqx/include/emqx.hrl").
|
||||||
-include_lib("stdlib/include/assert.hrl").
|
-include_lib("stdlib/include/assert.hrl").
|
||||||
|
|
||||||
|
%% To run this test locally:
|
||||||
|
%% ./scripts/ct/run.sh --app apps/emqx_bridge_cassandra --only-up
|
||||||
|
%% PROFILE=emqx-enterprise PROXY_HOST=localhost CASSA_TLS_HOST=localhost \
|
||||||
|
%% CASSA_TLS_PORT=9142 CASSA_TCP_HOST=localhost CASSA_TCP_NO_AUTH_HOST=localhost \
|
||||||
|
%% CASSA_TCP_PORT=19042 CASSA_TCP_NO_AUTH_PORT=19043 \
|
||||||
|
%% ./rebar3 ct --name 'test@127.0.0.1' -v --suite \
|
||||||
|
%% apps/emqx_bridge_cassandra/test/emqx_bridge_cassandra_connector_SUITE
|
||||||
|
|
||||||
%% Cassandra servers are defined at `.ci/docker-compose-file/docker-compose-cassandra.yaml`
|
%% Cassandra servers are defined at `.ci/docker-compose-file/docker-compose-cassandra.yaml`
|
||||||
%% You can change it to `127.0.0.1`, if you run this SUITE locally
|
%% You can change it to `127.0.0.1`, if you run this SUITE locally
|
||||||
-define(CASSANDRA_HOST, "cassandra").
|
-define(CASSANDRA_HOST, "cassandra").
|
||||||
-define(CASSANDRA_HOST_NOAUTH, "cassandra_noauth").
|
-define(CASSANDRA_HOST_NOAUTH, "cassandra_noauth").
|
||||||
-define(CASSANDRA_RESOURCE_MOD, emqx_bridge_cassandra_connector).
|
-define(CASSANDRA_RESOURCE_MOD, emqx_bridge_cassandra_connector).
|
||||||
|
|
||||||
%% This test SUITE requires a running cassandra instance. If you don't want to
|
|
||||||
%% bring up the whole CI infrastuctucture with the `scripts/ct/run.sh` script
|
|
||||||
%% you can create a cassandra instance with the following command (execute it
|
|
||||||
%% from root of the EMQX directory.). You also need to set ?CASSANDRA_HOST and
|
|
||||||
%% ?CASSANDRA_PORT to appropriate values.
|
|
||||||
%%
|
|
||||||
%% sudo docker run --rm -d --name cassandra --network host cassandra:3.11.14
|
|
||||||
|
|
||||||
%% Cassandra default username & password once enable `authenticator: PasswordAuthenticator`
|
%% Cassandra default username & password once enable `authenticator: PasswordAuthenticator`
|
||||||
%% in cassandra config
|
%% in cassandra config
|
||||||
-define(CASSA_USERNAME, <<"cassandra">>).
|
-define(CASSA_USERNAME, <<"cassandra">>).
|
||||||
|
@ -45,14 +45,14 @@ groups() ->
|
||||||
{noauth, [t_lifecycle]}
|
{noauth, [t_lifecycle]}
|
||||||
].
|
].
|
||||||
|
|
||||||
cassandra_servers(CassandraHost) ->
|
cassandra_servers(CassandraHost, CassandraPort) ->
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(#{hostname := Host, port := Port}) ->
|
fun(#{hostname := Host, port := Port}) ->
|
||||||
{Host, Port}
|
{Host, Port}
|
||||||
end,
|
end,
|
||||||
emqx_schema:parse_servers(
|
emqx_schema:parse_servers(
|
||||||
iolist_to_binary([CassandraHost, ":", erlang:integer_to_list(?CASSANDRA_DEFAULT_PORT)]),
|
iolist_to_binary([CassandraHost, ":", erlang:integer_to_list(CassandraPort)]),
|
||||||
#{default_port => ?CASSANDRA_DEFAULT_PORT}
|
#{default_port => CassandraPort}
|
||||||
)
|
)
|
||||||
).
|
).
|
||||||
|
|
||||||
|
@ -63,25 +63,30 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
init_per_group(Group, Config) ->
|
init_per_group(Group, Config) ->
|
||||||
{CassandraHost, AuthOpts} =
|
{CassandraHost, CassandraPort, AuthOpts} =
|
||||||
case Group of
|
case Group of
|
||||||
auth ->
|
auth ->
|
||||||
{?CASSANDRA_HOST, [{username, ?CASSA_USERNAME}, {password, ?CASSA_PASSWORD}]};
|
TcpHost = os:getenv("CASSA_TCP_HOST", "toxiproxy"),
|
||||||
|
TcpPort = list_to_integer(os:getenv("CASSA_TCP_PORT", "9042")),
|
||||||
|
{TcpHost, TcpPort, [{username, ?CASSA_USERNAME}, {password, ?CASSA_PASSWORD}]};
|
||||||
noauth ->
|
noauth ->
|
||||||
{?CASSANDRA_HOST_NOAUTH, []}
|
TcpHost = os:getenv("CASSA_TCP_NO_AUTH_HOST", "toxiproxy"),
|
||||||
|
TcpPort = list_to_integer(os:getenv("CASSA_TCP_NO_AUTH_PORT", "9043")),
|
||||||
|
{TcpHost, TcpPort, []}
|
||||||
end,
|
end,
|
||||||
case emqx_common_test_helpers:is_tcp_server_available(CassandraHost, ?CASSANDRA_DEFAULT_PORT) of
|
case emqx_common_test_helpers:is_tcp_server_available(CassandraHost, CassandraPort) of
|
||||||
true ->
|
true ->
|
||||||
%% keyspace `mqtt` must be created in advance
|
%% keyspace `mqtt` must be created in advance
|
||||||
{ok, Conn} =
|
{ok, Conn} =
|
||||||
ecql:connect([
|
ecql:connect([
|
||||||
{nodes, cassandra_servers(CassandraHost)},
|
{nodes, cassandra_servers(CassandraHost, CassandraPort)},
|
||||||
{keyspace, "mqtt"}
|
{keyspace, "mqtt"}
|
||||||
| AuthOpts
|
| AuthOpts
|
||||||
]),
|
]),
|
||||||
ecql:close(Conn),
|
ecql:close(Conn),
|
||||||
[
|
[
|
||||||
{cassa_host, CassandraHost},
|
{cassa_host, CassandraHost},
|
||||||
|
{cassa_port, CassandraPort},
|
||||||
{cassa_auth_opts, AuthOpts}
|
{cassa_auth_opts, AuthOpts}
|
||||||
| Config
|
| Config
|
||||||
];
|
];
|
||||||
|
@ -212,6 +217,7 @@ create_local_resource(ResourceId, CheckedConfig) ->
|
||||||
|
|
||||||
cassandra_config(Config) ->
|
cassandra_config(Config) ->
|
||||||
Host = ?config(cassa_host, Config),
|
Host = ?config(cassa_host, Config),
|
||||||
|
Port = ?config(cassa_port, Config),
|
||||||
AuthOpts = maps:from_list(?config(cassa_auth_opts, Config)),
|
AuthOpts = maps:from_list(?config(cassa_auth_opts, Config)),
|
||||||
CassConfig =
|
CassConfig =
|
||||||
AuthOpts#{
|
AuthOpts#{
|
||||||
|
@ -223,7 +229,7 @@ cassandra_config(Config) ->
|
||||||
"~s:~b",
|
"~s:~b",
|
||||||
[
|
[
|
||||||
Host,
|
Host,
|
||||||
?CASSANDRA_DEFAULT_PORT
|
Port
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue