Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .dialyzer_ignore.exs

This file was deleted.

2 changes: 0 additions & 2 deletions lib/event_store.ex
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,6 @@ defmodule EventStore do
|> Map.new()
end

defp pagination_metadata(_opts), do: %{}

defp telemetry_span(operation, opts, metadata, fun) do
Telemetry.span(operation, Telemetry.metadata(__MODULE__, opts, metadata), fun)
end
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ defmodule EventStore.Mixfile do

defp dialyzer do
[
ignore_warnings: ".dialyzer_ignore.exs",
plt_add_apps: [:ex_unit, :jason, :mix],
plt_add_deps: :app_tree,
plt_file: {:no_warn, "priv/plts/eventstore.plt"}
Expand Down
80 changes: 0 additions & 80 deletions test/manual/long_running_subscription.exs

This file was deleted.

10 changes: 0 additions & 10 deletions test/migrated_event_store_test.exs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
defmodule Event do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end

defmodule Snapshot do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end

defmodule EventStore.MigratedEventStoreTest do
use ExUnit.Case

Expand Down
16 changes: 8 additions & 8 deletions test/storage/append_events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ defmodule EventStore.Storage.AppendEventsTest do
events = EventFactory.create_recorded_events(3, stream_uuid)
:ok = Appender.append(conn, stream_id, events, append_opts(context))

for event <- events do
events = [%RecordedEvent{event | stream_version: 4}]
Enum.each(events, fn %RecordedEvent{} = event ->
duplicate_events = [%RecordedEvent{event | stream_version: 4}]

assert {:error, :duplicate_event} =
Appender.append(conn, stream_id, events, append_opts(context))
end
Appender.append(conn, stream_id, duplicate_events, append_opts(context))
end)
end

test "append existing events to a different stream should fail", context do
Expand All @@ -205,14 +205,14 @@ defmodule EventStore.Storage.AppendEventsTest do
events = EventFactory.create_recorded_events(3, stream1_uuid)
:ok = Appender.append(conn, stream1_id, events, append_opts(context))

for event <- events do
events = [
Enum.each(events, fn %RecordedEvent{} = event ->
duplicate_events = [
%RecordedEvent{event | stream_uuid: stream2_uuid, stream_version: 1}
]

assert {:error, :duplicate_event} =
Appender.append(conn, stream2_id, events, append_opts(context))
end
Appender.append(conn, stream2_id, duplicate_events, append_opts(context))
end)
end

test "append event to schema which does not exist", %{conn: conn} do
Expand Down
4 changes: 2 additions & 2 deletions test/storage/read_events_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule EventStore.Storage.ReadEventsTest do
test "without correlation_id", context do
{:ok, stream_uuid, stream_id} = create_stream(context)

[recorded_event] = EventFactory.create_recorded_events(1, stream_uuid)
[%RecordedEvent{} = recorded_event] = EventFactory.create_recorded_events(1, stream_uuid)

recorded_event = %RecordedEvent{recorded_event | correlation_id: nil}

Expand All @@ -49,7 +49,7 @@ defmodule EventStore.Storage.ReadEventsTest do
test "without causation_id", context do
{:ok, stream_uuid, stream_id} = create_stream(context)

[recorded_event] = EventFactory.create_recorded_events(1, stream_uuid)
[%RecordedEvent{} = recorded_event] = EventFactory.create_recorded_events(1, stream_uuid)

recorded_event = %RecordedEvent{recorded_event | causation_id: nil}

Expand Down
2 changes: 1 addition & 1 deletion test/support/event_factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ defmodule EventStore.EventFactory do

def deserialize_events(events) do
events
|> Enum.map(fn event ->
|> Enum.map(fn %RecordedEvent{} = event ->
%RecordedEvent{
event
| data: deserialize(event.data, type: "Elixir.EventStore.EventFactory.Event"),
Expand Down
103 changes: 103 additions & 0 deletions test/support/long_running_subscription.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
defmodule EventStore.LongRunningSubscription do
@moduledoc """
Appends to a stream on an interval and logs everything a subscription receives.

MIX_ENV=test mix run --no-halt -e "EventStore.LongRunningSubscription.start()"
"""

alias EventStore.UUID

defmodule ExampleEvent do
@derive Jason.Encoder
defstruct [:event]
end
Comment thread
cursor[bot] marked this conversation as resolved.

defmodule LoggingSubscriber do
use GenServer

alias EventStore.UUID

require Logger

def start_link(stream_uuid) do
GenServer.start_link(__MODULE__, stream_uuid)
end

@impl GenServer
def init(stream_uuid) do
{:ok, subscribe_to_stream(stream_uuid)}
end

@impl GenServer
def handle_info({:subscribed, subscription}, subscription) do
Logger.debug("Subscribed to stream")

{:noreply, subscription}
end

@impl GenServer
def handle_info({:events, events}, subscription) do
Logger.debug("Received event(s): #{inspect(events)}")

:ok = TestEventStore.ack(subscription, events)

{:noreply, subscription}
end

defp subscribe_to_stream(stream_uuid) do
{:ok, subscription} =
TestEventStore.subscribe_to_stream(stream_uuid, UUID.uuid4(), self())

subscription
end
end

defmodule IntervalAppender do
use GenServer

alias EventStore.{EventData, UUID}
alias EventStore.LongRunningSubscription.ExampleEvent

def start_link(stream_uuid, expected_version \\ 0, interval \\ 30_000) do
GenServer.start_link(__MODULE__, {stream_uuid, expected_version, interval})
end

@impl GenServer
def init({stream_uuid, expected_version, interval}) do
Process.send_after(self(), :append_to_stream, interval)

{:ok, {stream_uuid, expected_version, interval}}
end

@impl GenServer
def handle_info(:append_to_stream, {stream_uuid, expected_version, interval}) do
events = [
%EventData{
correlation_id: UUID.uuid4(),
causation_id: UUID.uuid4(),
event_type: "Elixir.EventStore.LongRunningSubscription.ExampleEvent",
data: %ExampleEvent{event: expected_version + 1},
metadata: %{"user" => "user@example.com"}
}
]

:ok = TestEventStore.append_to_stream(stream_uuid, expected_version, events)

Process.send_after(self(), :append_to_stream, interval)

{:noreply, {stream_uuid, expected_version + 1, interval}}
end
end

def start do
{:ok, _pid} = TestEventStore.start_link()

stream_uuid = UUID.uuid4()

{:ok, _subscriber} = LoggingSubscriber.start_link("$all")
{:ok, _subscriber} = LoggingSubscriber.start_link(stream_uuid)
{:ok, _appender} = IntervalAppender.start_link(stream_uuid)

:ok
end
end
9 changes: 9 additions & 0 deletions test/support/migration_fixtures.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Event do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end

defmodule Snapshot do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end
36 changes: 11 additions & 25 deletions test/manual/seed_eventstore.exs → test/support/migration_seed.ex
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
#
# Seed EventStore with data to test migrations.
#
# MIX_ENV=test mix es.reset
# MIX_ENV=test mix run test/manual/seed_eventstore.exs
#
# pg_dump eventstore_test > test/fixture/eventstore_seed.sql
# pg_dump -Fc eventstore_test > test/fixture/eventstore_seed.dump
#

defmodule Event do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end
defmodule EventStore.MigrationSeed do
@moduledoc """
Seeds an event store with the data captured in `test/fixture/eventstore_seed.dump`.

defmodule Snapshot do
@derive Jason.Encoder
defstruct [:data, version: "1"]
end
MIX_ENV=test mix es.reset
MIX_ENV=test mix run -e "EventStore.MigrationSeed.seed()"

pg_dump -Fc eventstore_test > test/fixture/eventstore_seed.dump
"""

defmodule Seed do
alias EventStore.{EventData, UUID}
alias EventStore.Snapshots.SnapshotData

def run(opts \\ []) do
def seed(opts \\ []) do
{:ok, _pid} = TestEventStore.start_link()

append_events(opts)
link_events(opts)
record_snapshots(opts)
Expand Down Expand Up @@ -96,8 +87,3 @@ defmodule Seed do
)
end
end

{:ok, _pid} = TestEventStore.start_link()

# Seed.run(stream_count: 1_000, event_count: 100, snapshot_count: 1_000)
Seed.run()
Loading