Skip to content

Commit

Permalink
* test.
Browse files Browse the repository at this point in the history
Signed-off-by: Hermann0222 <yukang.wei@emqx.io>
  • Loading branch information
OdyWayne committed Aug 29, 2023
1 parent 2376b8c commit e0ae520
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
19 changes: 10 additions & 9 deletions nanomq/tests/bridge_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
int
main()
{
char *cmd_sub_emqx[] = {"mosquitto_sub", "-h", "broker.emqx.io", "-p", "1883", "-t", "forward1/test", "-V", "mqttv5", NULL};
char *cmd_sub_nmq[] = {"mosquitto_sub", "-h", "127.0.0.1", "-p", "1881", "-t", "recv/topic1", "-V", "mqttv5", NULL};
char *cmd_sub_emqx[] = {"mosquitto_sub", "-h", "broker.emqx.io", "-p", "1883", "-t", "forward1/test", "-V", "mqttv5", "-q", "2", NULL};
char *cmd_sub_nmq[] = {"mosquitto_sub", "-h", "127.0.0.1", "-p", "1881", "-t", "recv/test", "-V", "mqttv5", "-q", "2", NULL};

char *cmd_pub_nmq = "mosquitto_pub -h 127.0.0.1 -p 1881 -t forward1/test -m message-to-emqx -V mqttv5";
char *cmd_pub_emqx = "mosquitto_pub -h broker.emqx.io -p 1883 -t recv/topic1 -m message-to-nmq -V mqttv5";
char *cmd_pub_nmq = "mosquitto_pub -h 127.0.0.1 -p 1881 -t forward1/test -m message-to-emqx -V mqttv5 -q 2";
char *cmd_pub_emqx = "mosquitto_pub -h broker.emqx.io -p 1883 -t recv/test -m message-to-nmq -V mqttv5 -q 2";

nng_thread *nmq;
pid_t pid_sub_nmq;
Expand All @@ -28,23 +28,24 @@ main()
conf = get_test_conf(BRIDGE_CONF);
assert(conf != NULL);
nng_thread_create(&nmq, (void *) broker_start_with_conf, (void *) conf);
nng_msleep(2000); // wait a while before sub
nng_msleep(1000); // wait a while before sub
printf("going to sub\n");

pid_sub_nmq = popen_sub_with_cmd(&outfp_nmq, cmd_sub_nmq);
pid_sub_emqx = popen_sub_with_cmd(&outfp_emqx, cmd_sub_emqx);
nng_msleep(4000);
nng_msleep(2000);
printf("going to pub\n");
p_pub_emqx = popen(cmd_pub_emqx, "r");
p_pub_nmq= popen(cmd_pub_nmq, "r");
nng_msleep(2000);
// check recv msg
printf("check recv msgs\n");
assert(read(outfp_nmq, buf_nmq, buf_size) != -1);
printf("get the msg in nmq:%s\n", buf_nmq);
assert(strncmp(buf_nmq, "message-to-nmq", 14) == 0);
assert(read(outfp_emqx, buf_emqx, buf_size) != -1);
printf("get the msg in emqx:%s\n", buf_emqx);
assert(strncmp(buf_emqx, "message-to-emqx", 15) == 0);
assert(read(outfp_nmq, buf_nmq, buf_size) != -1);
printf("get the msg in nmq:%s\n", buf_nmq);
assert(strncmp(buf_nmq, "message-to-nmq", 14) == 0);

kill(pid_sub_nmq, SIGKILL);
kill(pid_sub_emqx, SIGKILL);
Expand Down
14 changes: 3 additions & 11 deletions nanomq/tests/nanomq_bridge_test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ http_server {

log {
to = [file, console]
level = warn
level = debug
dir = "/tmp"
file = "nanomq.log"
rotation {
Expand Down Expand Up @@ -91,19 +91,11 @@ bridges.mqtt.emqx {
forwards = ["forward1/test","forward2/test"]
subscription = [
{
topic = "recv/topic1"
topic = "recv/test"
qos = 1
},
{
topic = "recv/topic2"
qos = 2
},
{
topic = "cmd/topic1"
qos = 1
},
{
topic = "cmd/topic2"
topic = "cmd/test"
qos = 2
}
]
Expand Down

0 comments on commit e0ae520

Please sign in to comment.