Browse Source

Fix code formatting

Piotr Orzechowski 1 month ago
parent
commit
a9c1a60690

+ 2
- 0
apps/kv/lib/kv/registry.ex View File

@@ -62,6 +62,7 @@ defmodule KV.Registry do
62 62
     case lookup(names, name) do
63 63
       {:ok, _} ->
64 64
         {:reply, :error, state}
65
+
65 66
       :error ->
66 67
         {:ok, bucket} = DynamicSupervisor.start_child(KV.BucketSupervisor, KV.Bucket)
67 68
         ref = Process.monitor(bucket)
@@ -80,6 +81,7 @@ defmodule KV.Registry do
80 81
       {:ok, bucket} ->
81 82
         _ = DynamicSupervisor.terminate_child(KV.BucketSupervisor, bucket)
82 83
         {:reply, :ok, state}
84
+
83 85
       :error ->
84 86
         {:reply, :error, state}
85 87
     end

+ 7
- 6
apps/kv/lib/kv/router.ex View File

@@ -8,22 +8,23 @@ defmodule KV.Router do
8 8
     first = :binary.first(bucket)
9 9
 
10 10
     # Try to find and entry in the table() or raise
11
-    entry = Enum.find(table(), fn {enum, _node} ->
12
-      first in enum
13
-    end) || no_entry_error(bucket)
11
+    entry =
12
+      Enum.find(table(), fn {enum, _node} ->
13
+        first in enum
14
+      end) || no_entry_error(bucket)
14 15
 
15 16
     # If the entry node is the current node
16 17
     if elem(entry, 1) == node() do
17 18
       apply(mod, fun, args)
18 19
     else
19 20
       {KV.RouterTasks, elem(entry, 1)}
20
-        |> Task.Supervisor.async(KV.Router, :route, [bucket, mod, fun, args])
21
-        |> Task.await()
21
+      |> Task.Supervisor.async(KV.Router, :route, [bucket, mod, fun, args])
22
+      |> Task.await()
22 23
     end
23 24
   end
24 25
 
25 26
   defp no_entry_error(bucket) do
26
-    raise "could not find entry for #{inspect bucket} in table #{inspect table()}"
27
+    raise "could not find entry for #{inspect(bucket)} in table #{inspect(table())}"
27 28
   end
28 29
 
29 30
   @doc """

+ 1
- 1
apps/kv/test/kv/registry_test.exs View File

@@ -58,6 +58,6 @@ defmodule KV.RegistryTest do
58 58
     Agent.stop(bucket, :shutdown)
59 59
 
60 60
     # Now trying to call the dead process causes a :noproc exit
61
-    catch_exit KV.Bucket.put(bucket, "mleko", 3)
61
+    catch_exit(KV.Bucket.put(bucket, "mleko", 3))
62 62
   end
63 63
 end

+ 1
- 1
apps/kv/test/test_helper.exs View File

@@ -1,3 +1,3 @@
1
-exclude = if Node.alive?, do: [], else: [distributed: true]
1
+exclude = if Node.alive?(), do: [], else: [distributed: true]
2 2
 
3 3
 ExUnit.start(exclude: exclude)

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

@@ -25,7 +25,9 @@ defmodule KVServer do
25 25
     # 2. `packet: :line` - receives data line by line
26 26
     # 3. `active: false` - blocks on `:gen_tcp.recv/2` until data is available
27 27
     # 4. `reuseaddr: true` - allows us to reuse the address if the listener crashes
28
-    {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true])
28
+    {:ok, socket} =
29
+      :gen_tcp.listen(port, [:binary, packet: :line, active: false, reuseaddr: true])
30
+
29 31
     Logger.info("Accepting connections on port #{port}")
30 32
     loop_acceptor(socket)
31 33
   end

+ 7
- 7
apps/kv_server/test/kv_server/command_test.exs View File

@@ -12,13 +12,13 @@ defmodule KVServer.CommandTest do
12 12
   end
13 13
 
14 14
   test "parses commands" do
15
-      assert KVServer.Command.parse("CREATE zakupy") == {:ok, {:create, "zakupy"}}
16
-      assert KVServer.Command.parse("DELETE zakupy") == {:ok, {:delete, "zakupy"}}
17
-      assert KVServer.Command.parse("PUT zakupy mleko 1") == {:ok, {:put, "zakupy", "mleko", "1"}}
18
-      assert KVServer.Command.parse("GET zakupy mleko") == {:ok, {:get, "zakupy", "mleko"}}
19
-      assert KVServer.Command.parse("DELETE zakupy mleko") == {:ok, {:delete, "zakupy", "mleko"}}
20
-      assert KVServer.Command.parse("UNKNOWN command") == {:error, :unknown_command}
21
-      assert KVServer.Command.parse("CREATE zakupy mleko") == {:error, :unknown_command}
15
+    assert KVServer.Command.parse("CREATE zakupy") == {:ok, {:create, "zakupy"}}
16
+    assert KVServer.Command.parse("DELETE zakupy") == {:ok, {:delete, "zakupy"}}
17
+    assert KVServer.Command.parse("PUT zakupy mleko 1") == {:ok, {:put, "zakupy", "mleko", "1"}}
18
+    assert KVServer.Command.parse("GET zakupy mleko") == {:ok, {:get, "zakupy", "mleko"}}
19
+    assert KVServer.Command.parse("DELETE zakupy mleko") == {:ok, {:delete, "zakupy", "mleko"}}
20
+    assert KVServer.Command.parse("UNKNOWN command") == {:error, :unknown_command}
21
+    assert KVServer.Command.parse("CREATE zakupy mleko") == {:error, :unknown_command}
22 22
   end
23 23
 
24 24
   test "creates and deletes buckets", %{registry: registry} do

Loading…
Cancel
Save