Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions distributed/remote_fun/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default:
@echo "usage make [client|server]"

client:
./rebar3 shell --sname 'client@localhost'
rebar3 shell --sname 'client@localhost'

server:
./rebar3 shell --sname 'server@localhost'
rebar3 shell --sname 'server@localhost'
6 changes: 3 additions & 3 deletions libraries/shortly/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ default:
@echo "usage [test|server]"

server:
./rebar3 shell --apps shortly
rebar3 shell --apps shortly

node_1:
./rebar3 shell --apps shortly --config src/config/node_1.config --sname node_1
rebar3 shell --apps shortly --config src/config/node_1.config --sname node_1

node_2:
./rebar3 shell --apps shortly --config src/config/node_2.config --sname node_2
rebar3 shell --apps shortly --config src/config/node_2.config --sname node_2
33 changes: 20 additions & 13 deletions libraries/shortly/rebar.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
{"1.1.0",
[{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.2.1">>},0},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.1.0">>},1},
{<<"gun">>,{pkg,<<"gun">>,<<"1.0.0-pre.4b">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"2.9.0">>},0},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.4.0">>},1},
{<<"syn">>,{pkg,<<"syn">>,<<"1.6.3">>},0}]}.
{"1.2.0",
[{<<"cowboy">>,{pkg,<<"cowboy">>,<<"2.12.0">>},0},
{<<"cowlib">>,{pkg,<<"cowlib">>,<<"2.13.0">>},1},
{<<"gun">>,{pkg,<<"gun">>,<<"2.1.0">>},0},
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},0},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.8.0">>},1},
{<<"syn">>,{pkg,<<"syn">>,<<"3.3.0">>},0}]}.
[
{pkg_hash,[
{<<"cowboy">>, <<"43E9F86A22922A7512A7CA50B61E9F9F90519CC042B3C060861A6AEE7F323CC9">>},
{<<"cowlib">>, <<"F73658B93DD043AF40400C3E4FD997068EBD0C617F8C8F4CD003A1A78EBF94F5">>},
{<<"gun">>, <<"DD53B9FD3D597CFA7974D6AD85128AC7E16A408D6DC8C392A532AA36EB032A5D">>},
{<<"jsx">>, <<"D2F6E5F069C00266CAD52FB15D87C428579EA4D7D73A33669E12679E203329DD">>},
{<<"ranch">>, <<"10272F95DA79340FA7E8774BA7930B901713D272905D0012B06CA6D994F8826B">>},
{<<"syn">>, <<"E3400A6286A7C44ED0A0293D0E83A1F44AA9B1A9EC2C8D54EEE2CD1F4FF2F94E">>}]}
{<<"cowboy">>, <<"F276D521A1FF88B2B9B4C54D0E753DA6C66DD7BE6C9FCA3D9418B561828A3731">>},
{<<"cowlib">>, <<"DB8F7505D8332D98EF50A3EF34B34C1AFDDEC7506E4EE4DD4A3A266285D282CA">>},
{<<"gun">>, <<"B4E4CBBF3026D21981C447E9E7CA856766046EFF693720BA43114D7F5DE36E87">>},
{<<"jsx">>, <<"D12516BAA0BB23A59BB35DCCAF02A1BD08243FCBB9EFE24F2D9D056CCFF71268">>},
{<<"ranch">>, <<"8C7A100A139FD57F17327B6413E4167AC559FBC04CA7448E9BE9057311597A1D">>},
{<<"syn">>, <<"4684A909EFDFEA35CE75A9662FC523E4A8A4E8169A3DF275E4DE4FA63F99C486">>}]},
{pkg_hash_ext,[
{<<"cowboy">>, <<"8A7ABE6D183372CEB21CAA2709BEC928AB2B72E18A3911AA1771639BEF82651E">>},
{<<"cowlib">>, <<"E1E1284DC3FC030A64B1AD0D8382AE7E99DA46C3246B815318A4B848873800A4">>},
{<<"gun">>, <<"52FC7FC246BFC3B00E01AEA1C2854C70A366348574AB50C57DFE796D24A0101D">>},
{<<"jsx">>, <<"0C5CC8FDC11B53CC25CF65AC6705AD39E54ECC56D1C22E4ADB8F5A53FB9427F3">>},
{<<"ranch">>, <<"49FBCFD3682FAB1F5D109351B61257676DA1A2FDBE295904176D5E521A2DDFE5">>},
{<<"syn">>, <<"E58EE447BC1094BDD21BF0ACC102B1FBF99541A508CD48060BF783C245EAF7D6">>}]}
].
Binary file removed libraries/shortly/rebar3
Binary file not shown.
10 changes: 5 additions & 5 deletions libraries/shortly/solution/shortly_notification_pg2.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
unsubscribe/1,
notify/1]).

-define (PG2_NAME, shortly_notification_pg2_name).
-define (PG_NAME, shortly_notification_pg2_name).

init() ->
pg2:create(?PG2_NAME).
pg:create(?PG_NAME).

subscribe(Pid) ->
pg2:join(?PG2_NAME, Pid).
pg:join(?PG_NAME, Pid).

unsubscribe(Pid) ->
pg2:leave(?PG2_NAME, Pid).
pg:leave(?PG_NAME, Pid).

notify(Msg) ->
Subs = pg2:get_members(?PG2_NAME),
Subs = pg:get_members(?PG_NAME),
lists:foreach(
fun(Pid) ->
Pid ! Msg
Expand Down
8 changes: 4 additions & 4 deletions libraries/shortly/solution/shortly_syn.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
-define(SYN_NAME, syn_ws_connections).

init() ->
syn:init().
ok = syn:add_node_to_scopes([?SYN_NAME]).

subscribe(Pid) ->
syn:join(?SYN_NAME, Pid).
ok = syn:join(?SYN_NAME, "shortly-group", Pid).

unsubscribe(Pid) ->
pg2:leave(?SYN_NAME, Pid).
syn:leave(?SYN_NAME, "shortly-group", Pid).

notify(Msg) ->
syn:publish(?SYN_NAME, Msg).
syn:publish(?SYN_NAME, "shortly-group", Msg).
2 changes: 1 addition & 1 deletion libraries/shortly/solution/shortly_ws_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ init(Req, Opts) ->
{cowboy_websocket,Req,Opts}.

websocket_init(State) ->
shortly_shortener:subscribe(self()),
ok = shortly_shortener:subscribe(self()),
{ok, State}.

websocket_handle(_Msg, State) ->
Expand Down
34 changes: 18 additions & 16 deletions libraries/shortly/test/shortly_shortener_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@
-record(shortly_urls, {hash, url}).

all() ->
[test_notfound,
[
test_notfound,
test_created,
test_ok,
test_redirect,
test_ws,
run_eunit].
run_eunit
].

init_per_suite(Config) ->
mnesia:start(),
mnesia:create_table(shortly_urls,
[{attributes, record_info(fields, shortly_urls)},
{type, set},
{ram_copies, [node()]}]),
application:ensure_all_started(shortly),
application:ensure_all_started(gun),
{ok, _ } = application:ensure_all_started(shortly),
{ok, _ } = application:ensure_all_started(syn),
{ok, _ } = application:ensure_all_started(gun),
Config.

end_per_suite(Config) ->
mnesia:clear_table(shortly_urls),
application:stop(shortly),
application:stop(syn),
application:stop(gun),
Config.

Expand Down Expand Up @@ -99,30 +103,28 @@ do_get_request(Url) ->
{StatusCode, Headers, json_to_map(Body)}.

url(Url) ->
StringUrl = http_uri:encode(Url),
StringUrl = uri_string:quote(Url),
list_to_binary(StringUrl).

ws_connect(Path) ->
{ok, Pid} = gun:open("127.0.0.1", 8080, #{retry=>0}),
{ok, http} = gun:await_up(Pid),
Ref = monitor(process, Pid),
gun:ws_upgrade(Pid, Path, [], #{compress => true}),
receive
{gun_ws_upgrade, Pid, ok, _} ->
ok;
_ ->
error(failed)
end,
{Pid, Ref}.
{gun_upgrade, Pid, StreamRef, [<<"websocket">>], _} ->
{Pid, StreamRef};
Err ->
error(Err)
end.

ws_get({Pid,_}) ->
receive
{gun_ws, Pid, {text, Text}} ->
{gun_ws, Pid, _StreamRef, {text, Text}} ->
Text;
_ ->
error(failed)
Failed ->
error(Failed)
after 5000 ->
error(timout)
error(timeout)
end.

ws_terminate({Pid, Ref}) ->
Expand Down