Skip to content

Commit

Permalink
[#52] Fix Sporadic :badarg error
Browse files Browse the repository at this point in the history
Overall enhancements
  • Loading branch information
cabol committed Feb 23, 2020
1 parent c3a3b8d commit c964e78
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ elixir:
- 1.9
- 1.8
otp_release:
- 22.1
- 22.2
- 21.3
- 20.3
sudo: false
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ useful and powerful features such as:
different [cache usage patterns][EHCache].

* Support for different distributed caching topologies, such as:
Partitioned, Near, Replicated, etc.
Replicated, Partitioned, Near, etc.

* Different eviction mechanisms, such as time-based eviction through the
expiry time property (`expire_at`) on the cached objects,
Expand Down Expand Up @@ -57,6 +57,7 @@ Cache | Nebulex Adapter | Dependency
:----------- | :----------------------------| :---------
Generational | Nebulex.Adapters.Local | Built-In
Partitioned | Nebulex.Adapters.Partitioned | Built-In
Replicated | Nebulex.Adapters.Replicated | Built-In
Multi-level | Nebulex.Adapters.Multilevel | Built-In
Redis | NebulexRedisAdapter | [nebulex_redis_adapter][nebulex_redis_adapter]
Memcached | NebulexMemcachedAdapter | [nebulex_memcached_adapter][nebulex_memcached_adapter]
Expand Down
7 changes: 6 additions & 1 deletion lib/nebulex/adapters/local/generation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ defmodule Nebulex.Adapters.Local.Generation do
end

def handle_call(:flush, _from, %State{cache: cache} = state) do
:ok = Enum.each(cache.__metadata__.generations, &Local.delete_all_objects/1)
:ok =
Enum.each(
cache.__metadata__.generations,
&Local.delete_all_objects(&1, cache.__state__)
)

{:reply, :ok, state}
end

Expand Down
8 changes: 2 additions & 6 deletions lib/nebulex/cache/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,8 @@ defmodule Nebulex.Cache.Supervisor do
Retrieves the compile time configuration.
"""
def compile_config(cache, opts) do
otp_app = Keyword.fetch!(opts, :otp_app)
adapter = Keyword.get(opts, :adapter)

unless adapter do
raise ArgumentError, "missing :adapter option on use Nebulex.Cache"
end
otp_app = opts[:otp_app] || raise ArgumentError, "expected otp_app: to be given as argument"
adapter = opts[:adapter] || raise ArgumentError, "expected adapter: to be given as argument"

unless Code.ensure_loaded?(adapter) do
raise ArgumentError,
Expand Down
3 changes: 1 addition & 2 deletions lib/nebulex/caching.ex
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ defmodule Nebulex.Caching do
## Private Functions

defp caching_action(action, fun, opts, block) do
cache =
Keyword.get(opts, :cache) || raise ArgumentError, "expected cache: to be given as argument"
cache = opts[:cache] || raise ArgumentError, "expected cache: to be given as argument"

{name, args} =
case Macro.decompose_call(fun) do
Expand Down
11 changes: 10 additions & 1 deletion test/nebulex/cache/supervisor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,20 @@ defmodule Nebulex.Cache.SupervisorTest do
end)
end

test "fail on compile_config because missing otp_app" do
opts = [:nebulex, n_shards: 2, adapter: TestAdapter]
:ok = Application.put_env(:nebulex, MyCache, opts)

assert_raise ArgumentError, "expected otp_app: to be given as argument", fn ->
Nebulex.Cache.Supervisor.compile_config(MyCache, opts)
end
end

test "fail on compile_config because missing adapter" do
opts = [otp_app: :nebulex, n_shards: 2]
:ok = Application.put_env(:nebulex, MyCache, opts)

assert_raise ArgumentError, "missing :adapter option on use Nebulex.Cache", fn ->
assert_raise ArgumentError, "expected adapter: to be given as argument", fn ->
Nebulex.Cache.Supervisor.compile_config(MyCache, opts)
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/support/test_cache.exs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ defmodule Nebulex.TestCache do
defmodule L3 do
use Nebulex.Cache,
otp_app: :nebulex,
adapter: Nebulex.Adapters.Local
adapter: Nebulex.Adapters.Local,
n_shards: 2
end

def fallback(_key) do
Expand Down

0 comments on commit c964e78

Please sign in to comment.