test(emqx_bridge_cassandra): add connector test case for Cassandra configured without authentication
This commit is contained in:
parent
f0c75d97e1
commit
607705518b
|
@ -1,4 +0,0 @@
|
|||
ARG CASSANDRA_TAG=3.11.6
|
||||
FROM cassandra:${CASSANDRA_TAG}
|
||||
COPY cassandra.yaml /etc/cassandra/cassandra.yaml
|
||||
CMD ["cassandra", "-f"]
|
File diff suppressed because it is too large
Load Diff
|
@ -1,32 +1,38 @@
|
|||
version: '3.9'
|
||||
|
||||
x-cassandra: &cassandra
|
||||
restart: always
|
||||
image: cassandra:${CASSANDRA_TAG:-3.11.6}
|
||||
environment:
|
||||
CASSANDRA_BROADCAST_ADDRESS: "1.2.3.4"
|
||||
CASSANDRA_RPC_ADDRESS: "0.0.0.0"
|
||||
HEAP_NEWSIZE: "128M"
|
||||
MAX_HEAP_SIZE: "2048M"
|
||||
#ports:
|
||||
# - "9042:9042"
|
||||
# - "9142:9142"
|
||||
command:
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |
|
||||
/opt/cassandra/bin/cassandra -f -R > /cassandra.log &
|
||||
/opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "CREATE KEYSPACE mqtt WITH REPLICATION = { 'class':'SimpleStrategy','replication_factor':1};"
|
||||
while [[ $$? -ne 0 ]];do sleep 5; /opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "CREATE KEYSPACE mqtt WITH REPLICATION = { 'class':'SimpleStrategy','replication_factor':1};"; done
|
||||
/opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "describe keyspaces;"
|
||||
tail -f /cassandra.log
|
||||
networks:
|
||||
- emqx_bridge
|
||||
|
||||
services:
|
||||
cassandra_server:
|
||||
<<: *cassandra
|
||||
container_name: cassandra
|
||||
build:
|
||||
context: ./cassandra
|
||||
args:
|
||||
CASSANDRA_TAG: ${CASSANDRA_TAG}
|
||||
image: emqx-cassandra
|
||||
restart: always
|
||||
environment:
|
||||
CASSANDRA_BROADCAST_ADDRESS: "1.2.3.4"
|
||||
CASSANDRA_RPC_ADDRESS: "0.0.0.0"
|
||||
HEAP_NEWSIZE: "128M"
|
||||
MAX_HEAP_SIZE: "2048M"
|
||||
volumes:
|
||||
- ./certs:/certs
|
||||
#ports:
|
||||
# - "9042:9042"
|
||||
# - "9142:9142"
|
||||
command:
|
||||
- /bin/bash
|
||||
- -c
|
||||
- |
|
||||
/opt/cassandra/bin/cassandra -f -R > /cassandra.log &
|
||||
/opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "CREATE KEYSPACE mqtt WITH REPLICATION = { 'class':'SimpleStrategy','replication_factor':1};"
|
||||
while [[ $$? -ne 0 ]];do sleep 5; /opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "CREATE KEYSPACE mqtt WITH REPLICATION = { 'class':'SimpleStrategy','replication_factor':1};"; done
|
||||
/opt/cassandra/bin/cqlsh -u cassandra -p cassandra -e "describe keyspaces;"
|
||||
tail -f /cassandra.log
|
||||
networks:
|
||||
- emqx_bridge
|
||||
- ./cassandra/cassandra.yaml:/etc/cassandra/cassandra.yaml
|
||||
cassandra_noauth_server:
|
||||
<<: *cassandra
|
||||
container_name: cassandra_noauth
|
||||
volumes:
|
||||
- ./certs:/certs
|
||||
- ./cassandra/cassandra_noauth.yaml:/etc/cassandra/cassandra.yaml
|
||||
|
|
|
@ -7,15 +7,17 @@
|
|||
-compile(nowarn_export_all).
|
||||
-compile(export_all).
|
||||
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
-include("emqx_bridge_cassandra.hrl").
|
||||
-include("emqx_connector/include/emqx_connector.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("emqx/include/emqx.hrl").
|
||||
-include_lib("stdlib/include/assert.hrl").
|
||||
|
||||
%% Cassandra server defined at `.ci/docker-compose-file/docker-compose-cassandra-tcp.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
|
||||
-define(CASSANDRA_HOST, "cassandra").
|
||||
-define(CASSANDRA_HOST_NOAUTH, "cassandra_noauth").
|
||||
-define(CASSANDRA_RESOURCE_MOD, emqx_bridge_cassandra_connector).
|
||||
|
||||
%% This test SUITE requires a running cassandra instance. If you don't want to
|
||||
|
@ -32,40 +34,58 @@
|
|||
-define(CASSA_PASSWORD, <<"cassandra">>).
|
||||
|
||||
all() ->
|
||||
emqx_common_test_helpers:all(?MODULE).
|
||||
[
|
||||
{group, auth},
|
||||
{group, noauth}
|
||||
].
|
||||
|
||||
groups() ->
|
||||
[].
|
||||
TCs = emqx_common_test_helpers:all(?MODULE),
|
||||
[
|
||||
{auth, TCs},
|
||||
{noauth, TCs}
|
||||
].
|
||||
|
||||
cassandra_servers() ->
|
||||
cassandra_servers(CassandraHost) ->
|
||||
lists:map(
|
||||
fun(#{hostname := Host, port := Port}) ->
|
||||
{Host, Port}
|
||||
end,
|
||||
emqx_schema:parse_servers(
|
||||
iolist_to_binary([?CASSANDRA_HOST, ":", erlang:integer_to_list(?CASSANDRA_DEFAULT_PORT)]),
|
||||
iolist_to_binary([CassandraHost, ":", erlang:integer_to_list(?CASSANDRA_DEFAULT_PORT)]),
|
||||
#{default_port => ?CASSANDRA_DEFAULT_PORT}
|
||||
)
|
||||
).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
case
|
||||
emqx_common_test_helpers:is_tcp_server_available(?CASSANDRA_HOST, ?CASSANDRA_DEFAULT_PORT)
|
||||
of
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_conf]),
|
||||
ok = emqx_connector_test_helpers:start_apps([emqx_resource]),
|
||||
{ok, _} = application:ensure_all_started(emqx_connector),
|
||||
Config.
|
||||
|
||||
init_per_group(Group, Config) ->
|
||||
{CassandraHost, AuthOpts} =
|
||||
case Group of
|
||||
auth ->
|
||||
{?CASSANDRA_HOST, [{username, ?CASSA_USERNAME}, {password, ?CASSA_PASSWORD}]};
|
||||
noauth ->
|
||||
{?CASSANDRA_HOST_NOAUTH, []}
|
||||
end,
|
||||
case emqx_common_test_helpers:is_tcp_server_available(CassandraHost, ?CASSANDRA_DEFAULT_PORT) of
|
||||
true ->
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_conf]),
|
||||
ok = emqx_connector_test_helpers:start_apps([emqx_resource]),
|
||||
{ok, _} = application:ensure_all_started(emqx_connector),
|
||||
%% keyspace `mqtt` must be created in advance
|
||||
{ok, Conn} =
|
||||
ecql:connect([
|
||||
{nodes, cassandra_servers()},
|
||||
{username, ?CASSA_USERNAME},
|
||||
{password, ?CASSA_PASSWORD},
|
||||
{nodes, cassandra_servers(CassandraHost)},
|
||||
{keyspace, "mqtt"}
|
||||
| AuthOpts
|
||||
]),
|
||||
ecql:close(Conn),
|
||||
Config;
|
||||
[
|
||||
{cassa_host, CassandraHost},
|
||||
{cassa_auth_opts, AuthOpts}
|
||||
| Config
|
||||
];
|
||||
false ->
|
||||
case os:getenv("IS_CI") of
|
||||
"yes" ->
|
||||
|
@ -75,6 +95,9 @@ init_per_suite(Config) ->
|
|||
end
|
||||
end.
|
||||
|
||||
end_per_group(_Group, _Config) ->
|
||||
ok.
|
||||
|
||||
end_per_suite(_Config) ->
|
||||
ok = emqx_common_test_helpers:stop_apps([emqx_conf]),
|
||||
ok = emqx_connector_test_helpers:stop_apps([emqx_resource]),
|
||||
|
@ -90,10 +113,10 @@ end_per_testcase(_, _Config) ->
|
|||
%% cases
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
t_lifecycle(_Config) ->
|
||||
t_lifecycle(Config) ->
|
||||
perform_lifecycle_check(
|
||||
<<"emqx_connector_cassandra_SUITE">>,
|
||||
cassandra_config()
|
||||
cassandra_config(Config)
|
||||
).
|
||||
|
||||
show(X) ->
|
||||
|
@ -168,25 +191,25 @@ perform_lifecycle_check(ResourceId, InitialConfig) ->
|
|||
%% utils
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
cassandra_config() ->
|
||||
Config =
|
||||
#{
|
||||
cassandra_config(Config) ->
|
||||
Host = ?config(cassa_host, Config),
|
||||
AuthOpts = maps:from_list(?config(cassa_auth_opts, Config)),
|
||||
CassConfig =
|
||||
AuthOpts#{
|
||||
auto_reconnect => true,
|
||||
keyspace => <<"mqtt">>,
|
||||
username => ?CASSA_USERNAME,
|
||||
password => ?CASSA_PASSWORD,
|
||||
pool_size => 8,
|
||||
servers => iolist_to_binary(
|
||||
io_lib:format(
|
||||
"~s:~b",
|
||||
[
|
||||
?CASSANDRA_HOST,
|
||||
Host,
|
||||
?CASSANDRA_DEFAULT_PORT
|
||||
]
|
||||
)
|
||||
)
|
||||
},
|
||||
#{<<"config">> => Config}.
|
||||
#{<<"config">> => CassConfig}.
|
||||
|
||||
test_query_no_params() ->
|
||||
{query, <<"SELECT count(1) AS T FROM system.local">>}.
|
||||
|
|
Loading…
Reference in New Issue