Skip to content

Commit

Permalink
Merge pull request #17 from antonmi/remove_broadcaster
Browse files Browse the repository at this point in the history
Remove Broadcaster. It can be done with a composer
  • Loading branch information
antonmi authored Apr 13, 2024
2 parents 806b3ba + 1f4d5a6 commit ec69de9
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 332 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ defmodule MySwitchModule do
end
```

### broadcaster

Broadcaster an IP to all the stages connected.

```elixir
[
broadcaster(:my_broadcast),
stage(:foo, count: 5)
]
```

### Goto

Send packet to a given `goto_point`
Expand Down
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
TODOs:
- Composer docs
- Broadcaster docs
Binary file modified images/ALF.key
Binary file not shown.
Binary file modified images/components.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 0 additions & 100 deletions lib/components/broadcaster.ex

This file was deleted.

14 changes: 9 additions & 5 deletions lib/components/goto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,16 @@ defmodule ALF.Components.Goto do

@impl true
def handle_call({:find_where_to_go, components}, _from, state) do
goto_point =
components
|> Enum.filter(&(&1.name == state.to and &1.__struct__ == GotoPoint))
|> Enum.random()
state =
case Enum.filter(components, &(&1.name == state.to and &1.__struct__ == GotoPoint)) do
[] ->
state

goto_points ->
goto_point = Enum.random(goto_points)
%{state | to_pid: goto_point.pid}
end

state = %{state | to_pid: goto_point.pid}
{:reply, state, [], state}
end

Expand Down
14 changes: 0 additions & 14 deletions lib/dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule ALF.DSL do
Basic,
Stage,
Switch,
Broadcaster,
DeadEnd,
GotoPoint,
Goto,
Expand Down Expand Up @@ -41,19 +40,6 @@ defmodule ALF.DSL do
end
end

defmacro broadcaster(name, options \\ []) do
count = options[:count] || 1

quote do
Broadcaster.validate_options(unquote(name), unquote(options))

broadcaster =
Basic.build_component(Broadcaster, unquote(name), unquote(count), %{}, __MODULE__)

%{broadcaster | count: unquote(count)}
end
end

defmacro goto(name, options \\ [opts: []]) do
to = options[:to]
opts = options[:opts] || []
Expand Down
38 changes: 1 addition & 37 deletions test/builder_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ALF.BuilderTest do
use ExUnit.Case, async: true

alias ALF.Builder
alias ALF.Components.{Stage, Switch, Broadcaster}
alias ALF.Components.{Stage, Switch}

setup do
sup_pid = Process.whereis(ALF.DynamicSupervisor)
Expand Down Expand Up @@ -38,16 +38,6 @@ defmodule ALF.BuilderTest do
end
end

defmodule PipelineWithBroadcaster do
def alf_components do
[
%Broadcaster{name: :broadcaster},
%Stage{name: :stage1, count: 2},
%Stage{name: :stage2}
]
end
end

describe "simple pipeline" do
test "build simple pipeline", %{sup_pid: sup_pid} do
{:ok, pipeline} = Builder.build(SimplePipeline, sup_pid, :pipeline)
Expand Down Expand Up @@ -95,18 +85,6 @@ defmodule ALF.BuilderTest do
end
end

describe "broadcaster" do
test "build pipeline with broadcaster", %{sup_pid: sup_pid} do
{:ok, pipeline} = Builder.build(PipelineWithBroadcaster, sup_pid, :pipeline)

[broadcaster, _stage11, _stage12, stage2] = pipeline.components

assert %Broadcaster{name: :broadcaster, pid: broadcaster_pid} = broadcaster
assert is_pid(broadcaster_pid)
assert %Stage{name: :stage2} = stage2
end
end

describe "build_sync" do
test "build with spec_simple_sync" do
[producer, stage, consumer] = Builder.build_sync(SimplePipeline, true)
Expand Down Expand Up @@ -141,19 +119,5 @@ defmodule ALF.BuilderTest do

assert consumer.subscribed_to == [{stage1.pid, :sync}, {stage2.pid, :sync}]
end

test "build with spec_with_broadcaster" do
[producer, broadcaster, stage1, stage2, consumer] =
Builder.build_sync(PipelineWithBroadcaster, true)

assert broadcaster.telemetry
assert broadcaster.subscribed_to == [{producer.pid, :sync}]

assert stage1.name == :stage1
assert stage1.pid
assert stage1.subscribed_to == [{broadcaster.pid, :sync}]

assert consumer.subscribed_to == [{stage2.pid, :sync}]
end
end
end
48 changes: 0 additions & 48 deletions test/components/broadcaster_test.exs

This file was deleted.

5 changes: 1 addition & 4 deletions test/dsl/dsl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule ALF.DSLTest do
alias ALF.Components.{
Stage,
Switch,
Broadcaster,
GotoPoint,
Goto,
Plug,
Expand All @@ -29,7 +28,6 @@ defmodule ALF.DSLTest do

@components [
goto_point(:goto_point),
broadcaster(:broadcaster),
stage(Mod1, count: 2),
switch(:cond_function,
branches: %{
Expand Down Expand Up @@ -82,10 +80,9 @@ defmodule ALF.DSLTest do
test "build PipelineB", %{sup_pid: sup_pid} do
{:ok, pipeline} = Builder.build(PipelineB, sup_pid, false)

[goto_point, broadcaster, _stage11, _stage12, switch, goto] = pipeline.components
[goto_point, _stage11, _stage12, switch, goto] = pipeline.components

assert %GotoPoint{name: :goto_point} = goto_point
assert %Broadcaster{name: :broadcaster} = broadcaster

assert %Switch{
name: :cond_function,
Expand Down
15 changes: 0 additions & 15 deletions test/dsl/validations_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,6 @@ defmodule ALF.DSL.ValidationsTest do
end
end

describe "Broadcaster" do
test "invalid options", %{sup_pid: sup_pid} do
assert_raise DSLError,
"Wrong options for the broadcaster broadcaster: [:foo]. " <>
"Available options are [:count]",
fn ->
defmodule BroadcasterWithWrongRequiredOpts do
use ALF.DSL

@components [broadcaster(:broadcaster, foo: :bar)]
end
end
end
end

describe "Goto" do
test "required options", %{sup_pid: sup_pid} do
assert_raise DSLError,
Expand Down
Loading

0 comments on commit ec69de9

Please sign in to comment.