Skip to content

Commit

Permalink
Prepare for next Commanded release
Browse files Browse the repository at this point in the history
  • Loading branch information
slashdotdash committed Oct 11, 2018
1 parent aa9375b commit 7f826f3
Show file tree
Hide file tree
Showing 13 changed files with 160 additions and 70 deletions.
6 changes: 6 additions & 0 deletions .formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
inputs: [
"lib/*/{lib,test}/**/*.{ex,exs}",
"lib/*/mix.exs"
]
]
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
language: elixir

elixir:
- 1.5.2
- 1.7.3

otp_release:
- 20.1
- 21.0

services:
- postgresql
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Next release

### Enhancements

- Support for Commanded's next release.

## v0.4.0

### Enhancements
Expand Down
5 changes: 2 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use Mix.Config

config :commanded,
event_store_adapter: Commanded.EventStore.Adapters.EventStore
config :commanded, event_store_adapter: Commanded.EventStore.Adapters.EventStore

import_config "#{Mix.env}.exs"
import_config "#{Mix.env()}.exs"
63 changes: 36 additions & 27 deletions lib/event_store_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,41 @@ defmodule Commanded.EventStore.Adapters.EventStore do

alias Commanded.EventStore.{EventData, RecordedEvent, SnapshotData}

@spec append_to_stream(String.t(), non_neg_integer, list(EventData.t())) ::
{:ok, non_neg_integer} | {:error, reason :: term}
@impl Commanded.EventStore
def child_spec, do: []

@impl Commanded.EventStore
def append_to_stream(stream_uuid, expected_version, events) do
case EventStore.append_to_stream(
stream_uuid,
expected_version,
Enum.map(events, &to_event_data(&1))
) do
:ok -> {:ok, expected_version + length(events)}
err -> err
end
EventStore.append_to_stream(
stream_uuid,
expected_version,
Enum.map(events, &to_event_data/1)
)
end

@spec stream_forward(String.t(), non_neg_integer, non_neg_integer) ::
Enumerable.t() | {:error, reason :: term}
@impl Commanded.EventStore
def stream_forward(stream_uuid, start_version \\ 0, read_batch_size \\ 1_000)

def stream_forward(stream_uuid, start_version, read_batch_size) do
case EventStore.stream_forward(stream_uuid, start_version, read_batch_size) do
{:error, reason} -> {:error, reason}
{:error, error} -> {:error, error}
stream -> Stream.map(stream, &from_recorded_event/1)
end
end

@spec subscribe(stream_uuid :: String.t()) :: :ok | {:error, term}
@impl Commanded.EventStore
def subscribe(stream_uuid)

def subscribe(:all), do: subscribe("$all")

def subscribe(stream_uuid) do
EventStore.subscribe(stream_uuid, mapper: &from_recorded_event/1)
end

@spec subscribe_to_all_streams(String.t(), pid, :origin | :current | integer) ::
{:ok, subscription :: any}
| {:error, :subscription_already_exists}
| {:error, reason :: term}
def subscribe_to_all_streams(subscription_name, subscriber, start_from \\ :origin)
@impl Commanded.EventStore
def subscribe_to(stream_uuid, subscription_name, subscriber, start_from \\ :origin)

def subscribe_to_all_streams(subscription_name, subscriber, start_from) do
def subscribe_to(:all, subscription_name, subscriber, start_from) do
EventStore.subscribe_to_all_streams(
subscription_name,
subscriber,
Expand All @@ -52,30 +51,40 @@ defmodule Commanded.EventStore.Adapters.EventStore do
)
end

@spec ack_event(pid, RecordedEvent.t()) :: :ok
def subscribe_to(stream_uuid, subscription_name, subscriber, start_from) do
EventStore.subscribe_to_stream(
stream_uuid,
subscription_name,
subscriber,
start_from: start_from,
mapper: &from_recorded_event/1
)
end

@impl Commanded.EventStore
def ack_event(subscription, %RecordedEvent{event_number: event_number}) do
EventStore.ack(subscription, event_number)
end

@spec unsubscribe_from_all_streams(String.t()) :: :ok
def unsubscribe_from_all_streams(subscription_name) do
EventStore.unsubscribe_from_all_streams(subscription_name)
@impl Commanded.EventStore
def unsubscribe(subscription) do
EventStore.Subscriptions.Subscription.unsubscribe(subscription)
end

@spec read_snapshot(String.t()) :: {:ok, SnapshotData.t()} | {:error, :snapshot_not_found}
@impl Commanded.EventStore
def read_snapshot(source_uuid) do
case EventStore.read_snapshot(source_uuid) do
{:ok, snapshot_data} -> {:ok, from_snapshot_data(snapshot_data)}
err -> err
end
end

@spec record_snapshot(SnapshotData.t()) :: :ok | {:error, reason :: term}
@impl Commanded.EventStore
def record_snapshot(%SnapshotData{} = snapshot) do
EventStore.record_snapshot(to_snapshot_data(snapshot))
end

@spec delete_snapshot(String.t()) :: :ok | {:error, reason :: term}
@impl Commanded.EventStore
def delete_snapshot(source_uuid) do
EventStore.delete_snapshot(source_uuid)
end
Expand Down
24 changes: 20 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do
app: :commanded_eventstore_adapter,
version: @version,
elixir: "~> 1.5",
elixirc_paths: elixirc_paths(Mix.env()),
description: description(),
docs: docs(),
package: package(),
Expand All @@ -26,12 +27,27 @@ defmodule Commanded.EventStore.Adapters.EventStore.Mixfile do
]
end

defp elixirc_paths(:test),
do: [
"deps/commanded/test/event_store",
"deps/commanded/test/support",
"lib",
"test/support"
]

defp elixirc_paths(_), do: ["lib", "test/helpers"]

defp deps do
[
{:commanded, ">= 0.16.0", runtime: false},
{:eventstore, ">= 0.14.0"},
{:ex_doc, "~> 0.17", only: :dev},
{:mix_test_watch, "~> 0.5", only: :dev}
# {:commanded, ">= 0.16.0", runtime: false},
{:commanded, github: "commanded/commanded", branch: "master", runtime: false},
# {:eventstore, ">= 0.14.0"},
{:eventstore, github: "commanded/eventstore", branch: "master"},

# Build & test tools
{:ex_doc, "~> 0.19", only: :dev},
{:mix_test_watch, "~> 0.9", only: :dev},
{:mox, "~> 0.4", only: :test}
]
end

Expand Down
23 changes: 14 additions & 9 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
%{
"commanded": {:hex, :commanded, "0.16.0", "10ab39952faf4af8bc0b077cce870f343e5e695b1e8cced4f425db66f651b048", [:mix], [{:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: true]}, {:poison, "~> 3.1", [hex: :poison, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"},
"commanded": {:git, "https://github.com/commanded/commanded.git", "0fd3758e5945f2bd8736619c48f212cc2bf552ad", [branch: "master"]},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm"},
"db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.5.0", "b0433a36d0e2430e3d50291b1c65f53c37d56f83665b43d79963684865beab68", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
"eventstore": {:hex, :eventstore, "0.14.0", "11ad4c888b9e5d635d789f39eca16d86185a1f463ad0eb66754f17b37b88ee9d", [:mix], [{:fsm, "~> 0.3", [hex: :fsm, repo: "hexpm", optional: false]}, {:gen_stage, "~> 0.13", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: false]}, {:uuid, "~> 1.1", [hex: :uuid, repo: "hexpm", optional: false]}], "hexpm"},
"ex_doc": {:hex, :ex_doc, "0.18.3", "f4b0e4a2ec6f333dccf761838a4b253d75e11f714b85ae271c9ae361367897b7", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.4", "f0bdda195c0e46e987333e986452ec523aed21d784189144f647c43eaf307064", [:mix], [], "hexpm"},
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
"elixir_uuid": {:hex, :elixir_uuid, "1.2.0", "ff26e938f95830b1db152cb6e594d711c10c02c6391236900ddd070a6b01271d", [:mix], [], "hexpm"},
"eventstore": {:git, "https://github.com/commanded/eventstore.git", "635ec6af6dfac067f172d3ca64d9b08c0044bff0", [branch: "master"]},
"ex_doc": {:hex, :ex_doc, "0.19.1", "519bb9c19526ca51d326c060cb1778d4a9056b190086a8c6c115828eaccea6cf", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.7", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm"},
"file_system": {:hex, :file_system, "0.2.6", "fd4dc3af89b9ab1dc8ccbcc214a0e60c41f34be251d9307920748a14bf41f1d3", [:mix], [], "hexpm"},
"fs": {:hex, :fs, "0.9.2", "ed17036c26c3f70ac49781ed9220a50c36775c6ca2cf8182d123b6566e49ec59", [:rebar], [], "hexpm"},
"fsm": {:hex, :fsm, "0.3.0", "d00e0a3c68f8cf8feb24ce3a732164638ec652c48ce416b66d4e375b6ee415eb", [:mix], [], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.13.1", "edff5bca9cab22c5d03a834062515e6a1aeeb7665fb44eddae086252e39c4378", [:mix], [], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.6.0", "5e206ed04860555a455de2983937efd3ce79f42bd8536fc6b900cc286f5bb830", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"},
"fsm": {:hex, :fsm, "0.3.1", "087aa9b02779a84320dc7a2d8464452b5308e29877921b2bde81cdba32a12390", [:mix], [], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.1", "9d46723fda072d4f4bb31a102560013f7960f5d80ea44dcb96fd6304ed61e7a4", [:mix], [], "hexpm"},
"makeup": {:hex, :makeup, "0.5.5", "9e08dfc45280c5684d771ad58159f718a7b5788596099bdfb0284597d368a882", [:mix], [{:nimble_parsec, "~> 0.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm"},
"makeup_elixir": {:hex, :makeup_elixir, "0.10.0", "0f09c2ddf352887a956d84f8f7e702111122ca32fbbc84c2f0569b8b65cbf7fa", [:mix], [{:makeup, "~> 0.5.5", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"mix_test_watch": {:hex, :mix_test_watch, "0.9.0", "c72132a6071261893518fa08e121e911c9358713f62794a90c95db59042af375", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm"},
"mox": {:hex, :mox, "0.4.0", "7f120840f7d626184a3d65de36189ca6f37d432e5d63acd80045198e4c5f7e6e", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"},
"poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"},
"postgrex": {:hex, :postgrex, "0.13.5", "3d931aba29363e1443da167a4b12f06dcd171103c424de15e5f3fc2ba3e6d9c5", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm"},
"uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"},
Expand Down
19 changes: 19 additions & 0 deletions test/event_store/append_events_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Commanded.EventStore.Adapters.EventStore.AppendEventsTest do
use Commanded.EventStore.AppendEventsTestCase

alias Commanded.EventStore.Adapters.EventStore.Storage

setup_all do
{:ok, conn} = Storage.connect()

[conn: conn]
end

setup %{conn: conn} do
on_exit(fn ->
Storage.reset!(conn)
end)

:ok
end
end
19 changes: 19 additions & 0 deletions test/event_store/snapshot_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule Commanded.EventStore.Adapters.EventStore.SnapshotTest do
use Commanded.EventStore.SnapshotTestCase

alias Commanded.EventStore.Adapters.EventStore.Storage

setup_all do
{:ok, conn} = Storage.connect()

[conn: conn]
end

setup %{conn: conn} do
on_exit(fn ->
Storage.reset!(conn)
end)

:ok
end
end
21 changes: 21 additions & 0 deletions test/event_store/subscription_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Commanded.EventStore.Adapters.EventStore.SubscriptionTest do
use Commanded.EventStore.SubscriptionTestCase

alias Commanded.EventStore.Adapters.EventStore.Storage

setup_all do
{:ok, conn} = Storage.connect()

[conn: conn]
end

setup %{conn: conn} do
on_exit(fn ->
Storage.reset!(conn)
end)

:ok
end

defp event_store_wait(_default \\ nil), do: 100
end
4 changes: 0 additions & 4 deletions test/event_store_adapter_test.exs

This file was deleted.

15 changes: 15 additions & 0 deletions test/support/storage.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule Commanded.EventStore.Adapters.EventStore.Storage do
def connect do
postgrex_config = EventStore.Config.parsed() |> EventStore.Config.default_postgrex_opts()

Postgrex.start_link(postgrex_config)
end

def reset!(conn) do
Application.stop(:eventstore)

EventStore.Storage.Initializer.reset!(conn)

Application.ensure_all_started(:eventstore)
end
end
21 changes: 0 additions & 21 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
ExUnit.start()

Mix.Task.run("event_store.create", ~w(--quiet))

# Configure this event store adapter for Commanded
Application.put_env(:commanded, :event_store_adapter, Commanded.EventStore.Adapters.EventStore)

postgrex_config = EventStore.Config.parsed() |> EventStore.Config.default_postgrex_opts()

{:ok, conn} = Postgrex.start_link(postgrex_config)

Application.put_env(:commanded, :stop_storage, fn ->
Application.stop(:eventstore)
end)

Application.put_env(:commanded, :reset_storage, fn ->
EventStore.Storage.Initializer.reset!(conn)

Application.ensure_all_started(:eventstore)

:ok
end)

0 comments on commit 7f826f3

Please sign in to comment.