Sfoglia il codice sorgente

chore(router): drop test-only `has_routes/1`

Seems that it's too much support work only for test purposes, where
`lookup_routes/1` is nearly as usable.
Andrew Mayorov 2 anni fa
parent
commit
e85789306b

+ 1 - 22
apps/emqx/src/emqx_router.erl

@@ -50,7 +50,7 @@
 -export([
     match_routes/1,
     lookup_routes/1,
-    has_routes/1
+    has_route/2
 ]).
 
 -export([print_routes/1]).
@@ -222,27 +222,6 @@ lookup_routes_regular(Topic) ->
 match_to_route(M) ->
     #route{topic = emqx_topic_index:get_topic(M), dest = emqx_topic_index:get_id(M)}.
 
--spec has_routes(emqx_types:topic()) -> boolean().
-has_routes(Topic) when is_binary(Topic) ->
-    case is_unified_table_active() of
-        true ->
-            has_routes_unified(Topic);
-        false ->
-            has_routes_regular(Topic)
-    end.
-
-has_routes_unified(Topic) ->
-    Pat = #routeidx{entry = emqx_topic_index:mk_key(Topic, '$1'), _ = '_'},
-    case ets:match(?ROUTE_TAB_UNIFIED, Pat, 1) of
-        {[_], _} ->
-            true;
-        _ ->
-            false
-    end.
-
-has_routes_regular(Topic) ->
-    ets:member(?ROUTE_TAB, Topic).
-
 -spec has_route(emqx_types:topic(), dest()) -> boolean().
 has_route(Topic, Dest) ->
     case is_unified_table_active() of

+ 1 - 1
apps/emqx/test/emqx_quic_multistreams_SUITE.erl

@@ -1094,7 +1094,7 @@ t_multi_streams_unsub(Config) ->
     ?retry(
         _Sleep2 = 100,
         _Attempts2 = 50,
-        false = emqx_router:has_routes(Topic)
+        [] = emqx_router:lookup_routes(Topic)
     ),
 
     case emqtt:publish_via(C, PubVia, Topic, #{}, <<6, 7, 8, 9>>, [{qos, PubQos}]) of

+ 2 - 2
apps/emqx/test/emqx_router_SUITE.erl

@@ -176,9 +176,9 @@ t_print_routes(_) ->
     ?R:add_route(<<"+/+">>),
     ?R:print_routes(<<"a/b">>).
 
-t_has_routes(_) ->
+t_has_route(_) ->
     ?R:add_route(<<"devices/+/messages">>, node()),
-    ?assert(?R:has_routes(<<"devices/+/messages">>)),
+    ?assert(?R:has_route(<<"devices/+/messages">>, node())),
     ?R:delete_route(<<"devices/+/messages">>).
 
 t_unexpected(_) ->

+ 2 - 2
apps/emqx/test/emqx_shared_sub_SUITE.erl

@@ -1054,7 +1054,7 @@ t_queue_subscription(Config) when is_list(Config) ->
         begin
             ct:pal("routes: ~p", [ets:tab2list(emqx_route)]),
             %% FIXME: should ensure we have 2 subscriptions
-            true = emqx_router:has_routes(Topic)
+            [_] = emqx_router:lookup_routes(Topic)
         end
     ),
 
@@ -1081,7 +1081,7 @@ t_queue_subscription(Config) when is_list(Config) ->
     %%     _Attempts0 = 50,
     %%    begin
     %%     ct:pal("routes: ~p", [ets:tab2list(emqx_route)]),
-    %%     false = emqx_router:has_routes(Topic)
+    %%     [] = emqx_router:lookup_routes(Topic)
     %%    end
     %%   ),
     ct:sleep(500),

+ 1 - 1
apps/emqx_bridge_kafka/test/emqx_bridge_kafka_impl_consumer_SUITE.erl

@@ -1928,7 +1928,7 @@ t_node_joins_existing_cluster(Config) ->
             ?retry(
                 _Sleep2 = 100,
                 _Attempts2 = 50,
-                true = erpc:call(N2, emqx_router, has_routes, [MQTTTopic])
+                [] =/= erpc:call(N2, emqx_router, lookup_routes, [MQTTTopic])
             ),
             {ok, SRef1} =
                 snabbkaffe:subscribe(