Skip to content

Commit

Permalink
refactor!: remove xandra cluster and utils
Browse files Browse the repository at this point in the history
so as not to rewrite the tests, for now we still register the cluster
used by Exandra under the same name.
  • Loading branch information
noaccOS committed Oct 1, 2024
1 parent 3d62135 commit 5c68385
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
7 changes: 0 additions & 7 deletions lib/astarte_data_access.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,7 @@ defmodule Astarte.DataAccess do
def init(init_arg) do
xandra_options = Keyword.fetch!(init_arg, :xandra_options)

xandra_cluster_options =
xandra_options
|> Keyword.put(:name, :astarte_data_access_xandra)
# TODO move to string keys
|> Keyword.put(:atom_keys, true)

children = [
{Xandra.Cluster, xandra_cluster_options},
{Astarte.DataAccess.Repo, xandra_options}
]

Expand Down
4 changes: 2 additions & 2 deletions test/device_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ defmodule Astarte.DataAccess.Device.XandraTest do
Xandra.Cluster.prepare!(:astarte_data_access_xandra, insert_empty_introspection_stmt)

Xandra.Cluster.execute!(:astarte_data_access_xandra, prepared, %{
device_id: device_id,
empty_introspection: %{}
"device_id" => device_id,
"empty_introspection" => %{}
})

assert Device.interface_version(
Expand Down
26 changes: 13 additions & 13 deletions test/support/database_test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,9 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
device_id = Base.url_decode64!(encoded_device_id, padding: false)

insert_device_query_params = %{
device_id: device_id,
aliases: aliases,
total_received_bytes: total_received_bytes
"device_id" => device_id,
"aliases" => aliases,
"total_received_bytes" => total_received_bytes
}

insert_device_query_prp = Xandra.prepare!(conn, @insert_device_statement)
Expand All @@ -437,8 +437,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do

for {_key, device_alias} <- aliases || %{} do
insert_alias_query_params = %{
device_id: device_id,
alias: device_alias
"device_id" => device_id,
"alias" => device_alias
}

alias_query_prepared = Xandra.prepare!(conn, @insert_alias_statement)
Expand All @@ -448,11 +448,11 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
end

insert_into_interface_0_params = %{
automaton_accepting_states:
"automaton_accepting_states" =>
Base.decode64!(
"g3QAAAAFYQNtAAAAEIAeEDVf33Bpjm4/0nkmmathBG0AAAAQjrtis2DBS6JBcp3e3YCcn2EFbQAAABBP5QNKPZuZ7H7DsjcWMD0zYQdtAAAAEOb3NjHv/B1+rVLT86O65QthCG0AAAAQKyxj3bvZVzVtSo5W9QTt2g=="
),
automaton_transitions:
"automaton_transitions" =>
Base.decode64!(
"g3QAAAAIaAJhAG0AAAAKbGNkQ29tbWFuZGEFaAJhAG0AAAAEdGltZWEGaAJhAG0AAAAMd2Vla1NjaGVkdWxlYQFoAmEBbQAAAABhAmgCYQJtAAAABXN0YXJ0YQNoAmECbQAAAARzdG9wYQRoAmEGbQAAAARmcm9tYQdoAmEGbQAAAAJ0b2EI"
)
Expand All @@ -463,11 +463,11 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
Xandra.execute!(conn, insert_into_interface_0_prepared, insert_into_interface_0_params)

insert_into_interface_1_params = %{
automaton_accepting_states:
"automaton_accepting_states" =>
Base.decode64!(
"g3QAAAAFYQJtAAAAEHUBDhsZnu783TXSVLDiCSRhBW0AAAAQOQfUHVvKMp2eUUzqKlSpmmEGbQAAABB6pEwRInNH2eYkSuAp3t6qYQdtAAAAEO/5V88D397tl4SocI49jLlhCG0AAAAQNGyA5MqZYnSB9nscG+WVIQ=="
),
automaton_transitions:
"automaton_transitions" =>
Base.decode64!(
"g3QAAAAIaAJhAG0AAAAAYQFoAmEAbQAAAANmb29hA2gCYQFtAAAABXZhbHVlYQJoAmEDbQAAAABhBGgCYQRtAAAACWJsb2JWYWx1ZWEGaAJhBG0AAAAJbG9uZ1ZhbHVlYQdoAmEEbQAAAAtzdHJpbmdWYWx1ZWEFaAJhBG0AAAAOdGltZXN0YW1wVmFsdWVhCA=="
)
Expand All @@ -480,8 +480,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
Xandra.execute!(conn, @insert_into_interface_2, %{})

insert_into_interface_3_params = %{
automaton_accepting_states: Base.decode64!("g3QAAAABYQNtAAAAEOPZVKNVUNqw17mW3O0hiYc="),
automaton_transitions:
"automaton_accepting_states" => Base.decode64!("g3QAAAABYQNtAAAAEOPZVKNVUNqw17mW3O0hiYc="),
"automaton_transitions" =>
Base.decode64!("g3QAAAADaAJhAG0AAAAAYQFoAmEBbQAAAABhAmgCYQJtAAAABWNvbG9yYQM=")
}

Expand All @@ -490,8 +490,8 @@ defmodule Astarte.DataAccess.DatabaseTestHelper do
Xandra.execute!(conn, insert_into_interface_3_prepared, insert_into_interface_3_params)

insert_into_interface_4_params = %{
automaton_accepting_states: Base.decode64!("g3QAAAABYQNtAAAAEGZjaujopxRZWiHuQLZfzfQ="),
automaton_transitions:
"automaton_accepting_states" => Base.decode64!("g3QAAAABYQNtAAAAEGZjaujopxRZWiHuQLZfzfQ="),
"automaton_transitions" =>
Base.decode64!(
"g3QAAAADaAJhAG0AAAADbmV3YQFoAmEBbQAAAAlpbnRlcmZhY2VhAmgCYQJtAAAABXZhbHVlYQM="
)
Expand Down
15 changes: 14 additions & 1 deletion test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
alias Astarte.DataAccess.Config

ExUnit.start()

children = [
{Astarte.DataAccess, xandra_options: Astarte.DataAccess.Config.xandra_options!()}
{Astarte.DataAccess, xandra_options: Config.xandra_options!()}
]

Supervisor.start_link(children, strategy: :one_for_one)

# Register the Xandra cluster process so that it can be used in tests
# Yes they both have id 'Astarte.DataAccess.Repo'
Astarte.DataAccess
|> Supervisor.which_children()
# Astarte.DataAccess' child
|> Enum.find_value(fn {id, pid, _, _} -> id == Astarte.DataAccess.Repo && pid end)
|> Supervisor.which_children()
# Astarte.DataAccess.Repo's child
|> Enum.find_value(fn {id, pid, _, _} -> id == Astarte.DataAccess.Repo && pid end)
|> Process.register(:astarte_data_access_xandra)

Code.require_file("support/database_test_helper.exs", __DIR__)

0 comments on commit 5c68385

Please sign in to comment.