-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathcache_manager_test.exs
58 lines (43 loc) · 1.68 KB
/
cache_manager_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2017-2023, Matteo Cafasso.
# All rights reserved.
defmodule RabbitMQMessageDeduplication.CacheManager.Test do
use ExUnit.Case
alias :timer, as: Timer
alias :mnesia, as: Mnesia
alias RabbitMQMessageDeduplication.Cache, as: Cache
alias RabbitMQMessageDeduplication.CacheManager, as: CacheManager
@caches :message_deduplication_caches
setup do
start_supervised!(%{id: :cache_manager,
start: {CacheManager,
:start_link,
[]}})
%{}
end
test "cache creation", %{} do
options = [persistence: :memory]
CacheManager.create(:cache, true, options)
{:atomic, [:cache]} = Mnesia.transaction(fn -> Mnesia.all_keys(@caches) end)
CacheManager.destroy(:cache)
end
test "cache deletion", %{} do
options = [persistence: :memory]
:ok = CacheManager.create(:cache, false, options)
{:atomic, [:cache]} = Mnesia.transaction(fn -> Mnesia.all_keys(@caches) end)
:ok = CacheManager.destroy(:cache)
{:atomic, []} = Mnesia.transaction(fn -> Mnesia.all_keys(@caches) end)
end
test "cache cleanup routine", %{} do
options = [persistence: :memory]
:ok = CacheManager.create(:cache, true, options)
{:ok, :inserted} = Cache.insert(:cache, "foo", 1000)
Timer.sleep(3200)
{:atomic, []} = Mnesia.transaction(fn -> Mnesia.all_keys(:cache) end)
{:ok, :inserted} = Cache.insert(:cache, "foo")
:ok = CacheManager.destroy(:cache)
end
end