From fbae50f83e14257ce4b30eda1e12f5aae25ba8b1 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 22 Feb 2024 15:35:08 +0100 Subject: [PATCH 01/22] feat: Find Options - Update components API --- libs/application_runner/priv/components-api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/application_runner/priv/components-api b/libs/application_runner/priv/components-api index 87c0e492..c5905611 160000 --- a/libs/application_runner/priv/components-api +++ b/libs/application_runner/priv/components-api @@ -1 +1 @@ -Subproject commit 87c0e492eda38e38ce900d4dc6cd21c270f6a9d6 +Subproject commit c5905611c941dd20da139c9a0d871f862657c325 From 7d69b01f567dc2fb93d15a3d80b7ce532f60d616 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 22 Feb 2024 15:46:21 +0100 Subject: [PATCH 02/22] debug --- libs/application_runner/lib/controllers/docs_controller.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index bc16efdf..22433cc5 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -252,6 +252,8 @@ defmodule ApplicationRunner.DocsController do Enum.map(Map.get(commands, "options", %{}), fn {k, v} -> {String.to_atom(k), v} end) ) + IO.inspect(mongo_opts) + case MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, coll, From dd34146586c6afbdfc597581b930879da191b5c0 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 22 Feb 2024 15:53:44 +0100 Subject: [PATCH 03/22] debug --- libs/application_runner/lib/controllers/docs_controller.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index 22433cc5..0bbbb5d6 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -252,6 +252,7 @@ defmodule ApplicationRunner.DocsController do Enum.map(Map.get(commands, "options", %{}), fn {k, v} -> {String.to_atom(k), v} end) ) + IO.inspect("mongo_opts") IO.inspect(mongo_opts) case MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ From c87cc06f5832e9702c18ca2fafec6e07ba275d71 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 22 Feb 2024 15:57:18 +0100 Subject: [PATCH 04/22] debug --- libs/application_runner/lib/controllers/docs_controller.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index 0bbbb5d6..118652e3 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -282,6 +282,9 @@ defmodule ApplicationRunner.DocsController do "This form of query is deprecated, prefer using: {query: , projection: {projection}}, more info at: https://www.mongodb.com/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find" ) + IO.inspect("find_deprecated") + IO.inspect(filter) + with {:ok, docs} <- MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, From d781520b3d6a92d7c4282676fe4b08fa617d9e8a Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 14:53:26 +0100 Subject: [PATCH 05/22] add logs --- libs/application_runner/lib/controllers/docs_controller.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index 118652e3..8856ea69 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -255,6 +255,8 @@ defmodule ApplicationRunner.DocsController do IO.inspect("mongo_opts") IO.inspect(mongo_opts) + Logger.warning("mongo_opts #{inspect(mongo_opts)}"); + case MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, coll, @@ -285,6 +287,8 @@ defmodule ApplicationRunner.DocsController do IO.inspect("find_deprecated") IO.inspect(filter) + Logger.warning("find_deprecated #{inspect(filter)}"); + with {:ok, docs} <- MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, From 3be4f8c44da5564e78b73f1dca9e736fed53d410 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:07:51 +0100 Subject: [PATCH 06/22] add log --- libs/application_runner/lib/session/route_server.ex | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/application_runner/lib/session/route_server.ex b/libs/application_runner/lib/session/route_server.ex index 9ddf10ca..e8140837 100644 --- a/libs/application_runner/lib/session/route_server.ex +++ b/libs/application_runner/lib/session/route_server.ex @@ -129,6 +129,8 @@ defmodule ApplicationRunner.Session.RouteServer do query = Map.get(find, "query", %{}) projection = Map.get(find, "projection", %{}) + Logger.warning("FIND OPTIONS: #{inspect(find)}") + if find == %{} && coll_deprecated != nil do Logger.warning( "Definition of view #{name} is deprecated since applicationRunner beta 106 check https://docs.lenra.io/components-api/components/view.html." From a3bb101264ae821ecc9c9f38502ca48bb532ade7 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:13:58 +0100 Subject: [PATCH 07/22] Add options in view uid --- .../lib/environment/view_uid.ex | 6 ++++-- .../lib/session/route_server.ex | 15 ++++++++------- .../lib/session/ui_builders/lenra_builder.ex | 4 ++-- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libs/application_runner/lib/environment/view_uid.ex b/libs/application_runner/lib/environment/view_uid.ex index 86d0e9ea..2041df1a 100644 --- a/libs/application_runner/lib/environment/view_uid.ex +++ b/libs/application_runner/lib/environment/view_uid.ex @@ -2,7 +2,7 @@ defmodule ApplicationRunner.Environment.ViewUid do @moduledoc """ This identify a unique widget for a given environment. """ - @enforce_keys [:name, :coll, :query_parsed, :query_transformed, :props, :context, :projection] + @enforce_keys [:name, :coll, :query_parsed, :query_transformed, :props, :context, :projection, :options] defstruct [ :name, :props, @@ -11,6 +11,7 @@ defmodule ApplicationRunner.Environment.ViewUid do :context, :coll, :projection, + :options, prefix_path: "" ] @@ -22,6 +23,7 @@ defmodule ApplicationRunner.Environment.ViewUid do coll: String.t() | nil, context: map() | nil, prefix_path: String.t(), - projection: map() + projection: map(), + options: map() } end diff --git a/libs/application_runner/lib/session/route_server.ex b/libs/application_runner/lib/session/route_server.ex index e8140837..279481c5 100644 --- a/libs/application_runner/lib/session/route_server.ex +++ b/libs/application_runner/lib/session/route_server.ex @@ -98,12 +98,12 @@ defmodule ApplicationRunner.Session.RouteServer do props <- Map.get(base_view, "props", %{}), find <- Map.get(base_view, "find", %{}), context_projection <- Map.get(base_view, "context"), - {coll, query, projection} <- extract_find(base_view, find), + {coll, query, projection, options} <- extract_find(base_view, find), {:ok, view_uid} <- create_view_uid( session_metadata, name, - %{coll: coll, query: query, projection: projection}, + %{coll: coll, query: query, projection: projection, options: options}, %{"route" => route_params}, props, session_metadata.context, @@ -128,17 +128,16 @@ defmodule ApplicationRunner.Session.RouteServer do coll = Map.get(find, "coll") query = Map.get(find, "query", %{}) projection = Map.get(find, "projection", %{}) - - Logger.warning("FIND OPTIONS: #{inspect(find)}") + options = Map.get(find, "options", %{}) if find == %{} && coll_deprecated != nil do Logger.warning( "Definition of view #{name} is deprecated since applicationRunner beta 106 check https://docs.lenra.io/components-api/components/view.html." ) - {coll_deprecated, query_deprecated, %{}} + {coll_deprecated, query_deprecated, %{}, %{}} else - {coll, query, projection} + {coll, query, projection, options} end end @@ -197,6 +196,7 @@ defmodule ApplicationRunner.Session.RouteServer do coll = Map.get(find, :coll) query = Map.get(find, :query) projection = Map.get(find, :projection) + options = Map.get(find, :options) mongo_user_id = case session_metadata.user_id do @@ -238,7 +238,8 @@ defmodule ApplicationRunner.Session.RouteServer do query_transformed: query_transformed, coll: coll, context: context, - projection: projection + projection: projection, + options: options }} end end diff --git a/libs/application_runner/lib/session/ui_builders/lenra_builder.ex b/libs/application_runner/lib/session/ui_builders/lenra_builder.ex index 689b074e..9549489e 100644 --- a/libs/application_runner/lib/session/ui_builders/lenra_builder.ex +++ b/libs/application_runner/lib/session/ui_builders/lenra_builder.ex @@ -126,13 +126,13 @@ defmodule ApplicationRunner.Session.UiBuilders.LenraBuilder do find = Map.get(component, "find", %{}) context_projection = Map.get(component, "context") - {coll, query, projection} = RouteServer.extract_find(component, find) + {coll, query, projection, options} = RouteServer.extract_find(component, find) with {:ok, new_view_uid} <- RouteServer.create_view_uid( session_metadata, name, - %{coll: coll, query: query, projection: projection}, + %{coll: coll, query: query, projection: projection, options: options}, %{}, props, view_uid.context, From aae96e4a63f180dd542904a2b248096c7fa4be18 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:26:42 +0100 Subject: [PATCH 08/22] add options in view_server --- libs/application_runner/lib/environment/view_dyn_sup.ex | 6 ++++-- libs/application_runner/lib/environment/view_server.ex | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/libs/application_runner/lib/environment/view_dyn_sup.ex b/libs/application_runner/lib/environment/view_dyn_sup.ex index 01991f0d..8a97bae9 100644 --- a/libs/application_runner/lib/environment/view_dyn_sup.ex +++ b/libs/application_runner/lib/environment/view_dyn_sup.ex @@ -29,6 +29,7 @@ defmodule ApplicationRunner.Environment.ViewDynSup do query_parsed = view_uid.query_parsed query_transformed = view_uid.query_transformed projection = view_uid.projection + options = view_uid.options Logger.debug("#{__MODULE__} ensure_child_started for #{inspect(%{env_id: env_id, session_id: session_id})}") @@ -38,14 +39,15 @@ defmodule ApplicationRunner.Environment.ViewDynSup do coll, query_parsed, query_transformed, - projection + projection, + options ) do case start_child(env_id, function_name, view_uid) do {:ok, pid} -> Logger.info("ApplicationRunner.Environment.ViewServer") QueryServer.join_group(qs_pid, session_id) - ViewServer.join_group(pid, env_id, coll, query_parsed, projection) + ViewServer.join_group(pid, env_id, coll, query_parsed, projection, options) QueryServer.monitor(qs_pid, pid) {:ok, pid} diff --git a/libs/application_runner/lib/environment/view_server.ex b/libs/application_runner/lib/environment/view_server.ex index 9d683971..fad54a5c 100644 --- a/libs/application_runner/lib/environment/view_server.ex +++ b/libs/application_runner/lib/environment/view_server.ex @@ -11,11 +11,11 @@ defmodule ApplicationRunner.Environment.ViewServer do require Logger def group_name(env_id, coll, query, projection) do - {__MODULE__, env_id, coll, query, projection} + {__MODULE__, env_id, coll, query, projection, options} end def join_group(pid, env_id, coll, query, projection) do - group = group_name(env_id, coll, query, projection) + group = group_name(env_id, coll, query, projection, options) Swarm.join(group, pid) end @@ -46,7 +46,7 @@ defmodule ApplicationRunner.Environment.ViewServer do %ViewUid{} = view_uid = Keyword.fetch!(opts, :view_uid) with data <- - QueryServer.get_data(env_id, view_uid.coll, view_uid.query_parsed, view_uid.projection), + QueryServer.get_data(env_id, view_uid.coll, view_uid.query_parsed, view_uid.projection, view_uid.options), {:ok, view} <- ApplicationServices.fetch_view( function_name, From 7f3c862542cd2a3f4de717aea0f5fcf14947083f Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:37:36 +0100 Subject: [PATCH 09/22] fix view_server --- libs/application_runner/lib/environment/view_server.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/application_runner/lib/environment/view_server.ex b/libs/application_runner/lib/environment/view_server.ex index fad54a5c..ae7c649a 100644 --- a/libs/application_runner/lib/environment/view_server.ex +++ b/libs/application_runner/lib/environment/view_server.ex @@ -10,11 +10,11 @@ defmodule ApplicationRunner.Environment.ViewServer do require Logger - def group_name(env_id, coll, query, projection) do + def group_name(env_id, coll, query, projection, options) do {__MODULE__, env_id, coll, query, projection, options} end - def join_group(pid, env_id, coll, query, projection) do + def join_group(pid, env_id, coll, query, projection, options) do group = group_name(env_id, coll, query, projection, options) Swarm.join(group, pid) end From fc88454f7043d4b20d30c59441c75b8ab1d1e5cf Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:46:29 +0100 Subject: [PATCH 10/22] add options in query_dyn_sup --- .../lib/environment/query_dyn_sup.ex | 11 ++++++----- .../lib/environment/query_server.ex | 12 +++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/libs/application_runner/lib/environment/query_dyn_sup.ex b/libs/application_runner/lib/environment/query_dyn_sup.ex index 9486dee7..3020ae5f 100644 --- a/libs/application_runner/lib/environment/query_dyn_sup.ex +++ b/libs/application_runner/lib/environment/query_dyn_sup.ex @@ -29,14 +29,14 @@ defmodule ApplicationRunner.Environment.QueryDynSup do DynamicSupervisor.init(strategy: :one_for_one) end - @spec ensure_child_started(term(), String.t() | nil, map() | nil, map() | nil, map()) :: + @spec ensure_child_started(term(), String.t() | nil, map() | nil, map() | nil, map(), map()) :: {:ok, pid()} | {:error, term()} - def ensure_child_started(env_id, coll, query_parsed, query_transformed, projection) do + def ensure_child_started(env_id, coll, query_parsed, query_transformed, projection, options) do Logger.debug( "#{__MODULE__} ensure query server started for #{inspect([env_id, coll, query_parsed, query_transformed])}" ) - case start_child(env_id, coll, query_parsed, query_transformed, projection) do + case start_child(env_id, coll, query_parsed, query_transformed, projection, options) do {:ok, pid} -> Logger.info("ApplicationRunner.Environment.QueryServer started") {:ok, pid} @@ -50,13 +50,14 @@ defmodule ApplicationRunner.Environment.QueryDynSup do end end - defp start_child(env_id, coll, query_parsed, query_transformed, projection) do + defp start_child(env_id, coll, query_parsed, query_transformed, projection, options) do init_value = [ query_parsed: query_parsed, query_transformed: query_transformed, coll: coll, env_id: env_id, - projection: projection + projection: projection, + options: options ] DynamicSupervisor.start_child(get_full_name(env_id), {QueryServer, init_value}) diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index 35d7891b..9784af6a 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -46,11 +46,11 @@ defmodule ApplicationRunner.Environment.QueryServer do Swarm.join(group, pid) end - def get_data(env_id, coll, query_parsed, projection) do - GenServer.call(get_full_name({env_id, coll, query_parsed}), {:get_data, projection}) + def get_data(env_id, coll, query_parsed, projection, options) do + GenServer.call(get_full_name({env_id, coll, query_parsed}), {:get_data, projection, options}) end - def add_projection(env_id, coll, query_parsed, projection) do + def add_projection(env_id, coll, query_parsed, projection, options) do GenServer.call(get_full_name({env_id, coll, query_parsed}), {:add_projection, projection}) end @@ -65,7 +65,8 @@ defmodule ApplicationRunner.Environment.QueryServer do {:ok, query_transformed} <- Keyword.fetch(opts, :query_transformed), {:ok, query_parsed} <- Keyword.fetch(opts, :query_parsed), {:ok, data} <- fetch_initial_data(env_id, coll, query_transformed), - {:ok, projection} <- Keyword.fetch(opts, :projection) do + {:ok, projection} <- Keyword.fetch(opts, :projection), + {:ok, options} <- Keyword.fetch(opts, :options) do projection_data = if projection != %{} do %{projection => projection_data(data, projection)} @@ -83,7 +84,8 @@ defmodule ApplicationRunner.Environment.QueryServer do latest_timestamp: Mongo.timestamp(DateTime.utc_now()), done_ids: MapSet.new(), w_pids: MapSet.new(), - projection_data: projection_data + projection_data: projection_data, + options: options }} else :error -> From 6d3d13eaab35f3f77244a73579b4bb4e5a4140d1 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 15:50:27 +0100 Subject: [PATCH 11/22] test --- libs/application_runner/lib/environment/query_server.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index 9784af6a..180b86ef 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -47,10 +47,10 @@ defmodule ApplicationRunner.Environment.QueryServer do end def get_data(env_id, coll, query_parsed, projection, options) do - GenServer.call(get_full_name({env_id, coll, query_parsed}), {:get_data, projection, options}) + GenServer.call(get_full_name({env_id, coll, query_parsed}), {:get_data, projection}) end - def add_projection(env_id, coll, query_parsed, projection, options) do + def add_projection(env_id, coll, query_parsed, projection) do GenServer.call(get_full_name({env_id, coll, query_parsed}), {:add_projection, projection}) end From 66223fa1c67d278951ad3a589c70a0d1b5f4222a Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 16:27:23 +0100 Subject: [PATCH 12/22] add options in fetch_initial_data --- .../lib/environment/query_server.ex | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index 180b86ef..44f6e9cf 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -64,9 +64,9 @@ defmodule ApplicationRunner.Environment.QueryServer do {:ok, coll} <- Keyword.fetch(opts, :coll), {:ok, query_transformed} <- Keyword.fetch(opts, :query_transformed), {:ok, query_parsed} <- Keyword.fetch(opts, :query_parsed), - {:ok, data} <- fetch_initial_data(env_id, coll, query_transformed), {:ok, projection} <- Keyword.fetch(opts, :projection), - {:ok, options} <- Keyword.fetch(opts, :options) do + {:ok, options} <- Keyword.fetch(opts, :options), + {:ok, data} <- fetch_initial_data(env_id, coll, query_transformed, projection, options) do projection_data = if projection != %{} do %{projection => projection_data(data, projection)} @@ -121,20 +121,28 @@ defmodule ApplicationRunner.Environment.QueryServer do Map.values(map_data) end - defp fetch_initial_data(_env_id, coll, query_transformed) + defp fetch_initial_data(_env_id, coll, query_transformed, projection, options) when is_nil(coll) or is_nil(query_transformed) do Logger.debug("#{__MODULE__} fetch_initial_data with nil query") {:ok, []} end - defp fetch_initial_data(env_id, coll, query_transformed) do + defp fetch_initial_data(env_id, coll, query_transformed, projection, options) do Logger.debug("#{__MODULE__} fetch_initial_data with data: #{inspect([env_id, coll, query_transformed])}") + mongo_opts = + Keyword.merge( + # [projection: projection], + [], + Enum.map(options, fn {k, v} -> {String.to_atom(k), v} end) + ) + MongoInstance.run_mongo_task(env_id, MongoStorage, :filter_docs, [ env_id, coll, - query_transformed + query_transformed, + mongo_opts ]) end From 38f794c13fd8533534d392cb79434ca0f872b928 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 29 Feb 2024 16:33:25 +0100 Subject: [PATCH 13/22] todo --- .../lib/environment/query_server.ex | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index 44f6e9cf..4976cbe0 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -428,14 +428,16 @@ defmodule ApplicationRunner.Environment.QueryServer do if projection_change?(projection_data, new_data, k) do {k, v} else - group = ViewServer.group_name(env_id, coll, query_parsed, k) + # TODO: Check that the options are properly handled, we might want to get the options from the state + group = ViewServer.group_name(env_id, coll, query_parsed, k, %{}) Swarm.publish(group, {:data_changed, projection_data(new_data, k)}) {k, projection_data(new_data, k)} end end) # Notify ViewServer with no projection. - group = ViewServer.group_name(env_id, coll, query_parsed, %{}) + # TODO: Check that the options are properly handled, we might want to get the options from the state + group = ViewServer.group_name(env_id, coll, query_parsed, %{}, %{}) Swarm.publish(group, {:data_changed, new_data}) new_projection_data @@ -451,11 +453,13 @@ defmodule ApplicationRunner.Environment.QueryServer do } ) do Enum.each(Map.keys(projection_data), fn projection_key -> - group = ViewServer.group_name(env_id, old_coll, query_parsed, projection_key) + # TODO: Check that the options are properly handled, we might want to get the options from the state + group = ViewServer.group_name(env_id, old_coll, query_parsed, projection_key, %{}) Swarm.publish(group, {:coll_changed, new_coll}) end) - group = ViewServer.group_name(env_id, old_coll, query_parsed, %{}) + # TODO: Check that the options are properly handled, we might want to get the options from the state + group = ViewServer.group_name(env_id, old_coll, query_parsed, %{}, %{}) Swarm.publish(group, {:coll_changed, new_coll}) end From 43a436fc4ffbb42608f661fc1d188b97b71b9b15 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Fri, 1 Mar 2024 10:19:38 +0100 Subject: [PATCH 14/22] Update components api --- libs/application_runner/priv/components-api | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/application_runner/priv/components-api b/libs/application_runner/priv/components-api index c5905611..cbe257da 160000 --- a/libs/application_runner/priv/components-api +++ b/libs/application_runner/priv/components-api @@ -1 +1 @@ -Subproject commit c5905611c941dd20da139c9a0d871f862657c325 +Subproject commit cbe257da5f729ec29556680cbb40e91685443677 From c07ead129aa7de41e9c00f7853274e539ff4f02c Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Fri, 1 Mar 2024 10:20:11 +0100 Subject: [PATCH 15/22] fix format --- libs/application_runner/lib/controllers/docs_controller.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index 8856ea69..35a993b5 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -255,7 +255,7 @@ defmodule ApplicationRunner.DocsController do IO.inspect("mongo_opts") IO.inspect(mongo_opts) - Logger.warning("mongo_opts #{inspect(mongo_opts)}"); + Logger.warning("mongo_opts #{inspect(mongo_opts)}") case MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, @@ -287,7 +287,7 @@ defmodule ApplicationRunner.DocsController do IO.inspect("find_deprecated") IO.inspect(filter) - Logger.warning("find_deprecated #{inspect(filter)}"); + Logger.warning("find_deprecated #{inspect(filter)}") with {:ok, docs} <- MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ From c459af234a21acd1dd238f56bbe2e0ddccc596f6 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Fri, 1 Mar 2024 11:01:52 +0100 Subject: [PATCH 16/22] Remove TODOs and inspects --- .../lib/controllers/docs_controller.ex | 10 ---------- .../application_runner/lib/environment/query_server.ex | 4 ---- 2 files changed, 14 deletions(-) diff --git a/libs/application_runner/lib/controllers/docs_controller.ex b/libs/application_runner/lib/controllers/docs_controller.ex index 35a993b5..bc16efdf 100644 --- a/libs/application_runner/lib/controllers/docs_controller.ex +++ b/libs/application_runner/lib/controllers/docs_controller.ex @@ -252,11 +252,6 @@ defmodule ApplicationRunner.DocsController do Enum.map(Map.get(commands, "options", %{}), fn {k, v} -> {String.to_atom(k), v} end) ) - IO.inspect("mongo_opts") - IO.inspect(mongo_opts) - - Logger.warning("mongo_opts #{inspect(mongo_opts)}") - case MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, coll, @@ -284,11 +279,6 @@ defmodule ApplicationRunner.DocsController do "This form of query is deprecated, prefer using: {query: , projection: {projection}}, more info at: https://www.mongodb.com/docs/manual/reference/method/db.collection.find/#mongodb-method-db.collection.find" ) - IO.inspect("find_deprecated") - IO.inspect(filter) - - Logger.warning("find_deprecated #{inspect(filter)}") - with {:ok, docs} <- MongoInstance.run_mongo_task(env.id, MongoStorage, :filter_docs, [ env.id, diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index 4976cbe0..ba2b4b2c 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -428,7 +428,6 @@ defmodule ApplicationRunner.Environment.QueryServer do if projection_change?(projection_data, new_data, k) do {k, v} else - # TODO: Check that the options are properly handled, we might want to get the options from the state group = ViewServer.group_name(env_id, coll, query_parsed, k, %{}) Swarm.publish(group, {:data_changed, projection_data(new_data, k)}) {k, projection_data(new_data, k)} @@ -436,7 +435,6 @@ defmodule ApplicationRunner.Environment.QueryServer do end) # Notify ViewServer with no projection. - # TODO: Check that the options are properly handled, we might want to get the options from the state group = ViewServer.group_name(env_id, coll, query_parsed, %{}, %{}) Swarm.publish(group, {:data_changed, new_data}) @@ -453,12 +451,10 @@ defmodule ApplicationRunner.Environment.QueryServer do } ) do Enum.each(Map.keys(projection_data), fn projection_key -> - # TODO: Check that the options are properly handled, we might want to get the options from the state group = ViewServer.group_name(env_id, old_coll, query_parsed, projection_key, %{}) Swarm.publish(group, {:coll_changed, new_coll}) end) - # TODO: Check that the options are properly handled, we might want to get the options from the state group = ViewServer.group_name(env_id, old_coll, query_parsed, %{}, %{}) Swarm.publish(group, {:coll_changed, new_coll}) end From 448239749de37170ccdfec91eb42105faa3de86f Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Fri, 1 Mar 2024 11:03:46 +0100 Subject: [PATCH 17/22] Add projection in mongo_opts --- libs/application_runner/lib/environment/query_server.ex | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/application_runner/lib/environment/query_server.ex b/libs/application_runner/lib/environment/query_server.ex index ba2b4b2c..9d97187c 100644 --- a/libs/application_runner/lib/environment/query_server.ex +++ b/libs/application_runner/lib/environment/query_server.ex @@ -133,8 +133,7 @@ defmodule ApplicationRunner.Environment.QueryServer do mongo_opts = Keyword.merge( - # [projection: projection], - [], + [projection: projection], Enum.map(options, fn {k, v} -> {String.to_atom(k), v} end) ) From b0ed9e53a43c3c2549d54309478e486e8278dbef Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Fri, 1 Mar 2024 11:21:16 +0100 Subject: [PATCH 18/22] fix test --- libs/application_runner/test/environment/view_dyn_sup_test.exs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/application_runner/test/environment/view_dyn_sup_test.exs b/libs/application_runner/test/environment/view_dyn_sup_test.exs index c12804d0..9bc43bee 100644 --- a/libs/application_runner/test/environment/view_dyn_sup_test.exs +++ b/libs/application_runner/test/environment/view_dyn_sup_test.exs @@ -76,7 +76,8 @@ defmodule ApplicationRunner.Environment.ViewDynSupTest do query_transformed: %{}, props: %{}, context: %{}, - projection: %{} + projection: %{}, + options: %{} } assert :undefined != Swarm.whereis_name(Environment.ViewDynSup.get_name(env_id)) From cc4856bdbe68e05574c3b5db5b993c76d69a5b17 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Thu, 7 Mar 2024 14:35:57 +0100 Subject: [PATCH 19/22] Fix tests --- .../test/environment/query_server_test.exs | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/libs/application_runner/test/environment/query_server_test.exs b/libs/application_runner/test/environment/query_server_test.exs index 1c2575f3..6a3e6553 100644 --- a/libs/application_runner/test/environment/query_server_test.exs +++ b/libs/application_runner/test/environment/query_server_test.exs @@ -181,6 +181,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -195,6 +196,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -220,6 +222,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, + %{}, %{} ) @@ -240,6 +243,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -253,6 +257,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, + %{}, %{} ) @@ -262,10 +267,11 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, + %{}, %{} ) - {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "foo", Parser.parse!("{}"), %{}, %{}) + {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "foo", Parser.parse!("{}"), %{}, %{}, %{}) QueryServer.join_group(pid1, "42") QueryServer.join_group(pid1, "43") @@ -288,6 +294,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -297,6 +304,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) end @@ -308,6 +316,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -323,6 +332,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -356,6 +366,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -392,15 +403,16 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{"name" => true} + %{"name" => true}, + %{} ) # View server with no projection - Swarm.join(ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}), self()) + Swarm.join(ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}), self()) # View server with projection Swarm.join( - ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{"name" => true}), + ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{"name" => true}, %{}), self() ) @@ -439,6 +451,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -461,6 +474,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -480,6 +494,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -508,6 +523,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -533,6 +549,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -557,27 +574,28 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, + %{}, %{} ) q2 = %{"idx" => 1} eq2 = Jason.encode!(q2) - {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq2), %{}, %{}) + {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq2), %{}, %{}, %{}) QueryServer.join_group(pid1, "42") QueryServer.join_group(pid2, "42") # BOTH process in Group 1 should receive the change event - group1 = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}) + group1 = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}) # Group 1 should NOT receive the change event (wrong env_id) - group2 = ViewServer.group_name(@env_id + 1, "test", Parser.parse!("{}"), %{}) + group2 = ViewServer.group_name(@env_id + 1, "test", Parser.parse!("{}"), %{}, %{}) # Group 1 should NOT receive the change event (wrong coll) - group3 = ViewServer.group_name(@env_id, "test1", Parser.parse!("{}"), %{}) + group3 = ViewServer.group_name(@env_id, "test1", Parser.parse!("{}"), %{}, %{}) # Group 1 should NOT receive the change event (query does not match) - group4 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"aaaa\": 1}"), %{}) + group4 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"aaaa\": 1}"), %{}, %{}) # Group 1 should receive the change event (query match) - group5 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"idx\": 1}"), %{}) + group5 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"idx\": 1}"), %{}, %{}) p1 = spawn_pass_process(:a1) p1b = spawn_pass_process(:a1b) @@ -610,6 +628,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -627,7 +646,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do test "should NOT insert data if the query does not match the new element" do q = %{"idx" => %{"$lt" => 3}} eq = Jason.encode!(q) - {:ok, _} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq), q, %{}) + {:ok, _} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq), q, %{}, %{}) name = QueryServer.get_full_name({@env_id, "test", Parser.parse!(eq)}) @@ -650,6 +669,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -677,6 +697,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -707,6 +728,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!(eq), Parser.replace_params(q, %{}), + %{}, %{} ) @@ -736,6 +758,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -763,6 +786,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -793,6 +817,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!(eq), q, + %{}, %{} ) @@ -822,6 +847,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -849,6 +875,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -876,6 +903,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -905,6 +933,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -920,6 +949,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) @@ -937,14 +967,15 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) name = QueryServer.get_name({@env_id, "test", Parser.parse!("{}")}) new_name = QueryServer.get_name({@env_id, "bar", Parser.parse!("{}")}) - group = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}) - new_group = ViewServer.group_name(@env_id, "bar", Parser.parse!("{}"), %{}) + group = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}) + new_group = ViewServer.group_name(@env_id, "bar", Parser.parse!("{}"), %{}, %{}) p1 = spawn_pass_process(:p1) p2 = spawn_pass_process(:p2) Swarm.join(group, p1) @@ -977,6 +1008,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), + %{}, %{} ) From 8882b17dd896f28c1beb362c400309bde21d7fa1 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Mon, 8 Apr 2024 11:34:56 +0200 Subject: [PATCH 20/22] fix test ? --- .../lib/environment/query_dyn_sup.ex | 2 +- .../test/environment/query_server_test.exs | 34 +------------------ 2 files changed, 2 insertions(+), 34 deletions(-) diff --git a/libs/application_runner/lib/environment/query_dyn_sup.ex b/libs/application_runner/lib/environment/query_dyn_sup.ex index 3020ae5f..176588f3 100644 --- a/libs/application_runner/lib/environment/query_dyn_sup.ex +++ b/libs/application_runner/lib/environment/query_dyn_sup.ex @@ -31,7 +31,7 @@ defmodule ApplicationRunner.Environment.QueryDynSup do @spec ensure_child_started(term(), String.t() | nil, map() | nil, map() | nil, map(), map()) :: {:ok, pid()} | {:error, term()} - def ensure_child_started(env_id, coll, query_parsed, query_transformed, projection, options) do + def ensure_child_started(env_id, coll, query_parsed, query_transformed, projection, options \\ %{}) do Logger.debug( "#{__MODULE__} ensure query server started for #{inspect([env_id, coll, query_parsed, query_transformed])}" ) diff --git a/libs/application_runner/test/environment/query_server_test.exs b/libs/application_runner/test/environment/query_server_test.exs index 6a3e6553..2e685562 100644 --- a/libs/application_runner/test/environment/query_server_test.exs +++ b/libs/application_runner/test/environment/query_server_test.exs @@ -181,7 +181,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -196,7 +195,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -222,7 +220,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{}, %{} ) @@ -243,7 +240,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -257,7 +253,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{}, %{} ) @@ -267,7 +262,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{}, %{} ) @@ -294,7 +288,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -304,7 +297,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) end @@ -316,7 +308,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -332,7 +323,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -366,7 +356,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -403,8 +392,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{"name" => true}, - %{} + %{"name" => true} ) # View server with no projection @@ -451,7 +439,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -474,7 +461,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -494,7 +480,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -523,7 +508,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -549,7 +533,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -574,7 +557,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), %{}, - %{}, %{} ) @@ -628,7 +610,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -669,7 +650,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -697,7 +677,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -728,7 +707,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!(eq), Parser.replace_params(q, %{}), - %{}, %{} ) @@ -758,7 +736,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -786,7 +763,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -817,7 +793,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!(eq), q, - %{}, %{} ) @@ -847,7 +822,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -875,7 +849,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -903,7 +876,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -933,7 +905,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -949,7 +920,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -967,7 +937,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) @@ -1008,7 +977,6 @@ defmodule ApplicationRunner.Environment.QueryServerTest do "test", Parser.parse!("{}"), Parser.replace_params(%{}, %{}), - %{}, %{} ) From ed8828e20aeed368d7af83c8c977285cb066355d Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Mon, 8 Apr 2024 11:37:19 +0200 Subject: [PATCH 21/22] Fix --- .../test/environment/query_server_test.exs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libs/application_runner/test/environment/query_server_test.exs b/libs/application_runner/test/environment/query_server_test.exs index 2e685562..1c2575f3 100644 --- a/libs/application_runner/test/environment/query_server_test.exs +++ b/libs/application_runner/test/environment/query_server_test.exs @@ -265,7 +265,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do %{} ) - {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "foo", Parser.parse!("{}"), %{}, %{}, %{}) + {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "foo", Parser.parse!("{}"), %{}, %{}) QueryServer.join_group(pid1, "42") QueryServer.join_group(pid1, "43") @@ -396,11 +396,11 @@ defmodule ApplicationRunner.Environment.QueryServerTest do ) # View server with no projection - Swarm.join(ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}), self()) + Swarm.join(ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}), self()) # View server with projection Swarm.join( - ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{"name" => true}, %{}), + ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{"name" => true}), self() ) @@ -563,21 +563,21 @@ defmodule ApplicationRunner.Environment.QueryServerTest do q2 = %{"idx" => 1} eq2 = Jason.encode!(q2) - {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq2), %{}, %{}, %{}) + {:ok, pid2} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq2), %{}, %{}) QueryServer.join_group(pid1, "42") QueryServer.join_group(pid2, "42") # BOTH process in Group 1 should receive the change event - group1 = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}) + group1 = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}) # Group 1 should NOT receive the change event (wrong env_id) - group2 = ViewServer.group_name(@env_id + 1, "test", Parser.parse!("{}"), %{}, %{}) + group2 = ViewServer.group_name(@env_id + 1, "test", Parser.parse!("{}"), %{}) # Group 1 should NOT receive the change event (wrong coll) - group3 = ViewServer.group_name(@env_id, "test1", Parser.parse!("{}"), %{}, %{}) + group3 = ViewServer.group_name(@env_id, "test1", Parser.parse!("{}"), %{}) # Group 1 should NOT receive the change event (query does not match) - group4 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"aaaa\": 1}"), %{}, %{}) + group4 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"aaaa\": 1}"), %{}) # Group 1 should receive the change event (query match) - group5 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"idx\": 1}"), %{}, %{}) + group5 = ViewServer.group_name(@env_id, "test", Parser.parse!("{\"idx\": 1}"), %{}) p1 = spawn_pass_process(:a1) p1b = spawn_pass_process(:a1b) @@ -627,7 +627,7 @@ defmodule ApplicationRunner.Environment.QueryServerTest do test "should NOT insert data if the query does not match the new element" do q = %{"idx" => %{"$lt" => 3}} eq = Jason.encode!(q) - {:ok, _} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq), q, %{}, %{}) + {:ok, _} = QueryDynSup.ensure_child_started(@env_id, "test", Parser.parse!(eq), q, %{}) name = QueryServer.get_full_name({@env_id, "test", Parser.parse!(eq)}) @@ -943,8 +943,8 @@ defmodule ApplicationRunner.Environment.QueryServerTest do name = QueryServer.get_name({@env_id, "test", Parser.parse!("{}")}) new_name = QueryServer.get_name({@env_id, "bar", Parser.parse!("{}")}) - group = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}, %{}) - new_group = ViewServer.group_name(@env_id, "bar", Parser.parse!("{}"), %{}, %{}) + group = ViewServer.group_name(@env_id, "test", Parser.parse!("{}"), %{}) + new_group = ViewServer.group_name(@env_id, "bar", Parser.parse!("{}"), %{}) p1 = spawn_pass_process(:p1) p2 = spawn_pass_process(:p2) Swarm.join(group, p1) From e487ad3c8525118308a8a64bdb6d906c39b9c854 Mon Sep 17 00:00:00 2001 From: "jonas.martinez" Date: Mon, 8 Apr 2024 11:42:13 +0200 Subject: [PATCH 22/22] Add more default values --- libs/application_runner/lib/environment/view_server.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/application_runner/lib/environment/view_server.ex b/libs/application_runner/lib/environment/view_server.ex index ae7c649a..d43b0900 100644 --- a/libs/application_runner/lib/environment/view_server.ex +++ b/libs/application_runner/lib/environment/view_server.ex @@ -10,11 +10,11 @@ defmodule ApplicationRunner.Environment.ViewServer do require Logger - def group_name(env_id, coll, query, projection, options) do + def group_name(env_id, coll, query, projection, options \\ %{}) do {__MODULE__, env_id, coll, query, projection, options} end - def join_group(pid, env_id, coll, query, projection, options) do + def join_group(pid, env_id, coll, query, projection, options \\ %{}) do group = group_name(env_id, coll, query, projection, options) Swarm.join(group, pid) end