From 8f0b13ec33df520d05fd8d44616bd4d6a8b84652 Mon Sep 17 00:00:00 2001 From: Mustafa Turan Date: Mon, 28 May 2018 00:16:41 -0700 Subject: [PATCH] Log empty topic listeners to prevent unnecessary ets inserts Add missing tests for existence check --- CHANGELOG.md | 3 ++- lib/event_bus/services/notification.ex | 11 ++++++++--- test/event_bus/managers/observation_test.exs | 7 +++++++ test/event_bus/managers/store_test.exs | 7 +++++++ test/event_bus/managers/topic_test.exs | 7 +++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be80cbe..3e134db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/event_bus/services/notification.ex b/lib/event_bus/services/notification.ex index 62a4fa0..326d73a 100644 --- a/lib/event_bus/services/notification.ex +++ b/lib/event_bus/services/notification.ex @@ -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() diff --git a/test/event_bus/managers/observation_test.exs b/test/event_bus/managers/observation_test.exs index 3757b9a..6da1e78 100644 --- a/test/event_bus/managers/observation_test.exs +++ b/test/event_bus/managers/observation_test.exs @@ -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 diff --git a/test/event_bus/managers/store_test.exs b/test/event_bus/managers/store_test.exs index a831ace..29cfa20 100644 --- a/test/event_bus/managers/store_test.exs +++ b/test/event_bus/managers/store_test.exs @@ -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 diff --git a/test/event_bus/managers/topic_test.exs b/test/event_bus/managers/topic_test.exs index ea27ef6..f7b25ac 100644 --- a/test/event_bus/managers/topic_test.exs +++ b/test/event_bus/managers/topic_test.exs @@ -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