Skip to content

Commit a407bd6

Browse files
committed
Code for step 5
1 parent ebfa104 commit a407bd6

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/load_generator.ex

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
defmodule PaymentsClient.LoadGenerator do
2+
alias PaymentsClient.{MockAPI, RateLimiter}
3+
4+
def create_requests(num_requests) do
5+
1..num_requests
6+
|> Enum.each(fn _ ->
7+
{request_handler, response_handler} = generate_random_request()
8+
9+
RateLimiter.make_request(request_handler, response_handler)
10+
end)
11+
end
12+
13+
defp generate_random_request do
14+
case Enum.random(1..3) do
15+
1 ->
16+
{
17+
{MockAPI, :create_payment, [123, %{cc_number: 1_234_567_890, exp_date: "01/28"}]},
18+
{MockAPI, :handle_create_payment}
19+
}
20+
21+
2 ->
22+
{
23+
{MockAPI, :delete_payment, [123, 456]},
24+
{MockAPI, :handle_delete_payment}
25+
}
26+
27+
3 ->
28+
{
29+
{MockAPI, :charge_payment, [123, 456, 10.00]},
30+
{MockAPI, :handle_charge_payment}
31+
}
32+
end
33+
end
34+
end

0 commit comments

Comments
 (0)