• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

emqx / pulsar-client-erl / 773

29 Nov 2024 08:57PM UTC coverage: 71.844% (-2.0%) from 73.807%
773

push

github

web-flow
Merge pull request #68 from thalesmg/fix-lookup-redirect-mkII

fix(client): handle `Redirect` in `LookupTopicResponse`

189 of 261 new or added lines in 8 files covered. (72.41%)

29 existing lines in 3 files now uncovered.

939 of 1307 relevant lines covered (71.84%)

313.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/src/pulsar_client_sup.erl
1
%% Copyright (c) 2013-2019 EMQ Technologies Co., Ltd. All Rights Reserved.
2
%%
3
%% Licensed under the Apache License, Version 2.0 (the "License");
4
%% you may not use this file except in compliance with the License.
5
%% You may obtain a copy of the License at
6
%%
7
%%     http://www.apache.org/licenses/LICENSE-2.0
8
%%
9
%% Unless required by applicable law or agreed to in writing, software
10
%% distributed under the License is distributed on an "AS IS" BASIS,
11
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
%% See the License for the specific language governing permissions and
13
%% limitations under the License.
14

15
-module(pulsar_client_sup).
16

17
%% @doc
18
%% pulsar_client_sup (1) (one_for_one)
19
%%  |
20
%%  +-- pulsar_client (1) (worker) (proxies calls and spawns new workers)
21
%%        |
22
%%        +-- pulsar_client (0..N)
23

24
-behaviour(supervisor).
25

26
-export([start_link/0, init/1]).
27

28
-export([ensure_present/3, ensure_absence/1]).
29

30
-define(SUPERVISOR, ?MODULE).
31

32
start_link() -> supervisor:start_link({local, ?SUPERVISOR}, ?MODULE, []).
20✔
33

34
init([]) ->
35
    SupFlags = #{strategy => one_for_one,
20✔
36
                 intensity => 10,
37
                 period => 5
38
               },
39
    Children = [], %% dynamically added/stopped
20✔
40
    {ok, {SupFlags, Children}}.
20✔
41

42
%% ensure a client started under supervisor
43
ensure_present(ClientId, Hosts, Opts) ->
44
    ChildSpec = child_spec(ClientId, Hosts, Opts),
23✔
45
    case supervisor:start_child(?SUPERVISOR, ChildSpec) of
23✔
46
        {ok, Pid} ->
47
            {ok, Pid};
20✔
48
        {error, {already_started, Pid}} ->
49
            {ok, Pid};
1✔
50
        {error, already_present} ->
NEW
51
            {error, client_not_running};
×
52
        {error, Reason} ->
53
            {error, map_start_error(Reason)}
2✔
54
    end.
55

56
%% ensure client stopped and deleted under supervisor
57
ensure_absence(ClientId) ->
58
    case supervisor:terminate_child(?SUPERVISOR, child_id(ClientId)) of
8✔
59
        ok -> ok = supervisor:delete_child(?SUPERVISOR, child_id(ClientId));
4✔
60
        {error, not_found} -> ok
4✔
61
    end.
62

63
child_id(ClientId) ->
64
    ClientId.
35✔
65

66
child_spec(ClientId, Servers, Opts) ->
67
    #{id => child_id(ClientId),
23✔
68
      start => {pulsar_client_manager, start_link, [ClientId, Servers, Opts]},
69
      restart => permanent,
70
      type => worker,
71
      shutdown => 5_000
72
    }.
73

74
map_start_error({{error, Reason}, _}) ->
75
    Reason;
2✔
76
map_start_error(Reason) ->
NEW
77
    Reason.
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc