Browse Source

Use routing facility

undefined
Piotr Orzechowski 6 months ago
parent
commit
f1d1d9a3d5

+ 3
- 3
apps/kv_server/lib/kv_server/command.ex View File

@@ -48,14 +48,14 @@ defmodule KVServer.Command do
48 48
   def run(command, registry \\ KV.Registry)
49 49
 
50 50
   def run({:create, bucket}, registry) do
51
-    case KV.Registry.create(registry, bucket) do
51
+    case KV.Router.route(bucket, KV.Registry, :create, [registry, bucket]) do
52 52
       {:ok, _} -> {:ok, "OK\n"}
53 53
       :error -> {:error, :already_exists}
54 54
     end
55 55
   end
56 56
 
57 57
   def run({:delete, bucket}, registry) do
58
-    case KV.Registry.delete(registry, bucket) do
58
+    case KV.Router.route(bucket, KV.Registry, :delete, [registry, bucket]) do
59 59
       :ok -> {:ok, "OK\n"}
60 60
       :error -> {:error, :not_found}
61 61
     end
@@ -83,7 +83,7 @@ defmodule KVServer.Command do
83 83
   end
84 84
 
85 85
   defp lookup(bucket, registry, callback) do
86
-    case KV.Registry.lookup(registry, bucket) do
86
+    case KV.Router.route(bucket, KV.Registry, :lookup, [registry, bucket]) do
87 87
       {:ok, pid} -> callback.(pid)
88 88
       :error -> {:error, :not_found}
89 89
     end

+ 1
- 0
apps/kv_server/test/kv_server/command_test.exs View File

@@ -3,6 +3,7 @@ defmodule KVServer.CommandTest do
3 3
   doctest KVServer.Command
4 4
 
5 5
   setup context do
6
+    :ok = Application.put_env(:kv, :routing_table, [{?a..?z, node()}])
6 7
     _ = start_supervised!({KV.Registry, name: context.test})
7 8
     %{registry: context.test}
8 9
   end

Loading…
Cancel
Save