alias StatesLanguage, as: SL
alias Wampex.Client.Realm
alias Wampex.Roles.Peer
- alias Wampex.Roles.Peer.{Authenticate, Hello}
+ alias Wampex.Roles.Peer.{Authenticate, Challenge, Hello}
+ alias Wampex.Roles.Dealer.Invocation
+ alias Wampex.Roles.Broker.Event
alias Wampex.Serializers.MessagePack
alias __MODULE__, as: Sess
alias Wampex.Client
url: binary(),
transport_pid: pid() | module() | nil,
message: Wampex.message() | nil,
- event: Wampex.event() | nil,
- invocation: Wampex.invocation() | nil,
+ event: Event.t() | nil,
+ invocation: Invocation.t() | nil,
goodbye: binary() | nil,
realm: Realm.t(),
name: module() | nil,
roles: [module()],
- challenge: {binary(), binary()} | nil,
+ challenge: Challenge.t() | nil,
interrupt: integer() | nil,
message_queue: [],
request_id: integer(),
data: %Sess{
transport: tt,
transport_pid: t,
- challenge: challenge,
+ challenge: %Challenge{} = challenge,
realm: %Realm{authentication: auth}
}
} = sl
@handle_event,
_,
@event,
- %SL{data: %Sess{name: name, event: event}} = sl
+ %SL{data: %Sess{name: name, event: %Event{subscription_id: sub_id} = event}} = sl
) do
Logger.debug("Received Event #{inspect(event)}")
sub = Client.subscriber_registry_name(name)
- Registry.dispatch(sub, elem(event, 1), fn entries ->
+ Registry.dispatch(sub, sub_id, fn entries ->
for {pid, _topic} <- entries, do: send(pid, event)
end)
@handle_invocation,
_,
@invocation,
- %SL{data: %Sess{name: name, invocation: invocation}} = sl
+ %SL{
+ data: %Sess{name: name, invocation: %Invocation{registration_id: reg_id} = invocation}
+ } = sl
) do
reg = Client.callee_registry_name(name)
- Registry.dispatch(reg, elem(invocation, 2), fn entries ->
+ Registry.dispatch(reg, reg_id, fn entries ->
for {pid, _procedure} <- entries, do: send(pid, invocation)
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", "7c5d257937ace7776f61ad63f8590c24ef5e382a", [tag: "7c5d257937ace7776f61ad63f8590c24ef5e382a"]},
+ "wampex": {:git, "https://gitlab.com/entropealabs/wampex.git", "5aaf4bf2dd9b69058ba2dc9c8c3f7919748b933a", [tag: "5aaf4bf2dd9b69058ba2dc9c8c3f7919748b933a"]},
"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"},
}
@url "ws://localhost:4000/ws"
@authid "admin"
- @auth_password "test1234"
- @realm_uri "org.entropealabs.admin"
+ @auth_password "bnASR5qF9y8k/sHF6S+NneCOhvVI0zFkvoKQpc2F+hA="
+ @realm_uri "admin"
@auth %Authentication{authid: @authid, authmethods: ["wampcra"], secret: @auth_password}
@realm %Realm{name: @realm_uri, authentication: @auth}
@roles [Callee, Caller, Publisher, Subscriber]
@device "as987d9a8sd79a87ds"
- setup_all do
- topologies = Application.get_env(:cluster_kv, :topologies)
-
- [
- server:
- Router.start_link(
- name: TestRouter,
- port: 4000,
- topologies: topologies,
- replicas: 1,
- quorum: 1,
- admin_realm: @realm_uri,
- admin_authid: @authid,
- admin_password: @auth_password
- )
- ]
- end
-
@session %Session{url: @url, realm: @realm, roles: @roles}
- @tag :client
- test "session_name" do
- assert Test.Session = Client.session_name(Test)
- end
-
- @tag :client
- test "subscriber_registry_name" do
- assert Test.SubscriberRegistry = Client.subscriber_registry_name(Test)
- end
-
- @tag :client
- test "callee_registry_name" do
- assert Test.CalleeRegistry = Client.callee_registry_name(Test)
- end
-
- @tag :client
- test "transport_name" do
- assert Test.Transport = Client.transport_name(Test)
- end
-
- @tag :client
- test "Callee.add" do
- assert %{callee: %{}} = Callee.add(%{})
- end
-
- @tag :client
- test "Callee.register" do
- assert [64, %{}, "test"] = Callee.register(%Register{procedure: "test"})
- end
-
- @tag :client
- test "Callee.unregister" do
- assert [66, 123_456] = Callee.unregister(%Unregister{registration_id: 123_456})
- end
-
- @tag :client
- test "Callee.yield" do
- assert [70, 1234, %{}, [], %{}] = Callee.yield(%Yield{request_id: 1234})
- assert [70, 1234, %{}, ["1"], %{}] = Callee.yield(%Yield{request_id: 1234, arg_list: ["1"]})
-
- assert [70, 1234, %{test: 1}, [2], %{}] =
- Callee.yield(%Yield{
- request_id: 1234,
- arg_list: [2],
- arg_kw: %{},
- options: %{test: 1}
- })
- end
-
- @tag :client
- test "Caller.add" do
- assert %{caller: %{}} = Caller.add(%{})
- end
-
- @tag :client
- test "Caller.call" do
- assert [48, %{}, "test", [], %{}] = Caller.call(%Call{procedure: "test"})
- assert [48, %{}, "test", [1], %{}] = Caller.call(%Call{procedure: "test", arg_list: [1]})
-
- assert [48, %{ok: 1}, "test", [1], %{test: 1}] =
- Caller.call(%Call{
- procedure: "test",
- arg_list: [1],
- arg_kw: %{test: 1},
- options: %{ok: 1}
- })
- end
-
- @tag :client
- test "Peer.add" do
- assert %{} = Caller.add(%{})
- end
-
- @tag :client
- test "Peer.hello" do
- assert [1, "test", %{agent: "WAMPex", roles: %{callee: %{}}}] =
- Peer.hello(%Hello{realm: "test", roles: [Callee]})
- end
-
- @tag :client
- test "Peer.authenticate" do
- assert [5, "a-signa-ture", %{}] ==
- Peer.authenticate(%Authenticate{signature: "a-signa-ture", extra: %{}})
- end
-
- @tag :client
- test "Peer.gooodbye" do
- assert [6, %{}, "test"] = Peer.goodbye(%Goodbye{reason: "test"})
- end
-
- @tag :client
- test "Publisher.add" do
- assert %{publisher: %{}} = Publisher.add(%{})
- end
-
- @tag :client
- test "Publisher.publish" do
- assert [16, %{}, "test", [], %{}] = Publisher.publish(%Publish{topic: "test"})
- assert [16, %{}, "test", [1], %{}] = Publisher.publish(%Publish{topic: "test", arg_list: [1]})
-
- assert [16, %{test: 2}, "test", [1], %{test: 1}] =
- Publisher.publish(%Publish{
- topic: "test",
- arg_list: [1],
- arg_kw: %{test: 1},
- options: %{test: 2}
- })
- end
-
- @tag :client
- test "Subscriber.add" do
- assert %{subscriber: %{}} = Subscriber.add(%{})
- end
-
- @tag :client
- test "Subscriber.subscribe" do
- assert [32, %{test: 1}, "test"] =
- Subscriber.subscribe(%Subscribe{topic: "test", options: %{test: 1}})
- end
-
- @tag :client
- test "Subscriber.unsubscribe" do
- assert [34, 1234] = Subscriber.unsubscribe(%Unsubscribe{subscription_id: 1234})
- end
-
- @tag :router
- test "Dealer.add" do
- assert %{dealer: %{}} = Dealer.add(%{})
- end
-
- @tag :router
- test "Dealer.registered" do
- assert [65, 123_456, 765_432] =
- Dealer.registered(%Registered{request_id: 123_456, registration_id: 765_432})
- end
-
- @tag :router
- test "Dealer.unregistered" do
- assert [67, 123_456] = Dealer.unregistered(%Unregistered{request_id: 123_456})
- end
-
- @tag :router
- test "Dealer.result" do
- assert [50, 1234, %{}, [], %{}] = Dealer.result(%Result{request_id: 1234})
- assert [50, 1234, %{}, ["1"], %{}] = Dealer.result(%Result{request_id: 1234, arg_list: ["1"]})
-
- assert [50, 1234, %{test: 1}, [2], %{}] =
- Dealer.result(%Result{
- request_id: 1234,
- arg_list: [2],
- arg_kw: %{},
- options: %{test: 1}
- })
- end
-
- @tag :router
- test "Dealer.invocation" do
- assert [68, 1234, 1234, %{}, [], %{}] =
- Dealer.invocation(%Invocation{request_id: 1234, registration_id: 1234})
-
- assert [68, 1234, 1234, %{}, ["1"], %{}] =
- Dealer.invocation(%Invocation{
- request_id: 1234,
- registration_id: 1234,
- arg_list: ["1"]
- })
-
- assert [68, 1234, 1234, %{test: 1}, [2], %{test: 2}] =
- Dealer.invocation(%Invocation{
- request_id: 1234,
- registration_id: 1234,
- arg_list: [2],
- arg_kw: %{test: 2},
- options: %{test: 1}
- })
- end
-
- @tag :router
- test "Broker.add" do
- assert %{broker: %{}} = Broker.add(%{})
- end
-
- @tag :router
- test "Broker.event" do
- assert [36, 123_456, 765_432, %{}, [], %{}] =
- Broker.event(%Event{subscription_id: 123_456, publication_id: 765_432})
-
- assert [36, 123_456, 765_432, %{}, [2], %{}] =
- Broker.event(%Event{subscription_id: 123_456, publication_id: 765_432, arg_list: [2]})
-
- assert [36, 123_456, 765_432, %{}, [2], %{test: 1}] =
- Broker.event(%Event{
- subscription_id: 123_456,
- publication_id: 765_432,
- arg_list: [2],
- arg_kw: %{test: 1}
- })
- end
-
- @tag :router
- test "Broker.subscribed" do
- assert [33, 123_456, 123_456] =
- Broker.subscribed(%Subscribed{request_id: 123_456, subscription_id: 123_456})
- end
-
- @tag :router
- test "Broker.unsubscribed" do
- assert [35, 123_456] = Broker.unsubscribed(%Unsubscribed{request_id: 123_456})
- end
-
- @tag :router
- test "Broker.published" do
- assert [17, 123_456, 654_321] =
- Broker.published(%Published{request_id: 123_456, publication_id: 654_321})
- end
-
- @tag :client
- test "MessagePack Serializer" do
- assert :binary = MessagePack.data_type()
- assert "\x93\x05\xC4\t123456789\x80" = MessagePack.serialize!([5, "123456789", %{}])
- assert {:ok, "\x93\x05\xC4\t123456789\x80"} = MessagePack.serialize([5, "123456789", %{}])
- assert [5, "123456789", %{}] = MessagePack.deserialize!("\x93\x05\xC4\t123456789\x80")
- assert {:ok, [5, "123456789", %{}]} = MessagePack.deserialize("\x93\x05\xC4\t123456789\x80")
- end
-
- @tag :client
- test "JSON Serializer" do
- assert :text = JSON.data_type()
- assert "[5,\"123456789\",{}]" = JSON.serialize!([5, "123456789", %{}])
- assert {:ok, "[5,\"123456789\",{}]"} = JSON.serialize([5, "123456789", %{}])
- assert [5, "123456789", %{}] = JSON.deserialize!("[5,\"123456789\",{}]")
- assert {:ok, [5, "123456789", %{}]} = JSON.deserialize("[5,\"123456789\",{}]")
- end
-
@tag :client
test "callee registration" do
name = TestCalleeRegistration
assert_receive {:registered, id}
end
- @tag :router
- test "get wildcard key" do
- subscriber_name = TestSubscriber
- topic = ".test.light..status"
- {:ok, _pid} = Client.start_link(name: subscriber_name, session: @session)
-
- assert {:ok, id} =
- Client.send_request(
- subscriber_name,
- Subscriber.subscribe(%Subscribe{topic: topic, options: %{match: "wildcard"}})
- )
-
- assert :ok =
- Client.send_request(
- subscriber_name,
- Subscriber.unsubscribe(%Unsubscribe{subscription_id: id})
- )
- end
-
@tag :abort
test "abort" do
Process.flag(:trap_exit, true)
caller_name = TestAdminCaller
Client.start_link(name: caller_name, session: @session)
- {:ok, %{}, [id], %{}} =
+ %Result{arg_list: [id]} =
Client.send_request(
caller_name,
Caller.call(%Call{
- procedure: "admin.create_user",
+ procedure: "admin.create_peer",
arg_kw: %{authid: "chris", password: "woot!", realm: @realm_uri}
})
)
Client.send_request(
caller_name,
Caller.call(%Call{
- procedure: "admin.create_user",
+ procedure: "admin.create_peer",
arg_kw: %{authid: "chris", password: "woot!", realm: "not.real"}
})
)
callee_name = TestCalleeRespond
Client.start_link(name: callee_name, session: @session)
TestCallee.start_link(self(), callee_name, @device)
- assert_receive {:registered, id}
+ assert_receive {_, _}
caller_name = TestCaller
Client.start_link(name: caller_name, session: @session)
- {:ok, %{}, ["ok"], %{"color" => "#FFFFFF"}} =
+ %Result{arg_list: ["ok"], arg_kw: %{"color" => "#FFFFFF"}} =
Client.send_request(
caller_name,
Caller.call(%Call{
})
)
- assert_receive {:invocation, _, _, _, _, _}
+ assert_receive %Invocation{}
end
@tag :client
})
)
- assert_receive {:event, _, _, _, _, _}, 2000
- assert_receive {:event, _, _, _, _, _}, 2000
- assert_receive {:event, _, _, _, _, _}, 2000
+ assert_receive %Event{}, 2000
+ assert_receive %Event{}, 2000
+ assert_receive %Event{}, 2000
end
end