Problem: a bunch of different caches are under the Explorer.Chain namespaces, cluttering the codebase Solution: create a subdirectory and collect them all under the Explorer.Chain.Cache namespacepull/2323/head
parent
8bcb31912b
commit
da775b07b7
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.BlockCountCache do |
||||
defmodule Explorer.Chain.Cache.BlockCount do |
||||
@moduledoc """ |
||||
Cache for block count. |
||||
""" |
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.BlockNumberCache do |
||||
defmodule Explorer.Chain.Cache.BlockNumber do |
||||
@moduledoc """ |
||||
Cache for max and min block numbers. |
||||
""" |
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.BlocksCache do |
||||
defmodule Explorer.Chain.Cache.Blocks do |
||||
@moduledoc """ |
||||
Caches the last imported blocks |
||||
""" |
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.NetVersionCache do |
||||
defmodule Explorer.Chain.Cache.NetVersion do |
||||
@moduledoc """ |
||||
Caches chain version. |
||||
""" |
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.TransactionCountCache do |
||||
defmodule Explorer.Chain.Cache.TransactionCount do |
||||
@moduledoc """ |
||||
Cache for estimated transaction count. |
||||
""" |
@ -1,4 +1,4 @@ |
||||
defmodule Explorer.Chain.TransactionsCache do |
||||
defmodule Explorer.Chain.Cache.Transactions do |
||||
@moduledoc """ |
||||
Caches the latest imported transactions |
||||
""" |
@ -1,59 +0,0 @@ |
||||
defmodule Explorer.Chain.BlockNumberCacheTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Chain.BlockNumberCache |
||||
|
||||
setup do |
||||
Application.put_env(:explorer, Explorer.Chain.BlockNumberCache, enabled: true) |
||||
|
||||
on_exit(fn -> |
||||
Application.put_env(:explorer, Explorer.Chain.BlockNumberCache, enabled: false) |
||||
end) |
||||
end |
||||
|
||||
describe "max_number/1" do |
||||
test "returns max number" do |
||||
insert(:block, number: 5) |
||||
|
||||
BlockNumberCache.setup() |
||||
|
||||
assert BlockNumberCache.max_number() == 5 |
||||
end |
||||
end |
||||
|
||||
describe "min_number/1" do |
||||
test "returns max number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumberCache.setup() |
||||
|
||||
assert BlockNumberCache.max_number() == 2 |
||||
end |
||||
end |
||||
|
||||
describe "update/1" do |
||||
test "updates max number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumberCache.setup() |
||||
|
||||
assert BlockNumberCache.max_number() == 2 |
||||
|
||||
assert BlockNumberCache.update(3) |
||||
|
||||
assert BlockNumberCache.max_number() == 3 |
||||
end |
||||
|
||||
test "updates min number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumberCache.setup() |
||||
|
||||
assert BlockNumberCache.min_number() == 2 |
||||
|
||||
assert BlockNumberCache.update(1) |
||||
|
||||
assert BlockNumberCache.min_number() == 1 |
||||
end |
||||
end |
||||
end |
@ -1,55 +1,55 @@ |
||||
defmodule Explorer.Chain.BlockCountCacheTest do |
||||
defmodule Explorer.Chain.Cache.BlockCountTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Chain.BlockCountCache |
||||
alias Explorer.Chain.Cache.BlockCount |
||||
|
||||
test "returns default transaction count" do |
||||
BlockCountCache.start_link(name: BlockTestCache) |
||||
BlockCount.start_link(name: BlockTestCache) |
||||
|
||||
result = BlockCountCache.count(BlockTestCache) |
||||
result = BlockCount.count(BlockTestCache) |
||||
|
||||
assert is_nil(result) |
||||
end |
||||
|
||||
test "updates cache if initial value is zero" do |
||||
BlockCountCache.start_link(name: BlockTestCache) |
||||
BlockCount.start_link(name: BlockTestCache) |
||||
|
||||
insert(:block, consensus: true) |
||||
insert(:block, consensus: true) |
||||
insert(:block, consensus: false) |
||||
|
||||
_result = BlockCountCache.count(BlockTestCache) |
||||
_result = BlockCount.count(BlockTestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = BlockCountCache.count(BlockTestCache) |
||||
updated_value = BlockCount.count(BlockTestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
||||
|
||||
test "does not update cache if cache period did not pass" do |
||||
BlockCountCache.start_link(name: BlockTestCache) |
||||
BlockCount.start_link(name: BlockTestCache) |
||||
|
||||
insert(:block, consensus: true) |
||||
insert(:block, consensus: true) |
||||
insert(:block, consensus: false) |
||||
|
||||
_result = BlockCountCache.count(BlockTestCache) |
||||
_result = BlockCount.count(BlockTestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = BlockCountCache.count(BlockTestCache) |
||||
updated_value = BlockCount.count(BlockTestCache) |
||||
|
||||
assert updated_value == 2 |
||||
|
||||
insert(:block, consensus: true) |
||||
insert(:block, consensus: true) |
||||
|
||||
_updated_value = BlockCountCache.count(BlockTestCache) |
||||
_updated_value = BlockCount.count(BlockTestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = BlockCountCache.count(BlockTestCache) |
||||
updated_value = BlockCount.count(BlockTestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
@ -0,0 +1,59 @@ |
||||
defmodule Explorer.Chain.Cache.BlockNumberTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Chain.Cache.BlockNumber |
||||
|
||||
setup do |
||||
Application.put_env(:explorer, Explorer.Chain.Cache.BlockNumber, enabled: true) |
||||
|
||||
on_exit(fn -> |
||||
Application.put_env(:explorer, Explorer.Chain.Cache.BlockNumber, enabled: false) |
||||
end) |
||||
end |
||||
|
||||
describe "max_number/1" do |
||||
test "returns max number" do |
||||
insert(:block, number: 5) |
||||
|
||||
BlockNumber.setup() |
||||
|
||||
assert BlockNumber.max_number() == 5 |
||||
end |
||||
end |
||||
|
||||
describe "min_number/1" do |
||||
test "returns max number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumber.setup() |
||||
|
||||
assert BlockNumber.max_number() == 2 |
||||
end |
||||
end |
||||
|
||||
describe "update/1" do |
||||
test "updates max number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumber.setup() |
||||
|
||||
assert BlockNumber.max_number() == 2 |
||||
|
||||
assert BlockNumber.update(3) |
||||
|
||||
assert BlockNumber.max_number() == 3 |
||||
end |
||||
|
||||
test "updates min number" do |
||||
insert(:block, number: 2) |
||||
|
||||
BlockNumber.setup() |
||||
|
||||
assert BlockNumber.min_number() == 2 |
||||
|
||||
assert BlockNumber.update(1) |
||||
|
||||
assert BlockNumber.min_number() == 1 |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,54 @@ |
||||
defmodule Explorer.Chain.Cache.TransactionCountTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Chain.Cache.TransactionCount |
||||
|
||||
test "returns default transaction count" do |
||||
TransactionCount.start_link([[], [name: TestCache]]) |
||||
|
||||
result = TransactionCount.value(TestCache) |
||||
|
||||
assert is_nil(result) |
||||
end |
||||
|
||||
test "updates cache if initial value is zero" do |
||||
TransactionCount.start_link([[], [name: TestCache]]) |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_result = TransactionCount.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCount.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
||||
|
||||
test "does not update cache if cache period did not pass" do |
||||
TransactionCount.start_link([[], [name: TestCache]]) |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_result = TransactionCount.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCount.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_updated_value = TransactionCount.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCount.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
||||
end |
@ -1,54 +0,0 @@ |
||||
defmodule Explorer.Chain.TransactionCountCacheTest do |
||||
use Explorer.DataCase |
||||
|
||||
alias Explorer.Chain.TransactionCountCache |
||||
|
||||
test "returns default transaction count" do |
||||
TransactionCountCache.start_link([[], [name: TestCache]]) |
||||
|
||||
result = TransactionCountCache.value(TestCache) |
||||
|
||||
assert is_nil(result) |
||||
end |
||||
|
||||
test "updates cache if initial value is zero" do |
||||
TransactionCountCache.start_link([[], [name: TestCache]]) |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_result = TransactionCountCache.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCountCache.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
||||
|
||||
test "does not update cache if cache period did not pass" do |
||||
TransactionCountCache.start_link([[], [name: TestCache]]) |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_result = TransactionCountCache.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCountCache.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
|
||||
insert(:transaction) |
||||
insert(:transaction) |
||||
|
||||
_updated_value = TransactionCountCache.value(TestCache) |
||||
|
||||
Process.sleep(1000) |
||||
|
||||
updated_value = TransactionCountCache.value(TestCache) |
||||
|
||||
assert updated_value == 2 |
||||
end |
||||
end |
Loading…
Reference in new issue