-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delete publishers via web interface(#121)
* Add deleted publishers to cache when setup the system * Delete publisher notify to all nodes * Add missing tests * Refactor to functions * Fix method name * Refactor * Change method name * No send messages when publisher is deleted
- Loading branch information
Showing
12 changed files
with
249 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
defmodule Postoffice.CacheTest do | ||
use Postoffice.DataCase, async: true | ||
|
||
alias Postoffice.Cache | ||
alias Postoffice.Fixtures | ||
|
||
@deleted_publisher_attrs %{ | ||
active: false, | ||
target: "http://fake.target3", | ||
initial_message: 0, | ||
type: "http", | ||
deleted: true | ||
} | ||
|
||
@disabled_publisher_attrs %{ | ||
active: false, | ||
target: "http://fake.another.target", | ||
initial_message: 0, | ||
type: "http", | ||
deleted: false | ||
} | ||
|
||
@active_publisher_attrs %{ | ||
active: true, | ||
target: "http://fake.last.target3", | ||
initial_message: 0, | ||
type: "http", | ||
deleted: false | ||
} | ||
|
||
describe "cache" do | ||
test "initialize cache with publishers" do | ||
topic = Fixtures.create_topic() | ||
active_publisher = Fixtures.create_publisher(topic, @active_publisher_attrs) | ||
deleted_publisher = Fixtures.create_publisher(topic, @deleted_publisher_attrs) | ||
disabled_publisher = Fixtures.create_publisher(topic, @disabled_publisher_attrs) | ||
|
||
Cache.initialize() | ||
|
||
assert Cachex.get(:postoffice, active_publisher.id) == {:ok, nil} | ||
assert Cachex.get(:postoffice, disabled_publisher.id) == {:ok, :disabled} | ||
assert Cachex.get(:postoffice, deleted_publisher.id) == {:ok, :deleted} | ||
end | ||
|
||
test "add to cache disabled publisher" do | ||
topic = Fixtures.create_topic() | ||
disabled_publisher = Fixtures.create_publisher(topic, @disabled_publisher_attrs) | ||
|
||
Cache.publisher_updated(disabled_publisher) | ||
|
||
assert Cachex.get(:postoffice, disabled_publisher.id) == {:ok, :disabled} | ||
|
||
end | ||
|
||
test "Remove from cache when activate a disabled publisher" do | ||
topic = Fixtures.create_topic() | ||
active_publisher = Fixtures.create_publisher(topic, @active_publisher_attrs) | ||
Cachex.put(:postoffice, active_publisher.id, :disabled) | ||
|
||
Cache.publisher_updated(active_publisher) | ||
|
||
assert Cachex.get(:postoffice, active_publisher.id) == {:ok, nil} | ||
|
||
end | ||
|
||
test "add to cache deleted publisher" do | ||
topic = Fixtures.create_topic() | ||
deleted_publisher = Fixtures.create_publisher(topic, @deleted_publisher_attrs) | ||
|
||
Cache.publisher_deleted(deleted_publisher) | ||
|
||
assert Cachex.get(:postoffice, deleted_publisher.id) == {:ok, :deleted} | ||
end | ||
|
||
test "add to cache deleted when is deactivated first publisher" do | ||
topic = Fixtures.create_topic() | ||
deleted_publisher = Fixtures.create_publisher(topic, @deleted_publisher_attrs) | ||
Cachex.put(:postoffice, deleted_publisher.id, :disabled) | ||
|
||
Cache.publisher_deleted(deleted_publisher) | ||
|
||
assert Cachex.get(:postoffice, deleted_publisher.id) == {:ok, :deleted} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.