-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from petabridge/dev
v0.6.1 Release
- Loading branch information
Showing
12 changed files
with
232 additions
and
55 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
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
32 changes: 32 additions & 0 deletions
32
src/Akka.Persistence.Azure.Tests/AzureTableJournalEscapePersistentIdSpec.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Reflection; | ||
using Akka.Actor; | ||
using Akka.Configuration; | ||
using Akka.Persistence.Azure.TestHelpers; | ||
using Akka.Persistence.TCK; | ||
using Akka.Persistence.TCK.Journal; | ||
using Akka.TestKit; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using static Akka.Persistence.Azure.Tests.Helper.AzureStorageConfigHelper; | ||
|
||
namespace Akka.Persistence.Azure.Tests | ||
{ | ||
public class AzureTableJournalEscapePersistentIdSpec : AzureTableJournalSpec, IClassFixture<WindowsAzureStorageEmulatorFixture> | ||
{ | ||
public AzureTableJournalEscapePersistentIdSpec(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void PreparePersistenceId(string pid) | ||
{ | ||
base.PreparePersistenceId(pid); | ||
|
||
// Before storage is initialized, let's set Pid to the value that needs to be encoded | ||
var persistenceIdUsedForTests = typeof(PluginSpec).GetField($"<{nameof(Pid)}>k__BackingField", BindingFlags.Instance | BindingFlags.NonPublic); | ||
var currentValue = persistenceIdUsedForTests.GetValue(this).ToString(); | ||
persistenceIdUsedForTests.SetValue(this, $"some/path/to/encode/{currentValue}"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Akka.Persistence.Azure.Tests/PartitionKeyEscapeHelperSpecs.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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Akka.Actor; | ||
using Akka.Persistence.Azure.Util; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Akka.Persistence.Azure.Tests | ||
{ | ||
public class PartitionKeyEscapeHelperSpecs | ||
{ | ||
[Theory] | ||
[InlineData("/system/sharding/areaCoordinator/singleton/coordinator")] | ||
[InlineData("/system/sha$rding/areaCoordinator/single$ton/coordinator$")] | ||
[InlineData("/system/sha$$$rding/areaCoord/inator$$/single$ton/coord$inator$")] | ||
public void Should_escape_correctly(string partitionKey) | ||
{ | ||
var escapedKey = PartitionKeyEscapeHelper.Escape(partitionKey); | ||
escapedKey.Should().NotContain("/"); | ||
var originalKey = PartitionKeyEscapeHelper.Unescape(escapedKey); | ||
originalKey.Should().Be(partitionKey); | ||
} | ||
} | ||
|
||
class A : ReceiveActor{ } | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
src/Akka.Persistence.Azure/Util/PartitionKeyEscapeHelper.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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Akka.Persistence.Azure.Util | ||
{ | ||
/// <summary> | ||
/// PartitionKeyEscapeHelper | ||
/// </summary> | ||
public static class PartitionKeyEscapeHelper | ||
{ | ||
/// <summary> | ||
/// Sequence we need to escape | ||
/// </summary> | ||
private const string InvalidSequence = "/"; | ||
/// <summary> | ||
/// Sequence we use to escape invalid chars | ||
/// </summary> | ||
/// <remarks> | ||
/// Using $ here to resolve https://github.com/petabridge/Akka.Persistence.Azure/issues/98 | ||
/// Actor names never start with $ sign, which helps to decode encoded keys | ||
/// </remarks> | ||
private const string EscapeSequence = "$"; | ||
|
||
/// <summary> | ||
/// Escape special characters in partition key | ||
/// </summary> | ||
/// <returns>Escaped partition key</returns> | ||
public static string Escape(string partitionKey) | ||
{ | ||
var escapedKey = partitionKey; | ||
// First, replate escape sequence in case if it is used in original key | ||
escapedKey = escapedKey.Replace(EscapeSequence, EscapeSequence + EscapeSequence); | ||
|
||
// Now escape special chars | ||
escapedKey = escapedKey.Replace(InvalidSequence, EscapeSequence); | ||
|
||
return escapedKey; | ||
} | ||
|
||
/// <summary> | ||
/// Unescape previously escaped partition key | ||
/// </summary> | ||
/// <returns>Original, unescaped partition key</returns> | ||
public static string Unescape(string escapedKey) | ||
{ | ||
var originalKey = escapedKey; | ||
var uuid = Guid.NewGuid().ToString("N"); | ||
// Do not touch duplicated escape sequence - we will replace them later | ||
originalKey = originalKey.Replace(EscapeSequence + EscapeSequence, uuid); | ||
|
||
// Restore escaped characters | ||
originalKey = originalKey.Replace(EscapeSequence, InvalidSequence); | ||
|
||
// Now it is safe to decode duplicated sequences | ||
originalKey = originalKey.Replace(uuid, EscapeSequence); | ||
|
||
return originalKey; | ||
} | ||
} | ||
} |
Oops, something went wrong.