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

Added default table and snapshot container names #99

Merged
merged 5 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
25 changes: 25 additions & 0 deletions src/Akka.Persistence.Azure.Tests/AzurePersistenceConfigSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ public void ShouldParseDefaultSnapshotConfig()
blobSettings.RequestTimeout.Should().Be(TimeSpan.FromSeconds(3));
blobSettings.VerboseLogging.Should().BeFalse();
}

[Fact]
public void ShouldProvideDefaultContainerNameValue()
{
var blobSettings =
AzureBlobSnapshotStoreSettings.Create(
ConfigurationFactory.ParseString(@"akka.persistence.snapshot-store.azure-blob-store{
connection-string = foo
}").WithFallback(AzurePersistence.DefaultConfig)
.GetConfig("akka.persistence.snapshot-store.azure-blob-store"));

blobSettings.ContainerName.Should().Be(AzureBlobSnapshotStoreSettings.DefaultContainerName);
}

[Fact]
public void ShouldParseTableConfig()
Expand All @@ -61,6 +74,18 @@ public void ShouldParseTableConfig()
tableSettings.VerboseLogging.Should().BeFalse();
}

[Fact]
public void ShouldProvideDefaultTableNameValue()
{
var tableSettings =
AzureTableStorageJournalSettings.Create(
ConfigurationFactory.ParseString(@"akka.persistence.journal.azure-table{
connection-string = foo
}").WithFallback(AzurePersistence.DefaultConfig)
.GetConfig("akka.persistence.journal.azure-table"));
tableSettings.TableName.Should().Be(AzureTableStorageJournalSettings.DefaultTableName);
}

[Fact]
public void ShouldParseQueryConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ namespace Akka.Persistence.Azure.Journal
/// </summary>
public sealed class AzureTableStorageJournalSettings
{
/// <summary>
/// Name of the table used as a fallback configuration value
/// </summary>
public const string DefaultTableName = "AkkaPersistenceDefaultTable";

private static readonly string[] ReservedTableNames = {"tables"};

Expand Down Expand Up @@ -75,10 +79,14 @@ public AzureTableStorageJournalSettings(
public static AzureTableStorageJournalSettings Create(Config config)
{
var connectionString = config.GetString("connection-string");
var tableName = config.GetString("table-name");
var tableName = config.GetString("table-name", DefaultTableName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize that easier way would be to set this default names in default hocon configuration - but this way users will be able to get name value from DefaultTableName constant in runtime. Which might be useful.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values should be stored in HOCON.

var connectTimeout = config.GetTimeSpan("connect-timeout", TimeSpan.FromSeconds(3));
var requestTimeout = config.GetTimeSpan("request-timeout", TimeSpan.FromSeconds(3));
var verbose = config.GetBoolean("verbose-logging", false);

// When value is not overriden after default config, still may have null/"" here
if (string.IsNullOrWhiteSpace(tableName))
tableName = DefaultTableName;

return new AzureTableStorageJournalSettings(
connectionString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ namespace Akka.Persistence.Azure.Snapshot
/// </summary>
public sealed class AzureBlobSnapshotStoreSettings
{
/// <summary>
/// Container name used as a fallback configuration value
/// </summary>
public const string DefaultContainerName = "akka-persistence-default-container";

public AzureBlobSnapshotStoreSettings(string connectionString, string containerName,
TimeSpan connectTimeout, TimeSpan requestTimeout, bool verboseLogging)
{
Expand Down Expand Up @@ -61,11 +66,20 @@ public AzureBlobSnapshotStoreSettings(string connectionString, string containerN
public static AzureBlobSnapshotStoreSettings Create(Config config)
{
var connectionString = config.GetString("connection-string");
var containerName = config.GetString("container-name");
var connectTimeout = config.GetTimeSpan("connect-timeout", TimeSpan.FromSeconds(3));
var requestTimeout = config.GetTimeSpan("request-timeout", TimeSpan.FromSeconds(3));
var verbose = config.GetBoolean("verbose-logging", false);
return new AzureBlobSnapshotStoreSettings(connectionString, containerName, connectTimeout, requestTimeout,
var containerName = config.GetString("container-name", DefaultContainerName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above about loading name in runtime.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values should be stored in HOCON.


// When value is not overriden after default config, still may have null/"" here
if (string.IsNullOrWhiteSpace(containerName))
containerName = DefaultContainerName;

return new AzureBlobSnapshotStoreSettings(
connectionString,
containerName,
connectTimeout,
requestTimeout,
verbose);
}
}
Expand Down