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

Completed implementation #45

Merged
merged 5 commits into from
Sep 30, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Akka.Persistence.TCK" Version="1.3.8" />
<PackageReference Include="FluentAssertions" Version="5.4.1" />
<PackageReference Include="Akka.Persistence.TCK" Version="1.3.14" />
<PackageReference Include="FluentAssertions" Version="5.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestSdkVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit" Version="2.4.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
// <copyright file="AzureBlobStorageSpec.cs" company="Petabridge, LLC">
// <copyright file="AzureBlobSnapshotStoreSpec.cs" company="Petabridge, LLC">
// Copyright (C) 2015 - 2018 Petabridge, LLC <https://petabridge.com>
// </copyright>
// -----------------------------------------------------------------------
Expand All @@ -10,14 +10,14 @@
using Akka.Persistence.TCK.Snapshot;
using Xunit;
using Xunit.Abstractions;
using static Akka.Persistence.Azure.Tests.AzureStorageConfigHelper;
using static Akka.Persistence.Azure.Tests.Helper.AzureStorageConfigHelper;

namespace Akka.Persistence.Azure.Tests
{
[Collection("AzureSnapshot")]
public class AzureBlobStorageSpec : SnapshotStoreSpec
public class AzureBlobSnapshotStoreSpec : SnapshotStoreSpec
{
public AzureBlobStorageSpec(ITestOutputHelper output) : base(Config(),
public AzureBlobSnapshotStoreSpec(ITestOutputHelper output) : base(Config(),
nameof(AzureTableJournalSpec), output)
{
AzurePersistence.Get(Sys);
Expand Down
20 changes: 20 additions & 0 deletions src/Akka.Persistence.Azure.Tests/AzurePersistenceConfigSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System;
using Akka.Configuration;
using Akka.Persistence.Azure.Journal;
using Akka.Persistence.Azure.Query;
using Akka.Persistence.Azure.Snapshot;
using FluentAssertions;
using FluentAssertions.Equivalency;
Expand Down Expand Up @@ -60,6 +61,25 @@ public void ShouldParseTableConfig()
tableSettings.VerboseLogging.Should().BeFalse();
}

[Fact]
public void ShouldParseQueryConfig()
{
var querySettings =
AzureTableStorageQuerySettings.Create(
ConfigurationFactory.ParseString(@"akka.persistence.query.journal.azure-table{
class = ""classname""
write-plugin = foo
max-buffer-size = 100
refresh-interval = 3s
}").WithFallback(AzurePersistence.DefaultConfig)
.GetConfig("akka.persistence.query.journal.azure-table"));

querySettings.Class.Should().Be("classname");
querySettings.WritePlugin.Should().Be("foo");
querySettings.MaxBufferSize.Should().Be("100");
querySettings.RefreshInterval.Should().Be(new TimeSpan(0, 0, 3));
}

[Theory]
[InlineData("fo", "Invalid table name length")]
[InlineData("1foo", "Invalid table name")]
Expand Down
29 changes: 0 additions & 29 deletions src/Akka.Persistence.Azure.Tests/AzureStorageConfigHelper.cs

This file was deleted.

23 changes: 12 additions & 11 deletions src/Akka.Persistence.Azure.Tests/AzureTableJournalSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,41 @@
// </copyright>
// -----------------------------------------------------------------------

using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Persistence.Azure.TestHelpers;
using Akka.Persistence.TCK.Journal;
using System;
using Xunit;
using Xunit.Abstractions;
using static Akka.Persistence.Azure.Tests.AzureStorageConfigHelper;
using static Akka.Persistence.Azure.Tests.Helper.AzureStorageConfigHelper;

namespace Akka.Persistence.Azure.Tests
{
[Collection("AzureJournal")]
public class AzureTableJournalSpec : JournalSpec
{
public static string TableName { get; private set; }

public AzureTableJournalSpec(ITestOutputHelper output) : base(Config(), nameof(AzureTableJournalSpec),
output)
public AzureTableJournalSpec(ITestOutputHelper output)
: base(Config(), nameof(AzureTableJournalSpec), output)
{
AzurePersistence.Get(Sys);

Initialize();

output.WriteLine("Current table: {0}", TableName);
}

public static string TableName { get; private set; }

public static Config Config()
{
var config =
var azureConfig =
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
? AzureConfig(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
: AzureConfig(WindowsAzureStorageEmulatorFixture.GenerateConnStr());

TableName = config.GetString("akka.persistence.journal.azure-table.table-name");
TableName = azureConfig.GetString("akka.persistence.journal.azure-table.table-name");

return config;
return azureConfig;
}

protected override void Dispose(bool disposing)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using Akka.Configuration;

namespace Akka.Persistence.Azure.Tests.Helper
{
public static class AzureStorageConfigHelper
{
public static Config AzureConfig(string connectionString)
{
var tableName = "t" + Guid.NewGuid().ToString().Replace("-", "");
var containerName = "testcontainer" + Guid.NewGuid();

return ConfigurationFactory.ParseString(
@"
akka {
loglevel = DEBUG
log-config-on-start = off
test.single-expect-default = 30s

persistence {
publish-plugin-commands = on

journal {
plugin = ""akka.persistence.journal.azure-table""

azure-table {
connection-string=""" + connectionString + @"""
connect-timeout = 3s
request-timeout = 3s
verbose-logging = on

event-adapters {
color-tagger = ""Akka.Persistence.TCK.Query.ColorFruitTagger, Akka.Persistence.TCK""
}
event-adapter-bindings = {
""System.String"" = color-tagger
}
}
}

query {
journal {
azure-table {
write-plugin = ""akka.persistence.journal.azure-table""
refresh-interval = 1s
max-buffer-size = 150
}
}
}

snapshot-store {
plugin = ""akka.persistence.snapshot-store.azure-blob-store""

azure-blob-store {
connection-string=""" + connectionString + @"""
request-timeout = 3s
}
}
}
}")
.WithFallback("akka.persistence.journal.azure-table.table-name=" + tableName)
.WithFallback("akka.persistence.snapshot-store.azure-blob-store.container-name=" + containerName);
}

}
}
45 changes: 45 additions & 0 deletions src/Akka.Persistence.Azure.Tests/Helper/JournalTestActor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Akka.Actor;

namespace Akka.Persistence.Azure.Tests.Helper
{
public class JournalTestActor : UntypedPersistentActor
{
public static Props Props(string persistenceId) => Actor.Props.Create(() => new JournalTestActor(persistenceId));

public sealed class DeleteCommand
{
public DeleteCommand(long toSequenceNr)
{
ToSequenceNr = toSequenceNr;
}

public long ToSequenceNr { get; }
}

public JournalTestActor(string persistenceId)
{
PersistenceId = persistenceId;
}

public override string PersistenceId { get; }

protected override void OnRecover(object message)
{
}

protected override void OnCommand(object message)
{
switch (message)
{
case DeleteCommand delete:
DeleteMessages(delete.ToSequenceNr);
Sender.Tell($"{delete.ToSequenceNr}-deleted");
break;
case string cmd:
var sender = Sender;
Persist(cmd, e => sender.Tell($"{e}-done"));
break;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Akka.Configuration;
using Akka.Persistence.Azure.Query;
using Akka.Persistence.Azure.TestHelpers;
using Akka.Persistence.Azure.Tests.Helper;
using Akka.Persistence.Query;
using Akka.Persistence.TCK.Query;
using System;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Azure.Tests.Query
{
[Collection("AzureQuery")]
public sealed class AzureTableCurrentEventsByPersistenceIdSpec
: CurrentEventsByPersistenceIdSpec
{
public AzureTableCurrentEventsByPersistenceIdSpec(ITestOutputHelper output)
: base(Config(), nameof(AzureTablePersistenceIdsSpec), output)
{
AzurePersistence.Get(Sys);

ReadJournal =
Sys.ReadJournalFor<AzureTableStorageReadJournal>(
AzureTableStorageReadJournal.Identifier);

output.WriteLine("Current table: {0}", TableName);
}

public static string TableName { get; private set; }

public static Config Config()
{
var azureConfig =
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
? AzureStorageConfigHelper.AzureConfig(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
: AzureStorageConfigHelper.AzureConfig(WindowsAzureStorageEmulatorFixture.GenerateConnStr());

TableName = azureConfig.GetString("akka.persistence.journal.azure-table.table-name");

return azureConfig;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Persistence.Azure.Query;
using Akka.Persistence.Azure.TestHelpers;
using Akka.Persistence.Azure.Tests.Helper;
using Akka.Persistence.Query;
using Akka.Persistence.TCK.Query;
using Xunit;
using Xunit.Abstractions;

namespace Akka.Persistence.Azure.Tests.Query
{
[Collection("AzureQuery")]
public sealed class AzureTableCurrentEventsByTagSpec
: CurrentEventsByTagSpec
{
public AzureTableCurrentEventsByTagSpec(ITestOutputHelper output)
: base(Config(), nameof(AzureTablePersistenceIdsSpec), output)
{
AzurePersistence.Get(Sys);

ReadJournal =
Sys.ReadJournalFor<AzureTableStorageReadJournal>(
AzureTableStorageReadJournal.Identifier);

output.WriteLine("Current table: {0}", TableName);

var x = Sys.ActorOf(JournalTestActor.Props("x"));
x.Tell("warm-up");
ExpectMsg("warm-up-done", TimeSpan.FromSeconds(10));

}

public static string TableName { get; private set; }

public static Config Config()
{
var azureConfig =
!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
? AzureStorageConfigHelper.AzureConfig(Environment.GetEnvironmentVariable("AZURE_CONNECTION_STR"))
: AzureStorageConfigHelper.AzureConfig(WindowsAzureStorageEmulatorFixture.GenerateConnStr());

TableName = azureConfig.GetString("akka.persistence.journal.azure-table.table-name");

return azureConfig;
}
}
}
Loading