Skip to content

Commit

Permalink
Merge pull request #28 from otobus/mustafaturan/empty_topic_listeners
Browse files Browse the repository at this point in the history
Log empty topic listeners to prevent unnecessary ETS inserts
  • Loading branch information
Mustafa TURAN authored May 28, 2018
2 parents b6e3ed1 + 8f0b13e commit 6ae1c3e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [1.3.X]


- Log empty topic listeners
- Add missing tests for existence check
- Update time spent calculation for EventSource block
- Remove support for system event tracing (Updated the wiki to create wrapper for system event tracing)

Expand Down
11 changes: 8 additions & 3 deletions lib/event_bus/services/notification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ defmodule EventBus.Service.Notification do
@spec notify(Event.t()) :: no_return()
def notify(%Event{id: id, topic: topic} = event) do
listeners = Subscription.subscribers(topic)
:ok = Store.create(event)
:ok = Observation.create({listeners, topic, id})

notify_listeners(listeners, {topic, id})
if listeners == [] do
Logger.log(@logging_level, "Topic :#{topic} listener set is empty!")
else
:ok = Store.create(event)
:ok = Observation.create({listeners, topic, id})

notify_listeners(listeners, {topic, id})
end
end

@spec notify_listeners(list(), tuple()) :: no_return()
Expand Down
7 changes: 7 additions & 0 deletions test/event_bus/managers/observation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ defmodule EventBus.Manager.ObservationTest do
:ok
end

test "exist?" do
topic = :metrics_received_1
Observation.register_topic(topic)

assert Observation.exist?(topic)
end

test "register_topic" do
assert :ok == Observation.register_topic(:metrics_destroyed)
end
Expand Down
7 changes: 7 additions & 0 deletions test/event_bus/managers/store_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ defmodule EventBus.Manager.StoreTest do
:ok
end

test "exist?" do
topic = :metrics_received_1
Store.register_topic(topic)

assert Store.exist?(topic)
end

test "register_topic" do
assert :ok == Store.register_topic(@topic)
end
Expand Down
7 changes: 7 additions & 0 deletions test/event_bus/managers/topic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ defmodule EventBus.Manager.TopicTest do
:ok
end

test "exist?" do
topic = :metrics_received_1
Topic.register(topic)

assert Topic.exist?(topic)
end

test "register_topic" do
assert :ok == Topic.register(:t1)
end
Expand Down

0 comments on commit 6ae1c3e

Please sign in to comment.