Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLClock as part of Maestro #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: elixir
elixir:
- 1.7.0
- 1.9.0
otp_release:
- 21.0

Expand Down
4 changes: 2 additions & 2 deletions lib/maestro/aggregate/root.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ defmodule Maestro.Aggregate.Root do
end

def new do
with {:ok, agg_id} <- HLClock.now() do
with {:ok, agg_id} <- HLClock.now(:maestro_hlc) do
Root.whereis(agg_id, __MODULE__)
{:ok, agg_id}
end
Expand Down Expand Up @@ -359,7 +359,7 @@ defmodule Maestro.Aggregate.Root do
events
|> Enum.with_index(agg.sequence + 1)
|> Enum.reduce([], fn {event, seq}, evs ->
with {:ok, ts} <- HLClock.now() do
with {:ok, ts} <- HLClock.now(:maestro_hlc) do
[%{event | timestamp: ts, sequence: seq} | evs]
end
end)
Expand Down
1 change: 1 addition & 0 deletions lib/maestro/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Maestro.Application do

def start(_type, _args) do
children = [
{HLClock, name: :maestro_hlc},
{Registry, keys: :unique, name: Maestro.Aggregate.Registry},
{Maestro.Aggregate.Supervisor, []}
]
Expand Down
4 changes: 2 additions & 2 deletions lib/maestro/types/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ defmodule Maestro.Types.Event do

@primary_key false
schema "event_log" do
field(:timestamp, Ecto.HLClock, primary_key: true)
field(:aggregate_id, Ecto.HLClock)
field(:timestamp, EctoHLClock, primary_key: true)
field(:aggregate_id, EctoHLClock)
field(:sequence, :integer)
field(:type, :string)
field(:body, :map)
Expand Down
2 changes: 1 addition & 1 deletion lib/maestro/types/snapshot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Maestro.Types.Snapshot do

@primary_key false
schema "snapshots" do
field(:aggregate_id, Ecto.HLClock, primary_key: true)
field(:aggregate_id, EctoHLClock, primary_key: true)
field(:sequence, :integer)
field(:body, :map)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/mix/tasks/maestro.create.event_store_migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ defmodule Mix.Tasks.Maestro.Create.EventStoreMigration do
add :body, :map, null: false
end

Ecto.HLClock.Migration.create_hlc_constraint(:event_log, :timestamp)
Ecto.HLClock.Migration.create_hlc_constraint(:event_log, :aggregate_id)
Ecto.HLClock.Migration.create_hlc_constraint(:snapshots, :aggregate_id)
EctoHLClock.Migration.create_hlc_constraint(:event_log, :timestamp)
EctoHLClock.Migration.create_hlc_constraint(:event_log, :aggregate_id)
EctoHLClock.Migration.create_hlc_constraint(:snapshots, :aggregate_id)

create constraint(:event_log, :sequence, check: "sequence > 0")
create unique_index(:event_log, [:aggregate_id, :sequence],
Expand Down
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
defmodule Maestro.Mixfile do
use Mix.Project

@version "0.3.4"
@version "0.4.0"
@source_url "https://github.com/toniqsystems/maestro"

def project do
[
app: :maestro,
version: @version,
elixir: "~> 1.7",
elixir: "~> 1.9",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
Expand Down Expand Up @@ -44,10 +44,10 @@ defmodule Maestro.Mixfile do

defp deps do
[
{:ecto, "~> 3.0"},
{:ecto_sql, "~> 3.0"},
{:ecto, "~> 3.2"},
{:ecto_sql, "~> 3.2"},
{:postgrex, ">= 0.0.0"},
{:ecto_hlclock, "~> 0.1"},
{:ecto_hlclock, "~> 0.2"},
{:jason, "~> 1.1"},
{:mock, "~> 0.3", only: :test, runtime: false},
{:credo, "~> 1.0", only: [:dev, :test]},
Expand Down
34 changes: 17 additions & 17 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"credo": {:hex, :credo, "1.0.5", "fdea745579f8845315fe6a3b43e2f9f8866839cfbc8562bb72778e9fdaa94214", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "2.0.5", "ddb2ba6761a08b2bb9ca0e7d260e8f4dd39067426d835c24491a321b7f92a4da", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.7.0", "30d6b52c88541f9a66637359ddf85016df9eb266170d53105f02e4a67e00c5aa", [:mix], [], "hexpm"},
"credo": {:hex, :credo, "1.1.4", "c2f3b73c895d81d859cec7fcee7ffdb972c595fd8e85ab6f8c2adbf01cf7c29c", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"db_connection": {:hex, :db_connection, "2.1.1", "a51e8a2ee54ef2ae6ec41a668c85787ed40cb8944928c191280fe34c15b76ae5", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm"},
"decimal": {:hex, :decimal, "1.8.0", "ca462e0d885f09a1c5a342dbd7c1dcf27ea63548c65a65e67334f4b61803822e", [:mix], [], "hexpm"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm"},
"dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.3.2", "b840562ea3d67795ffbb5bd88940b1bed0ed9fa32834915125ea7d02e35888a5", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.0.7", "44dda84ac6b17bbbdeb8ac5dfef08b7da253b37a453c34ab1a98de7f7e5fec7f", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_hlclock": {:hex, :ecto_hlclock, "0.1.2", "432f8f71cd3e426884a64ddba7762d2a61c4bff2707e2e46d30f6c9599c8d2a1", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:hlclock, "~> 0.1", [hex: :hlclock, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.0.5", "7e44172b4f7aca4469f38d7f6a3da394dbf43a1bcf0ca975e958cb957becd74e", [:mix], [{:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.0.6", [hex: :ecto, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.9.1", [hex: :mariaex, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.14.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.3.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.20.2", "1bd0dfb0304bade58beb77f20f21ee3558cc3c753743ae0ddbb0fd7ba2912331", [:mix], [{:earmark, "~> 1.3", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.10", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.10.6", "e2b9718c9d8e3ef90bc22278c3f76c850a9f9116faf4ebe9678063310742edc2", [:mix], [{:hackney, "~> 1.13", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"earmark": {:hex, :earmark, "1.4.1", "07bb382826ee8d08d575a1981f971ed41bd5d7e86b917fd012a93c51b5d28727", [:mix], [], "hexpm"},
"ecto": {:hex, :ecto, "3.2.2", "bb6d1dbcd7ef975b60637e63182e56f3d7d0b5dd9c46d4b9d6183a5c455d65d1", [:mix], [{:decimal, "~> 1.6", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ecto_hlclock": {:hex, :ecto_hlclock, "0.2.0", "7c0e0ddbf252dda8de91eabae28345e990742588aba063fdcdcfc97cbc7e95c7", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:hlclock, "~> 1.0", [hex: :hlclock, repo: "hexpm", optional: false]}], "hexpm"},
"ecto_sql": {:hex, :ecto_sql, "3.2.0", "751cea597e8deb616084894dd75cbabfdbe7255ff01e8c058ca13f0353a3921b", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.2.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.2.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"excoveralls": {:hex, :excoveralls, "0.11.2", "0c6f2c8db7683b0caa9d490fb8125709c54580b4255ffa7ad35f3264b075a643", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
"exjsx": {:hex, :exjsx, "4.0.0", "60548841e0212df401e38e63c0078ec57b33e7ea49b032c796ccad8cde794b5c", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.1", "9f8f471c844b8ce395f7b6d8398139e26ddca9ebc171a8b91342ee15a19963f4", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.4", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"hlclock": {:hex, :hlclock, "0.1.6", "ca4de3f8b3eb410e29de8273cb060a265fe89d5498a272efc58619753764d0c7", [:mix], [], "hexpm"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"hlclock": {:hex, :hlclock, "1.0.0", "7a72fc7a20a9382499216227edf97a8b118e21fc3fcad0e81b8d10c616ce1431", [:mix], [], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"jsx": {:hex, :jsx, "2.8.3", "a05252d381885240744d955fbe3cf810504eb2567164824e19303ea59eef62cf", [:mix, :rebar3], [], "hexpm"},
"makeup": {:hex, :makeup, "0.8.0", "9cf32aea71c7fe0a4b2e9246c2c4978f9070257e5c9ce6d4a28ec450a839b55f", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.13.0", "be7a477997dcac2e48a9d695ec730b2d22418292675c75aa2d34ba0909dcdeda", [:mix], [{:makeup, "~> 0.8", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"makeup": {:hex, :makeup, "1.0.0", "671df94cf5a594b739ce03b0d0316aa64312cee2574b6a44becb83cd90fb05dc", [:mix], [{:nimble_parsec, "~> 0.5.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"meck": {:hex, :meck, "0.8.13", "ffedb39f99b0b99703b8601c6f17c7f76313ee12de6b646e671e3188401f7866", [:rebar3], [], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"mock": {:hex, :mock, "0.3.3", "42a433794b1291a9cf1525c6d26b38e039e0d3a360732b5e467bfc77ef26c914", [:mix], [{:meck, "~> 0.8.13", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.0", "90e2eca3d0266e5c53f8fbe0079694740b9c91b6747f2b7e3c5d21966bba8300", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.14.1", "63247d4a5ad6b9de57a0bac5d807e1c32d41e39c04b8a4156a26c63bcd8a2e49", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.15.1", "23ce3417de70f4c0e9e7419ad85bdabcc6860a6925fe2c6f3b1b5b1e8e47bf2f", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.5", "6eaf7ad16cb568bb01753dbbd7a95ff8b91c7979482b95f38443fe2c8852a79b", [:make, :mix, :rebar3], [], "hexpm"},
"stream_data": {:hex, :stream_data, "0.4.2", "fa86b78c88ec4eaa482c0891350fcc23f19a79059a687760ddcf8680aac2799b", [:mix], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.3.0", "099a7f3ce31e4780f971b4630a3c22ec66d22208bc090fe33a2a3a6a67754a73", [:rebar3], [], "hexpm"},
"telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"},
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ defmodule Maestro.Repo.Migrations.EventLogAndSnapshots do
add :body, :map, null: false
end

Ecto.HLClock.Migration.create_hlc_constraint(:event_log, :timestamp)
Ecto.HLClock.Migration.create_hlc_constraint(:event_log, :aggregate_id)
EctoHLClock.Migration.create_hlc_constraint(:event_log, :timestamp)
EctoHLClock.Migration.create_hlc_constraint(:event_log, :aggregate_id)

create constraint(:event_log, :sequence, check: "sequence > 0")
create unique_index(:event_log, [:aggregate_id, :sequence],
Expand All @@ -23,6 +23,6 @@ defmodule Maestro.Repo.Migrations.EventLogAndSnapshots do
add :body, :map, null: false
end

Ecto.HLClock.Migration.create_hlc_constraint(:snapshots, :aggregate_id)
EctoHLClock.Migration.create_hlc_constraint(:snapshots, :aggregate_id)
end
end
2 changes: 1 addition & 1 deletion priv/repo/migrations/20180423183715_named_aggregates.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule Maestro.Repo.Migrations.NamedAggregates do
add(:aggregate_id, :binary, null: false)
end

Ecto.HLClock.Migration.create_hlc_constraint(
EctoHLClock.Migration.create_hlc_constraint(
:named_aggregates,
:aggregate_id
)
Expand Down
9 changes: 4 additions & 5 deletions test/maestro/aggregate_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ defmodule Maestro.AggregateTest do

alias DBConnection.ConnectionError
alias Ecto.Adapters.SQL.Sandbox
alias HLClock.Server, as: HLCServer
alias Maestro.Aggregate.Root
alias Maestro.{InvalidCommandError, InvalidHandlerError}
alias Maestro.{Repo, SampleAggregate}
Expand All @@ -21,8 +20,6 @@ defmodule Maestro.AggregateTest do
Maestro.Store.Postgres
)

HLCServer.start_link()

:ok = Sandbox.checkout(Repo)
Sandbox.mode(Repo, {:shared, self()})

Expand All @@ -31,8 +28,10 @@ defmodule Maestro.AggregateTest do

describe "command/event lifecycle" do
property "commands and events without snapshots" do
check all agg_id <- timestamp(),
coms <- commands(agg_id, max_commands: 200) do
check all(
agg_id <- timestamp(),
coms <- commands(agg_id, max_commands: 200)
) do
for com <- coms do
:ok = SampleAggregate.evaluate(com)
end
Expand Down
48 changes: 30 additions & 18 deletions test/maestro/in_memory_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ defmodule Maestro.InMemoryTest do

describe "commit_events/1" do
property "no conflict events are committed" do
check all agg_id <- timestamp(),
times <-
uniq_list_of(
timestamp(),
min_length: 1,
max_length: 10
) do
check all(
agg_id <- timestamp(),
times <-
uniq_list_of(
timestamp(),
min_length: 1,
max_length: 10
)
) do
InMemory.reset()

times
Expand All @@ -47,9 +49,11 @@ defmodule Maestro.InMemoryTest do
end

property "sequence conflicts are marked for retry" do
check all agg_id <- timestamp(),
ts0 <- timestamp(),
times <- uniq_list_of(timestamp(), min_length: 1) do
check all(
agg_id <- timestamp(),
ts0 <- timestamp(),
times <- uniq_list_of(timestamp(), min_length: 1)
) do
InMemory.reset()

times
Expand All @@ -71,8 +75,10 @@ defmodule Maestro.InMemoryTest do

describe "get_events/2" do
property "returns empty list when no relevant events exist" do
check all agg_id <- timestamp(),
times <- uniq_list_of(timestamp()) do
check all(
agg_id <- timestamp(),
times <- uniq_list_of(timestamp())
) do
InMemory.reset()

times
Expand All @@ -85,8 +91,10 @@ defmodule Maestro.InMemoryTest do
end

property "returns events otherwise" do
check all agg_id <- timestamp(),
times <- uniq_list_of(timestamp(), min_length: 1) do
check all(
agg_id <- timestamp(),
times <- uniq_list_of(timestamp(), min_length: 1)
) do
InMemory.reset()

total = Enum.count(times)
Expand All @@ -111,8 +119,10 @@ defmodule Maestro.InMemoryTest do

describe "commit_snapshot/1" do
property "commits if newer" do
check all agg_id <- timestamp(),
[seq0, seq1] <- uniq_list_of(integer(1..100_000), length: 2) do
check all(
agg_id <- timestamp(),
[seq0, seq1] <- uniq_list_of(integer(1..100_000), length: 2)
) do
InMemory.reset()

agg_id
Expand All @@ -131,8 +141,10 @@ defmodule Maestro.InMemoryTest do

describe "get_snapshot/2" do
property "retrieve if newer" do
check all agg_id <- timestamp(),
[seq0, seq1] <- uniq_list_of(integer(1..100_000), length: 2) do
check all(
agg_id <- timestamp(),
[seq0, seq1] <- uniq_list_of(integer(1..100_000), length: 2)
) do
InMemory.reset()

agg_id
Expand Down