Просмотр исходного кода

fix(emqx_connector): fix resource status

EMQ-YangM 4 лет назад
Родитель
Сommit
e54f4b75da

+ 1 - 1
apps/emqx_connector/README.md

@@ -21,7 +21,7 @@ An MySQL connector can be used as following:
          ssl => false,user => "root",verify => false},
    id => <<"mysql-abc">>,mod => emqx_connector_mysql,
    state => #{poolname => 'mysql-abc'},
-   status => started}]
+   status => connected}]
 (emqx@127.0.0.1)6> emqx_resource:query(<<"mysql-abc">>, {sql, <<"SELECT count(1)">>}).
 {ok,[<<"count(1)">>],[[1]]}
 ```

+ 1 - 1
apps/emqx_connector/test/emqx_connector_api_SUITE.erl

@@ -695,7 +695,7 @@ wait_for_resource_ready(InstId, 0) ->
     ct:fail(wait_resource_timeout);
 wait_for_resource_ready(InstId, Retry) ->
     case emqx_bridge:lookup(InstId) of
-        {ok, #{resource_data := #{status := started}}} -> ok;
+        {ok, #{resource_data := #{status := connected}}} -> ok;
         _ ->
             timer:sleep(100),
             wait_for_resource_ready(InstId, Retry-1)

+ 2 - 2
apps/emqx_connector/test/emqx_connector_mysql_SUITE.erl

@@ -70,7 +70,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
         ?MYSQL_RESOURCE_MOD,
         CheckedConfig
     ),
-    ?assertEqual(InitialStatus, started),
+    ?assertEqual(InitialStatus, connected),
     % Instance should match the state and status of the just started resource
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := InitialStatus}} = emqx_resource:get_instance(PoolName),
     ?assertEqual(ok, emqx_resource:health_check(PoolName)),
@@ -82,7 +82,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
     % Resource will be listed still, but state will be changed and healthcheck will fail
     % as the worker no longer exists.
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := StoppedStatus}} = emqx_resource:get_instance(PoolName),
-    ?assertEqual(StoppedStatus, stopped),
+    ?assertEqual(StoppedStatus, disconnected),
     ?assertEqual({error,health_check_failed}, emqx_resource:health_check(PoolName)),
     % Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
     ?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),

+ 2 - 2
apps/emqx_connector/test/emqx_connector_pgsql_SUITE.erl

@@ -70,7 +70,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
         ?PGSQL_RESOURCE_MOD,
         CheckedConfig
     ),
-    ?assertEqual(InitialStatus, started),
+    ?assertEqual(InitialStatus, connected),
     % Instance should match the state and status of the just started resource
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := InitialStatus}} = emqx_resource:get_instance(PoolName),
     ?assertEqual(ok, emqx_resource:health_check(PoolName)),
@@ -81,7 +81,7 @@ perform_lifecycle_check(PoolName, InitialConfig) ->
     % Resource will be listed still, but state will be changed and healthcheck will fail
     % as the worker no longer exists.
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := StoppedStatus}} = emqx_resource:get_instance(PoolName),
-    ?assertEqual(StoppedStatus, stopped),
+    ?assertEqual(StoppedStatus, disconnected),
     ?assertEqual({error,health_check_failed}, emqx_resource:health_check(PoolName)),
     % Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
     ?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),

+ 2 - 2
apps/emqx_connector/test/emqx_connector_redis_SUITE.erl

@@ -85,7 +85,7 @@ perform_lifecycle_check(PoolName, InitialConfig, RedisCommand) ->
         ?REDIS_RESOURCE_MOD,
         CheckedConfig
     ),
-    ?assertEqual(InitialStatus, started),
+    ?assertEqual(InitialStatus, connected),
     % Instance should match the state and status of the just started resource
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := InitialStatus}} = emqx_resource:get_instance(PoolName),
     ?assertEqual(ok, emqx_resource:health_check(PoolName)),
@@ -95,7 +95,7 @@ perform_lifecycle_check(PoolName, InitialConfig, RedisCommand) ->
     % Resource will be listed still, but state will be changed and healthcheck will fail
     % as the worker no longer exists.
     {ok, ?CONNECTOR_RESOURCE_GROUP, #{state := State, status := StoppedStatus}} = emqx_resource:get_instance(PoolName),
-    ?assertEqual(StoppedStatus, stopped),
+    ?assertEqual(StoppedStatus, disconnected),
     ?assertEqual({error,health_check_failed}, emqx_resource:health_check(PoolName)),
     % Resource healthcheck shortcuts things by checking ets. Go deeper by checking pool itself.
     ?assertEqual({error, not_found}, ecpool:stop_sup_pool(ReturnedPoolName)),