From 6f4b22e376ac4620ea3c65f0495514f07008c25d Mon Sep 17 00:00:00 2001 From: firest Date: Sat, 6 Jan 2024 16:36:14 +0800 Subject: [PATCH] test(iotdb): add template test case for IoTDB --- .../src/emqx_bridge_iotdb.erl | 4 ++ .../src/emqx_bridge_iotdb_connector.erl | 2 + .../test/emqx_bridge_iotdb_impl_SUITE.erl | 57 +++++++++++++++++++ changes/feat-12261.en.md | 1 + rel/i18n/emqx_bridge_iotdb.hocon | 10 ++-- scripts/spellcheck/dicts/emqx.txt | 2 + 6 files changed, 70 insertions(+), 6 deletions(-) create mode 100644 changes/feat-12261.en.md diff --git a/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb.erl b/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb.erl index 4b509e908..34591332b 100644 --- a/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb.erl +++ b/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb.erl @@ -192,6 +192,10 @@ desc(action_parameters) -> ?DESC("action_parameters"); desc(action_parameters_data) -> ?DESC("action_parameters_data"); +desc(action_resource_opts) -> + "Action Resource Options"; +desc("creation_opts") -> + "Creation Options"; desc(auth_basic) -> "Basic Authentication"; desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" -> diff --git a/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb_connector.erl b/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb_connector.erl index 1b3cd4c38..5f6e31aaf 100644 --- a/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb_connector.erl +++ b/apps/emqx_bridge_iotdb/src/emqx_bridge_iotdb_connector.erl @@ -147,6 +147,8 @@ fields("get") -> desc(config) -> ?DESC("desc_config"); +desc(auth_basic) -> + "Basic Authentication"; desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" -> ["Configuration for IoTDB using `", string:to_upper(Method), "` method."]; desc(_) -> diff --git a/apps/emqx_bridge_iotdb/test/emqx_bridge_iotdb_impl_SUITE.erl b/apps/emqx_bridge_iotdb/test/emqx_bridge_iotdb_impl_SUITE.erl index 25349121a..6b9af7b9a 100644 --- a/apps/emqx_bridge_iotdb/test/emqx_bridge_iotdb_impl_SUITE.erl +++ b/apps/emqx_bridge_iotdb/test/emqx_bridge_iotdb_impl_SUITE.erl @@ -589,6 +589,63 @@ t_device_id(Config) -> iotdb_reset(Config, ConfiguredDevice), ok. +t_template(Config) -> + %% Create without data configured + ?assertMatch({ok, _}, emqx_bridge_v2_testlib:create_bridge(Config)), + ResourceId = emqx_bridge_v2_testlib:resource_id(Config), + BridgeId = emqx_bridge_v2_testlib:bridge_id(Config), + ?retry( + _Sleep = 1_000, + _Attempts = 20, + ?assertEqual({ok, connected}, emqx_resource_manager:health_check(ResourceId)) + ), + TemplateDeviceId = <<"root.deviceWithTemplate">>, + DeviceId = <<"root.deviceWithoutTemplate">>, + Topic = <<"some/random/topic">>, + iotdb_reset(Config, DeviceId), + iotdb_reset(Config, TemplateDeviceId), + Payload1 = make_iotdb_payload(DeviceId, "test", "BOOLEAN", true), + MessageF1 = make_message_fun(Topic, Payload1), + + is_success_check( + emqx_resource:simple_sync_query(ResourceId, {BridgeId, MessageF1()}) + ), + + {ok, {{_, 200, _}, _, Res1_1}} = iotdb_query(Config, <<"select * from ", DeviceId/binary>>), + ?assertMatch(#{<<"values">> := [[true]]}, emqx_utils_json:decode(Res1_1)), + + iotdb_reset(Config, DeviceId), + iotdb_reset(Config, TemplateDeviceId), + + %% reconfigure with data template + {ok, _} = + emqx_bridge_v2_testlib:update_bridge_api(Config, #{ + <<"parameters">> => #{ + <<"device_id">> => TemplateDeviceId, + <<"data">> => [ + #{ + <<"measurement">> => <<"${payload.measurement}">>, + <<"data_type">> => "TEXT", + <<"value">> => <<"${payload.device_id}">> + } + ] + } + }), + + is_success_check( + emqx_resource:simple_sync_query(ResourceId, {BridgeId, MessageF1()}) + ), + + {ok, {{_, 200, _}, _, Res2_2}} = iotdb_query( + Config, <<"select * from ", TemplateDeviceId/binary>> + ), + + ?assertMatch(#{<<"values">> := [[<>]]}, emqx_utils_json:decode(Res2_2)), + + iotdb_reset(Config, DeviceId), + iotdb_reset(Config, TemplateDeviceId), + ok. + is_empty(null) -> true; is_empty([]) -> true; is_empty([[]]) -> true; diff --git a/changes/feat-12261.en.md b/changes/feat-12261.en.md new file mode 100644 index 000000000..52949b5d2 --- /dev/null +++ b/changes/feat-12261.en.md @@ -0,0 +1 @@ +The bridges for IoTDB have been split so it is available via the connectors and actions APIs. They are still backwards compatible with the old bridge API. diff --git a/rel/i18n/emqx_bridge_iotdb.hocon b/rel/i18n/emqx_bridge_iotdb.hocon index 987006a53..c1841428a 100644 --- a/rel/i18n/emqx_bridge_iotdb.hocon +++ b/rel/i18n/emqx_bridge_iotdb.hocon @@ -72,13 +72,12 @@ desc_name.label: """Bridge Name""" config_parameters_timestamp.desc: -"""Timestamp. Placeholders in format of ${var} is supported, the finally value can be:
+"""Timestamp. Placeholders in format of ${var} is supported, the final value can be:
- now: use the `now_ms` which is contained in the payload as timestamp - now_ms: same as above - now_us: use the `now_us` which is contained in the payload as timestamp -- now_ns: use the `now_us` which is contained in the payload as timestamp -- any other: use the value directly as the timestamp -""" +- now_ns: use the `now_ns` which is contained in the payload as timestamp +- any other: use the value directly as the timestamp""" config_parameters_timestamp.label: """Timestamp""" @@ -96,8 +95,7 @@ config_parameters_data_type.desc: - INT32 - INT64 - FLOAT -- DOUBLE -""" +- DOUBLE""" config_parameters_data_type.label: """Data type""" diff --git a/scripts/spellcheck/dicts/emqx.txt b/scripts/spellcheck/dicts/emqx.txt index 9c1799a36..401df33a6 100644 --- a/scripts/spellcheck/dicts/emqx.txt +++ b/scripts/spellcheck/dicts/emqx.txt @@ -295,3 +295,5 @@ upstream priv Syskeeper msacc +now_us +ns