-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Clean up EventStoreDb module (#792)
- Loading branch information
1 parent
955d709
commit eaa6068
Showing
9 changed files
with
148 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,67 @@ | ||
namespace Testcontainers.EventStore | ||
namespace Testcontainers.EventStoreDb; | ||
|
||
public sealed class EventStoreDbBuilder : ContainerBuilder<EventStoreDbBuilder, EventStoreDbContainer, EventStoreDbConfiguration> | ||
{ | ||
public sealed class EventStoreDbBuilder : ContainerBuilder<EventStoreDbBuilder, EventStoreDbContainer, EventStoreDbConfiguration> | ||
{ | ||
private const string EventStoreImage = "eventstore/eventstore:21.2.0-buster-slim"; | ||
public const string EventStoreDbImage = "eventstore/eventstore:22.10.1-buster-slim"; | ||
|
||
public const ushort EventStorePort = 2113; | ||
public const ushort EventStoreDbPort = 2113; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class. | ||
/// </summary> | ||
public EventStoreDbBuilder() | ||
: this(new EventStoreDbConfiguration()) | ||
{ | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class. | ||
/// </summary> | ||
public EventStoreDbBuilder() | ||
: this(new EventStoreDbConfiguration()) | ||
{ | ||
DockerResourceConfiguration = Init().DockerResourceConfiguration; | ||
} | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class. | ||
/// </summary> | ||
/// <param name="dockerResourceConfiguration">The Docker resource configuration.</param> | ||
private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration) | ||
: base(dockerResourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = dockerResourceConfiguration; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="EventStoreDbBuilder" /> class. | ||
/// </summary> | ||
/// <param name="dockerResourceConfiguration">The Docker resource configuration.</param> | ||
private EventStoreDbBuilder(EventStoreDbConfiguration dockerResourceConfiguration) | ||
: base(dockerResourceConfiguration) | ||
{ | ||
DockerResourceConfiguration = dockerResourceConfiguration; | ||
} | ||
/// <inheritdoc /> | ||
protected override EventStoreDbConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <inheritdoc /> | ||
protected override EventStoreDbConfiguration DockerResourceConfiguration { get; } | ||
|
||
/// <inheritdoc /> | ||
public override EventStoreDbContainer Build() | ||
{ | ||
return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); | ||
} | ||
/// <inheritdoc /> | ||
public override EventStoreDbContainer Build() | ||
{ | ||
return new EventStoreDbContainer(DockerResourceConfiguration, TestcontainersSettings.Logger); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(EventStoreImage) | ||
.WithPortBinding(EventStorePort, true) | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy()) | ||
.WithEnvironment("EVENTSTORE_CLUSTER_SIZE", "1") | ||
.WithEnvironment("EVENTSTORE_RUN_PROJECTIONS", "All") | ||
.WithEnvironment("EVENTSTORE_START_STANDARD_PROJECTIONS", "true") | ||
.WithEnvironment("EVENTSTORE_INSECURE", "true"); | ||
} | ||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Init() | ||
{ | ||
return base.Init() | ||
.WithImage(EventStoreDbImage) | ||
.WithPortBinding(EventStoreDbPort, true) | ||
.WithEnvironment("EVENTSTORE_CLUSTER_SIZE", "1") | ||
.WithEnvironment("EVENTSTORE_RUN_PROJECTIONS", "All") | ||
.WithEnvironment("EVENTSTORE_START_STANDARD_PROJECTIONS", "true") | ||
.WithEnvironment("EVENTSTORE_INSECURE", "true") | ||
.WithWaitStrategy(Wait.ForUnixContainer().UntilContainerIsHealthy()); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); | ||
} | ||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Clone(IContainerConfiguration resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); | ||
} | ||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Clone(IResourceConfiguration<CreateContainerParameters> resourceConfiguration) | ||
{ | ||
return Merge(DockerResourceConfiguration, new EventStoreDbConfiguration(resourceConfiguration)); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue) | ||
{ | ||
return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue)); | ||
} | ||
/// <inheritdoc /> | ||
protected override EventStoreDbBuilder Merge(EventStoreDbConfiguration oldValue, EventStoreDbConfiguration newValue) | ||
{ | ||
return new EventStoreDbBuilder(new EventStoreDbConfiguration(oldValue, newValue)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
src/Testcontainers.EventStoreDb/Testcontainers.EventStoreDb.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj" /> | ||
</ItemGroup> | ||
</Project> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks> | ||
<LangVersion>latest</LangVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1"/> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="$(SolutionDir)src/Testcontainers/Testcontainers.csproj"/> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 41 additions & 49 deletions
90
tests/Testcontainers.EventStoreDb.Tests/EventStoreDbContainerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,44 @@ | ||
namespace Testcontainers.EventStore; | ||
namespace Testcontainers.EventStoreDb; | ||
|
||
public sealed class EventStoreDbContainerTest : IAsyncLifetime | ||
{ | ||
private readonly EventStoreDbContainer _eventStoreContainer = new EventStoreDbBuilder().Build(); | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return _eventStoreContainer.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _eventStoreContainer.DisposeAsync().AsTask(); | ||
} | ||
|
||
[Fact] | ||
public async Task ConnectionEstablished() | ||
{ | ||
// Given | ||
var settings = EventStoreClientSettings.Create(_eventStoreContainer.GetConnectionString()); | ||
using EventStoreClient connection = new EventStoreClient(settings); | ||
|
||
// When | ||
var tokenSource = new CancellationTokenSource(); | ||
var cancellationToken = tokenSource.Token; | ||
|
||
var evt = new { EntityId = Guid.NewGuid().ToString("N"), ImportantData = "I wrote my first event!" }; | ||
|
||
var eventData = new EventData( | ||
Uuid.NewUuid(), | ||
"TestEvent", | ||
JsonSerializer.SerializeToUtf8Bytes(evt)); | ||
|
||
await connection.AppendToStreamAsync( | ||
"some-stream", | ||
StreamState.Any, | ||
new[] { eventData }, | ||
cancellationToken: cancellationToken); | ||
|
||
var result = connection.ReadStreamAsync( | ||
Direction.Forwards, | ||
"some-stream", | ||
StreamPosition.Start, | ||
cancellationToken: cancellationToken); | ||
|
||
var events = await result.ToListAsync(cancellationToken); | ||
|
||
// Then | ||
Assert.NotNull(events); | ||
} | ||
} | ||
private readonly EventStoreDbContainer _eventStoreDbContainer = new EventStoreDbBuilder().Build(); | ||
|
||
public Task InitializeAsync() | ||
{ | ||
return _eventStoreDbContainer.StartAsync(); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return _eventStoreDbContainer.DisposeAsync().AsTask(); | ||
} | ||
|
||
[Fact] | ||
[Trait(nameof(DockerCli.DockerPlatform), nameof(DockerCli.DockerPlatform.Linux))] | ||
public async Task ReadStreamReturnsEvent() | ||
{ | ||
// Given | ||
const string eventType = "some-event"; | ||
|
||
const string streamName = "some-stream"; | ||
|
||
var settings = EventStoreClientSettings.Create(_eventStoreDbContainer.GetConnectionString()); | ||
|
||
using var client = new EventStoreClient(settings); | ||
|
||
var eventData = new EventData(Uuid.NewUuid(), eventType, Array.Empty<byte>()); | ||
|
||
// When | ||
_ = await client.AppendToStreamAsync(streamName, StreamState.NoStream, new[] { eventData }) | ||
.ConfigureAwait(false); | ||
|
||
var resolvedEvents = client.ReadStreamAsync(Direction.Forwards, streamName, StreamPosition.Start); | ||
|
||
var resolvedEvent = await resolvedEvents.FirstAsync() | ||
.ConfigureAwait(false); | ||
|
||
// Then | ||
Assert.Equal(eventType, resolvedEvent.Event.EventType); | ||
} | ||
} |
Oops, something went wrong.