Explorar el Código

Use routing facility

master
Piotr Orzechowski hace 6 meses
padre
commit
1cc265f1e3

+ 3
- 3
apps/kv_server/lib/kv_server/command.ex Ver fichero

@@ -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

+ 4
- 0
apps/kv_server/test/kv_server/command_test.exs Ver fichero

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

Loading…
Cancelar
Guardar