-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Process ExecutionCompleted event * Implement domain logic to handle executions from wanda * Add wanda event handling policy * Use new commanded mocked version of tests * Use uuid as cluster_id type * Correct some typos * Revert back the policy usage in the processor * Dispatch command in handle itself
- Loading branch information
Showing
7 changed files
with
289 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lib/trento/domain/cluster/commands/complete_checks_execution_wanda.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Trento.Domain.Commands.CompleteChecksExecutionWanda do | ||
@moduledoc """ | ||
Complete the checks execution with the incoming result | ||
""" | ||
|
||
@required_fields :all | ||
|
||
use Trento.Command | ||
|
||
require Trento.Domain.Enums.Health, as: Health | ||
|
||
defcommand do | ||
field :cluster_id, Ecto.UUID | ||
field :health, Ecto.Enum, values: Health.values() | ||
end | ||
end |
14 changes: 14 additions & 0 deletions
14
lib/trento/domain/cluster/events/cluster_checks_health_changed.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule Trento.Domain.Events.ClusterChecksHealthChanged do | ||
@moduledoc """ | ||
This event is emitted when the checks health of a cluster changes. | ||
""" | ||
|
||
use Trento.Event | ||
|
||
require Trento.Domain.Enums.Health, as: Health | ||
|
||
defevent do | ||
field :cluster_id, Ecto.UUID | ||
field :checks_health, Ecto.Enum, values: Health.values() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/trento/application/integration/checks/wanda/messaging/amqp/processor_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
defmodule Trento.Integration.Checks.Wanda.Messaging.AMQP.ProcessorTest do | ||
@moduledoc false | ||
use ExUnit.Case, async: true | ||
use Trento.DataCase | ||
|
||
import Mox | ||
|
||
alias Trento.Integration.Checks.Wanda.Messaging.AMQP.Processor | ||
|
||
alias Trento.Checks.V1.ExecutionCompleted | ||
alias Trento.Contracts | ||
alias Trento.Domain.Commands.CompleteChecksExecutionWanda | ||
|
||
require Trento.Domain.Enums.Health, as: Health | ||
|
||
describe "process" do | ||
test "should process ExecutionCompleted and dispatch command" do | ||
execution_id = UUID.uuid4() | ||
group_id = UUID.uuid4() | ||
|
||
execution_completed = | ||
Contracts.to_event(%ExecutionCompleted{ | ||
execution_id: execution_id, | ||
group_id: group_id, | ||
result: :PASSING | ||
}) | ||
|
||
message = %GenRMQ.Message{payload: execution_completed, attributes: %{}, channel: nil} | ||
|
||
expect(Trento.Commanded.Mock, :dispatch, fn command, opts -> | ||
assert %CompleteChecksExecutionWanda{ | ||
cluster_id: ^group_id, | ||
health: Health.passing() | ||
} = command | ||
|
||
assert [correlation_id: ^execution_id] = opts | ||
:ok | ||
end) | ||
|
||
assert :ok = Processor.process(message) | ||
end | ||
|
||
test "should return error if the event handling fails" do | ||
execution_completed = | ||
Contracts.to_event(%ExecutionCompleted{ | ||
execution_id: UUID.uuid4(), | ||
group_id: "invalid-id", | ||
result: :PASSING | ||
}) | ||
|
||
message = %GenRMQ.Message{payload: execution_completed, attributes: %{}, channel: nil} | ||
|
||
assert_raise RuntimeError, | ||
"%{cluster_id: [\"is invalid\"]}", | ||
fn -> Processor.process(message) end | ||
end | ||
|
||
@tag capture_log: true | ||
test "should return error if the event cannot be decoded" do | ||
message = %GenRMQ.Message{payload: "bad-payload", attributes: %{}, channel: nil} | ||
assert {:error, :decoding_error} = Processor.process(message) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters