--- /dev/null
+{
+ "coverage_options": {
+ "minimum_coverage": 76.1
+ }
+}
defmodule Wampex.Realm do
- @moduledoc false
+ @moduledoc "Defines the WAMP Realm"
defstruct [:name, :authentication]
defmodule Wampex.Role do
+ @moduledoc "Behaviour for Roles"
@callback add(map()) :: map()
@callback handle(message :: Wampex.message(), data :: StatesLanguage.t()) ::
{StatesLanguage.t(), [:gen_statem.action()], integer() | nil,
[@call, %{}, procedure]
end
- def call(procedure, opts) do
- [@call, opts, procedure]
+ def call(procedure, arg_l) do
+ [@call, %{}, procedure, arg_l]
end
- def call(procedure, args_l, opts) do
- [@call, opts, procedure, args_l]
- end
-
- def call(procedure, args_l, args_kw, opts) do
- [@call, opts, procedure, args_l, args_kw]
+ def call(procedure, arg_l, arg_kw) do
+ [@call, %{}, procedure, arg_l, arg_kw]
end
@impl true
[@publish, %{}, topic]
end
- def publish(topic, opts) do
- [@publish, opts, topic]
+ def publish(topic, arg_l) do
+ [@publish, %{}, topic, arg_l]
end
- def publish(topic, args_l, opts) do
- [@publish, opts, topic, args_l]
- end
-
- def publish(topic, args_l, args_kw, opts) do
- [@publish, opts, topic, args_l, args_kw]
+ def publish(topic, arg_l, arg_kw) do
+ [@publish, %{}, topic, arg_l, arg_kw]
end
@impl true
Map.put(roles, :subscriber, %{})
end
- def subscribe(topic, opts \\ %{}) when is_binary(topic) and is_map(opts) do
- [@subscribe, opts, topic]
+ def subscribe(topic) do
+ [@subscribe, %{}, topic]
end
def unsubscribe(sub_id) do
defmodule Wampex.Serializer do
+ @moduledoc "Behaviour for Serializers"
@type data_type :: :binary | :text
@callback data_type() :: data_type()
@callback serialize!(data :: Wampex.message()) :: binary()
defmodule Wampex.Serializer.JSON do
+ @moduledoc "JSON Serializer"
@behaviour Wampex.Serializer
@impl true
defmodule Wampex.Serializer.MessagePack do
+ @moduledoc "MessgePack Serializer"
@behaviour Wampex.Serializer
@impl true
defmodule Wampex.Session do
+ @moduledoc """
+ A state machine based process for managing a WAMP Session. Utilizes StatesLanguage to implement the gen_statem process. See priv/session.json for the JSON representation
+ """
use StatesLanguage, data: "priv/session.json"
@max_id 9_007_199_254_740_992
request_id
end
- defp get_request_id(current_id) when current_id == @max_id do
+ def get_request_id(current_id) when current_id == @max_id do
1
end
- defp get_request_id(current_id) do
+ def get_request_id(current_id) do
current_id + 1
end
sub = Wampex.subscriber_registry_name(name)
Registry.dispatch(sub, elem(event, 1), fn entries ->
- for {pid, topic} <- entries, do: send(pid, event)
+ for {pid, _topic} <- entries, do: send(pid, event)
end)
{:ok, sl, [{:next_event, :internal, :transition}]}
reg = Wampex.callee_registry_name(name)
Registry.dispatch(reg, elem(invocation, 2), fn entries ->
- for {pid, procedure} <- entries, do: send(pid, invocation)
+ for {pid, _procedure} <- entries, do: send(pid, invocation)
end)
{:ok, sl, [{:next_event, :internal, :transition}]}
defmodule Wampex.Transport do
+ @moduledoc "Behaviour for Transports"
@callback send_request(atom() | pid(), Wampex.message()) :: :ok
@callback start_link(
url: binary(),
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
elixirc_paths: elixirc_paths(Mix.env()),
- deps: deps()
+ aliases: aliases(),
+ deps: deps(),
+ preferred_cli_env: [
+ coveralls: :test,
+ "coveralls.detail": :test,
+ "coveralls.post": :test,
+ "coveralls.html": :test,
+ all_tests: :test
+ ],
+ test_coverage: [tool: ExCoveralls]
]
end
defp deps do
[
+ {:excoveralls, "~> 0.12.2", only: [:dev, :test], runtime: false},
+ {:credo, "~> 1.2", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 0.5.1", only: [:dev, :test], runtime: false},
{:jason, "~> 1.1"},
{:msgpack, "~> 0.7.0"},
{:websockex, "~> 0.4"}
]
end
+
+ defp aliases do
+ [
+ all_tests: [
+ "compile --force --warnings-as-errors",
+ "credo --strict",
+ "format --check-formatted",
+ "coveralls",
+ "dialyzer --halt-exit-status"
+ ]
+ ]
+ end
end
%{
+ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
+ "certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "805abd97539caf89ec6d4732c91e62ba9da0cda51ac462380bbd28ee697a8c42"},
"conv_case": {:hex, :conv_case, "0.2.2", "5a98b74ab8f7ddbad670e5c7bb39ff280e60699aa3b25c7062ceccf48137433c", [:mix], [], "hexpm", "561c550ab6d55b2a4d4c14449e58c9957798613eb26ea182e14a962965377bca"},
+ "coveralls": {:hex, :coveralls, "2.1.0", "b44cea21202c0e1994dfced8cedbff66bcd03eeeb565484345b28afacda0559b", [:rebar3], [{:jsx, "2.10.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm", "bbfbe2a7bebb2d22db15a657e6c1733243e1501714d60fe14a14790d96e7c3b2"},
+ "credo": {:hex, :credo, "1.2.2", "f57faf60e0a12b0ba9fd4bad07966057fde162b33496c509b95b027993494aab", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8f2623cd8c895a6f4a55ef10f3fdf6a55a9ca7bef09676bd835551687bf8a740"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm", "6c32a70ed5d452c6650916555b1f96c79af5fc4bf286997f8b15f213de786f73"},
"elixpath": {:hex, :elixpath, "0.1.0", "f860e931db7bda6856dc68145694ca429643cc068ef30d7ff6b4096d4357963e", [:mix], [{:nimble_parsec, "~> 0.5", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "30ce06079b41f1f5216ea2cd11605cfe4c82239628555cb3fde9f10055a6eb67"},
+ "excoveralls": {:hex, :excoveralls, "0.12.2", "a513defac45c59e310ac42fcf2b8ae96f1f85746410f30b1ff2b710a4b6cd44b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "151c476331d49b45601ffc45f43cb3a8beb396b02a34e3777fea0ad34ae57d89"},
+ "hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm", "e0100f8ef7d1124222c11ad362c857d3df7cb5f4204054f9f0f4a728666591fc"},
+ "idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm", "4bdd305eb64e18b0273864920695cb18d7a2021f31a11b9c5fbcd9a253f936e2"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fdf843bca858203ae1de16da2ee206f53416bbda5dc8c9e78f43243de4bc3afe"},
"json_xema": {:hex, :json_xema, "0.4.0", "377446cd5c0e2cbba52b9d7ab67c05579e6d4a788335220215a8870eac821996", [:mix], [{:conv_case, "~> 0.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:xema, "~> 0.11", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "452724a5b2751cd69191edd3fd3da0c2194c164ebd49efd85f9abb64d6621b53"},
+ "jsx": {:hex, :jsx, "2.10.0", "77760560d6ac2b8c51fd4c980e9e19b784016aa70be354ce746472c33beb0b1c", [:rebar3], [], "hexpm", "9a83e3704807298016968db506f9fad0f027de37546eb838b3ae1064c3a0ad62"},
+ "metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
+ "mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm", "f278585650aa581986264638ebf698f8bb19df297f66ad91b18910dfc6e19323"},
"msgpack": {:hex, :msgpack, "0.7.0", "128ae0a2227c7e7a2847c0f0f73551c268464f8c1ee96bffb920bc0a5712b295", [:rebar3], [], "hexpm", "4649353da003e6f438d105e4b1e0f17757f6f5ec8687a6f30875ff3ac4ce2a51"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.3", "def21c10a9ed70ce22754fdeea0810dafd53c2db3219a0cd54cf5526377af1c6", [:mix], [], "hexpm", "589b5af56f4afca65217a1f3eb3fee7e79b09c40c742fddc1c312b3ac0b3399f"},
+ "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
+ "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm", "13104d7897e38ed7f044c4de953a6c28597d1c952075eb2e328bc6d6f2bfc496"},
"states_language": {:hex, :states_language, "0.2.8", "f9dfd3c0bd9a9d7bda25ef315f2d90944cd6b2022a7f3c403deb1d4ec451825e", [:mix], [{:elixpath, "~> 0.1.0", [hex: :elixpath, repo: "hexpm", optional: false]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: false]}, {:json_xema, "~> 0.4.0", [hex: :json_xema, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:xema, "~> 0.11.0", [hex: :xema, repo: "hexpm", optional: false]}], "hexpm", "a5231691e7cb37fe32dc7de54c2dc86d1d60e84c4f0379f3246e55be2a85ec78"},
"telemetry": {:hex, :telemetry, "0.4.1", "ae2718484892448a24470e6aa341bc847c3277bfb8d4e9289f7474d752c09c7f", [:rebar3], [], "hexpm", "4738382e36a0a9a2b6e25d67c960e40e1a2c95560b9f936d8e29de8cd858480f"},
+ "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm", "1d1848c40487cdb0b30e8ed975e34e025860c02e419cb615d255849f3427439d"},
"websockex": {:hex, :websockex, "0.4.2", "9a3b7dc25655517ecd3f8ff7109a77fce94956096b942836cdcfbc7c86603ecc", [:mix], [], "hexpm", "803cd76e91544b56f0e655e36790be797fa6436db9224f7c303db9b9df2a3df4"},
"xema": {:hex, :xema, "0.11.0", "7b5118418633cffc27092110d02d4faeea938149dd3f6c64299e41e747067e80", [:mix], [{:conv_case, "~> 0.2.2", [hex: :conv_case, repo: "hexpm", optional: false]}, {:decimal, "~> 1.7", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "51491c9a953d65069d4b30aa2f70bc45ff99fd1bc3345bc72ce4e644d01ea14e"},
}
defmodule TestCallee do
+ @moduledoc false
use GenServer
require Logger
alias Wampex.Role.Callee
defmodule TestSubscriber do
+ @moduledoc false
use GenServer
require Logger
alias Wampex.Role.Subscriber
doctest Wampex
alias Wampex.{Realm, Session}
- alias Wampex.Role.{Callee, Caller, Publisher, Subscriber}
+ alias Wampex.Role.{Callee, Caller, Peer, Publisher, Subscriber}
require Logger
@url "ws://localhost:18080/ws"
@session Session.new(@url, @realm, @roles)
+ test "session_name" do
+ assert Test.Session = Wampex.session_name(Test)
+ end
+
+ test "subscriber_registry_name" do
+ assert Test.SubscriberRegistry = Wampex.subscriber_registry_name(Test)
+ end
+
+ test "callee_registry_name" do
+ assert Test.CalleeRegistry = Wampex.callee_registry_name(Test)
+ end
+
+ test "transport_name" do
+ assert Test.Transport = Wampex.transport_name(Test)
+ end
+
+ test "get_request_id plus one" do
+ assert 11 = Wampex.Session.get_request_id(10)
+ end
+
+ test "get_request_id resets" do
+ assert 1 = Wampex.Session.get_request_id(9_007_199_254_740_992)
+ end
+
+ test "Callee.add" do
+ assert %{callee: %{}} = Callee.add(%{})
+ end
+
+ test "Callee.register" do
+ assert [64, %{}, "test"] = Callee.register("test")
+ end
+
+ test "Callee.unregister" do
+ assert [66, 123_456] = Callee.unregister(123_456)
+ end
+
+ test "Callee.yield" do
+ assert [70, 1234, %{}] = Callee.yield(1234)
+ assert [70, 1234, %{}, []] = Callee.yield(1234, [])
+ assert [70, 1234, %{}, [], %{}] = Callee.yield(1234, [], %{})
+ end
+
+ test "Caller.add" do
+ assert %{caller: %{}} = Caller.add(%{})
+ end
+
+ test "Caller.call" do
+ assert [48, %{}, "test"] = Caller.call("test")
+ assert [48, %{}, "test", []] = Caller.call("test", [])
+ assert [48, %{}, "test", [], %{}] = Caller.call("test", [], %{})
+ end
+
+ test "Peer.add" do
+ assert %{} = Caller.add(%{})
+ end
+
+ test "Peer.hello" do
+ assert [1, "test", %{roles: %{callee: %{}}}] = Peer.hello("test", [Callee])
+ end
+
+ test "Peer.gooodbye" do
+ assert [6, %{}, "test"] = Peer.goodbye("test")
+ end
+
+ test "Publisher.add" do
+ assert %{publisher: %{}} = Publisher.add(%{})
+ end
+
+ test "Publisher.publish" do
+ assert [16, %{}, "test"] = Publisher.publish("test")
+ assert [16, %{}, "test", []] = Publisher.publish("test", [])
+ assert [16, %{}, "test", [], %{}] = Publisher.publish("test", [], %{})
+ end
+
+ test "Subscriber.add" do
+ assert %{subscriber: %{}} = Subscriber.add(%{})
+ end
+
+ test "Subscriber.subscribe" do
+ assert [32, %{}, "test"] = Subscriber.subscribe("test")
+ end
+
+ test "Subscriber.unsubscribe" do
+ assert [34, 1234] = Subscriber.unsubscribe(1234)
+ end
+
test "callee registration" do
name = TestCalleeRegistration
Wampex.start_link(name, @session)
{:ok, ["ok"], %{"color" => "#FFFFFF"}} =
Wampex.send_request(
caller_name,
- Caller.call("com.actuator.#{@device}.light", [1], %{color: "#FFFFFF"}, %{})
+ Caller.call("com.actuator.#{@device}.light", [1], %{color: "#FFFFFF"})
)
assert_receive {:invocation, _, _, _, _, _}
Wampex.cast_send_request(
TestPublisher,
- Publisher.publish("com.data.temp", [12.5, 45.6, 87.5], %{loc: "60645"}, %{})
+ Publisher.publish("com.data.temp", [12.5, 45.6, 87.5], %{loc: "60645"})
)
assert_receive {:event, _, _, _, _, _}