alias Wampex.Client.Session, as: Sess
alias Wampex.Roles.{Callee, Subscriber}
+ alias Wampex.Roles.Callee.Yield
alias Wampex.Roles.Callee.Register
+ alias Wampex.Roles.Caller
+ alias Wampex.Roles.Caller.Call
+ alias Wampex.Roles.Dealer.Result
+ alias Wampex.Roles.Peer.Error
+ alias Wampex.Roles.Publisher
+ alias Wampex.Roles.Publisher.Publish
alias Wampex.Roles.Subscriber.Subscribe
@spec start_link(name: atom(), session_data: Sess.t()) ::
{:ok, id}
end
- @spec send_request(name :: module(), request :: Wampex.message(), timeout :: integer()) ::
+ @spec yield(name :: module(), yield :: Yield.t()) :: :ok
+ def yield(name, yield) do
+ cast(name, Callee.yield(yield))
+ end
+
+ @spec call(name :: module(), call :: Call.t(), timeout :: integer) :: Result.t() | Error.t()
+ def call(name, call, timeout \\ 5000) do
+ sync(name, Caller.call(call), timeout)
+ end
+
+ @spec publish(name :: module, event :: Publish.t()) :: :ok
+ def publish(name, event) do
+ cast(name, Publisher.publish(event))
+ end
+
+ @spec sync(name :: module(), request :: Wampex.message(), timeout :: integer()) ::
term()
- def send_request(name, request, timeout \\ 5000) do
+ def sync(name, request, timeout \\ 5000) do
Sess.send_request(session_name(name), request, timeout)
end
- @spec cast_send_request(name :: module(), Wampex.message()) :: :ok
- def cast_send_request(name, request) do
+ @spec cast(name :: module(), Wampex.message()) :: :ok
+ def cast(name, request) do
Sess.cast_send_request(session_name(name), request)
end
end
{:states_language, "~> 0.2"},
{:wampex,
git: "https://gitlab.com/entropealabs/wampex.git",
- tag: "92648dd6f1a4a9ed24b10eec3533d29108b31852"},
+ tag: "591a03f9ed1585942afc043fe4a73beb7641e1e3"},
{:websockex, "~> 0.4.2"}
]
end
"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"},
- "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "92648dd6f1a4a9ed24b10eec3533d29108b31852", [tag: "92648dd6f1a4a9ed24b10eec3533d29108b31852"]},
+ "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "591a03f9ed1585942afc043fe4a73beb7641e1e3", [tag: "591a03f9ed1585942afc043fe4a73beb7641e1e3"]},
"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"},
}
end
def handle_info(
- %Invocation{request_id: id, details: dets, arg_kw: arg_kw} = invocation,
+ %Invocation{request_id: id, details: %{"procedure" => proc}, arg_kw: arg_kw} = invocation,
{test, name, _reg} = state
) do
- Logger.info("Got invocation #{inspect(dets)}")
+ Logger.info("Got invocation #{proc}")
send(test, invocation)
- Client.cast_send_request(
+ Client.yield(
name,
- Callee.yield(%Yield{
+ %Yield{
request_id: id,
arg_list: [:ok],
arg_kw: %{color: Map.get(arg_kw, "color")}
- })
+ }
)
{:noreply, state}
require Logger
alias Wampex.Client
alias Wampex.Roles.Subscriber
- alias Subscriber.{Subscribe, Unsubscribe}
+ alias Subscriber.Subscribe
def start_link(test, name, topic) do
GenServer.start_link(__MODULE__, {test, name, topic})
send(test, event)
{:noreply, state}
end
-
- def terminate(_r, {_test, name, subs}) do
- Enum.each(subs, fn sub ->
- Client.send_request(
- name,
- Subscriber.unsubscribe(%Unsubscribe{subscription_id: sub})
- )
- end)
-
- :ok
- end
end
alias Wampex.Roles.{Callee, Caller, Peer, Publisher, Subscriber}
alias Wampex.Roles.Caller.Call
alias Wampex.Roles.Dealer.{Invocation, Result}
- alias Wampex.Roles.Peer.Hello
+ alias Wampex.Roles.Peer.{Error, Hello}
alias Wampex.Roles.Publisher.Publish
require Logger
@url "ws://localhost:4000/ws"
@authid "admin"
- @auth_password "bnASR5qF9y8k/sHF6S+NneCOhvVI0zFkvoKQpc2F+hA="
+ @auth_password "test1234"
@realm_uri "admin"
@auth %Authentication{authid: @authid, authmethods: ["wampcra"], secret: @auth_password}
@realm %Realm{name: @realm_uri, authentication: @auth}
Process.flag(:trap_exit, true)
callee_name = TestAbort
{:ok, pid} = Client.start_link(name: callee_name, session: @session)
- Client.cast_send_request(callee_name, Peer.hello(%Hello{realm: "test", roles: [Callee]}))
+ Client.cast(callee_name, Peer.hello(%Hello{realm: "test", roles: [Callee]}))
assert_receive {:EXIT, ^pid, :shutdown}, 1000
end
caller_name = TestExistCaller
Client.start_link(name: caller_name, session: @session)
- assert {:error, 48, "wamp.error.no_registration", %{"procedure" => "this.should.not.exist"},
- [],
- %{}} =
- Client.send_request(
+ assert %Error{error: "wamp.error.no_registration"} =
+ Client.call(
caller_name,
- Caller.call(%Call{
+ %Call{
procedure: "this.should.not.exist",
arg_list: [1],
arg_kw: %{color: "#FFFFFF"}
- })
+ }
)
end
caller_name = TestAdminCaller
Client.start_link(name: caller_name, session: @session)
- %Result{arg_list: [id]} =
- Client.send_request(
- caller_name,
- Caller.call(%Call{
- procedure: "admin.create_peer",
- arg_kw: %{authid: "chris", password: "woot!", realm: @realm_uri}
- })
- )
-
- assert is_binary(id)
+ assert %Result{arg_kw: %{"authid" => "chris"}} =
+ Client.call(
+ caller_name,
+ %Call{
+ procedure: "admin.create_peer",
+ arg_kw: %{
+ authid: "chris",
+ password: "woot!",
+ realm: @realm_uri,
+ roles: [],
+ tenant: "org.entropealabs"
+ }
+ }
+ )
end
@tag :client
caller_name = TestAdminErrorCaller
Client.start_link(name: caller_name, session: @session)
- assert {:error, 48, "Error registering user", %{}, [], %{}} =
- Client.send_request(
+ assert %Error{error: "error"} =
+ Client.call(
caller_name,
- Caller.call(%Call{
+ %Call{
procedure: "admin.create_peer",
- arg_kw: %{authid: "chris", password: "woot!", realm: "not.real"}
- })
+ arg_kw: %{
+ authid: "chris",
+ password: "woot!",
+ realm: "not.real",
+ roles: [],
+ tenant: "org.entropealabs"
+ }
+ }
)
end
Client.start_link(name: caller_name, session: @session)
%Result{arg_list: ["ok"], arg_kw: %{"color" => "#FFFFFF"}} =
- Client.send_request(
+ Client.call(
caller_name,
- Caller.call(%Call{
+ %Call{
procedure: "com.actuator.#{@device}.light",
arg_list: [1],
arg_kw: %{color: "#FFFFFF"}
- })
+ }
)
assert_receive %Invocation{}
Client.start_link(name: TestPublisher, session: @session)
- Client.cast_send_request(
+ Client.publish(
TestPublisher,
- Publisher.publish(%Publish{
+ %Publish{
topic: "com.data.test.temp",
arg_list: [12.5, 45.6, 87.5],
arg_kw: %{loc: "60645"}
- })
+ }
)
assert_receive %Event{}, 2000