-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
198 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
- Proper supervision tree!!! | ||
- Module behaviour | ||
- flow and rename in dsl | ||
- tick source with timeout | ||
- tick source with timeout | ||
- remove chunk_by, introduce buffer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
defmodule Strom.Rename do | ||
use GenServer | ||
|
||
defstruct names: nil, pid: nil | ||
|
||
def start(names) do | ||
state = %__MODULE__{names: names} | ||
|
||
{:ok, pid} = GenServer.start_link(__MODULE__, state) | ||
__state__(pid) | ||
end | ||
|
||
@impl true | ||
def init(%__MODULE__{} = state), do: {:ok, %{state | pid: self()}} | ||
|
||
def call(flow, %__MODULE__{}, names) when is_map(names) do | ||
Enum.reduce(names, flow, fn {name, new_name}, acc -> | ||
acc | ||
|> Map.put(new_name, Map.fetch!(acc, name)) | ||
|> Map.delete(name) | ||
end) | ||
end | ||
|
||
def stop(%__MODULE__{pid: pid}), do: GenServer.call(pid, :stop) | ||
|
||
def __state__(pid) when is_pid(pid), do: GenServer.call(pid, :__state__) | ||
|
||
@impl true | ||
def handle_call(:stop, _from, state) do | ||
{:stop, :normal, :ok, state} | ||
end | ||
|
||
def handle_call(:__state__, _from, state), do: {:reply, state, state} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Strom.RenameTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Strom.Rename | ||
|
||
test "start and stop" do | ||
rename = Rename.start(%{s1: :s2}) | ||
assert Process.alive?(rename.pid) | ||
:ok = Rename.stop(rename) | ||
refute Process.alive?(rename.pid) | ||
end | ||
|
||
test "rename" do | ||
names = %{s1: :foo1, s2: :foo2} | ||
rename = Rename.start(names) | ||
|
||
flow = %{s1: [1], s2: [2], s3: [3]} | ||
|
||
new_flow = Rename.call(flow, rename, names) | ||
|
||
refute new_flow[:s1] | ||
refute new_flow[:s2] | ||
|
||
assert Enum.to_list(new_flow[:foo1]) == [1] | ||
assert Enum.to_list(new_flow[:foo2]) == [2] | ||
assert Enum.to_list(new_flow[:s3]) == [3] | ||
end | ||
|
||
test "raise when there is no such name" do | ||
names = %{s2: :foo2} | ||
rename = Rename.start(names) | ||
flow = %{s1: [1]} | ||
|
||
assert_raise KeyError, fn -> | ||
Rename.call(flow, rename, names) | ||
end | ||
end | ||
end |