-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
356 additions
and
24 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
100 changes: 100 additions & 0 deletions
100
src/Akka.Persistence.Redis.Cluster.Tests/RedisJournalDefaultDatabaseSpec.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,100 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RedisJournalSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using Akka.Configuration; | ||
using Akka.Persistence.TCK.Journal; | ||
using FluentAssertions; | ||
using StackExchange.Redis; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Persistence.Redis.Cluster.Tests | ||
{ | ||
[Collection("RedisClusterSpec")] | ||
public class RedisJournalDefaultDatabaseSpec : JournalSpec | ||
{ | ||
private readonly RedisClusterFixture _fixture; | ||
|
||
public static Config Config(RedisClusterFixture fixture) | ||
{ | ||
DbUtils.Initialize(fixture); | ||
|
||
return ConfigurationFactory.ParseString($@" | ||
akka.loglevel = INFO | ||
akka.persistence.journal.plugin = ""akka.persistence.journal.redis"" | ||
akka.persistence.journal.redis {{ | ||
class = ""Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis"" | ||
plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
configuration-string = ""{DbUtils.ConnectionString},defaultDatabase=0"" | ||
use-database-number-from-connection-string = true | ||
}} | ||
akka.test.single-expect-default = 3s") | ||
.WithFallback(RedisPersistence.DefaultConfig()); | ||
} | ||
|
||
public RedisJournalDefaultDatabaseSpec(ITestOutputHelper output, RedisClusterFixture fixture) | ||
: base(Config(fixture), nameof(RedisJournalSpec), output) | ||
{ | ||
_fixture = fixture; | ||
|
||
RedisPersistence.Get(Sys); | ||
Initialize(); | ||
} | ||
|
||
protected override bool SupportsRejectingNonSerializableObjects { get; } = false; | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
DbUtils.Clean(); | ||
} | ||
|
||
[Fact] | ||
public void Randomly_distributed_RedisKey_with_HashTag_should_be_distributed_relatively_equally_between_cluster_master() | ||
{ | ||
var totalEntries = 10000; | ||
|
||
var redis = ConnectionMultiplexer.Connect(_fixture.ConnectionString); | ||
var db = redis.GetDatabase(); | ||
var journalHelper = new JournalHelper(Sys, "foo"); | ||
var dict = new Dictionary<EndPoint, int>(); | ||
|
||
for (var i = 0; i < totalEntries; ++i) | ||
{ | ||
var id = $"{Guid.NewGuid():N}-{i}"; | ||
var ep = db.IdentifyEndpoint(journalHelper.GetJournalKey(id, true)); | ||
if (!dict.TryGetValue(ep, out _)) | ||
{ | ||
dict[ep] = 1; | ||
} | ||
else | ||
{ | ||
dict[ep]++; | ||
} | ||
} | ||
|
||
var values = dict.Values.AsEnumerable().ToArray(); | ||
|
||
// Evaluate standard deviation | ||
var standardDeviation = StandardDeviation(values); | ||
Output.WriteLine($"Server assignment distribution: [{string.Join(",", values)}]. Standard deviation: [{standardDeviation}]"); | ||
|
||
// Should be less than 1 percent of total keys | ||
StandardDeviation(values).Should().BeLessThan(totalEntries * 0.01); | ||
} | ||
|
||
private double StandardDeviation(int[] values) | ||
{ | ||
var mean = values.Average(); | ||
var sum = values.Sum(d => Math.Pow(d - mean, 2)); | ||
return Math.Sqrt((sum) / (values.Count() - 1)); | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Akka.Persistence.Redis.Cluster.Tests/RedisSnapshotStoreDefaultDatabaseSpec.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,61 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RedisSnapshotStoreSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Akka.Configuration; | ||
using Akka.Persistence.TCK.Snapshot; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Persistence.Redis.Cluster.Tests | ||
{ | ||
[Collection("RedisClusterSpec")] | ||
public class RedisSnapshotStoreDefaultDatabaseSpec : SnapshotStoreSpec | ||
{ | ||
public static Config Config(RedisClusterFixture fixture) | ||
{ | ||
DbUtils.Initialize(fixture); | ||
|
||
return ConfigurationFactory.ParseString($@" | ||
akka.test.single-expect-default = 3s | ||
akka.persistence {{ | ||
publish-plugin-commands = on | ||
snapshot-store {{ | ||
plugin = ""akka.persistence.snapshot-store.redis"" | ||
redis {{ | ||
class = ""Akka.Persistence.Redis.Snapshot.RedisSnapshotStore, Akka.Persistence.Redis"" | ||
configuration-string = ""{fixture.ConnectionString},defaultDatabase=0"" | ||
use-database-number-from-connection-string = true | ||
plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
}} | ||
}} | ||
}} | ||
akka.actor {{ | ||
serializers {{ | ||
persistence-snapshot = ""Akka.Persistence.Redis.Serialization.PersistentSnapshotSerializer, Akka.Persistence.Redis"" | ||
}} | ||
serialization-bindings {{ | ||
""Akka.Persistence.SelectedSnapshot, Akka.Persistence"" = persistence-snapshot | ||
}} | ||
serialization-identifiers {{ | ||
""Akka.Persistence.Redis.Serialization.PersistentSnapshotSerializer, Akka.Persistence.Redis"" = 48 | ||
}} | ||
}}").WithFallback(RedisPersistence.DefaultConfig()); | ||
} | ||
|
||
public RedisSnapshotStoreDefaultDatabaseSpec(ITestOutputHelper output, RedisClusterFixture fixture) | ||
: base(Config(fixture), nameof(RedisSnapshotStoreSpec), output) | ||
{ | ||
RedisPersistence.Get(Sys); | ||
Initialize(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
DbUtils.Clean(); | ||
} | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
src/Akka.Persistence.Redis.Tests/RedisJournalDefaultDatabaseSpec.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,52 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RedisJournalSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Akka.Configuration; | ||
using Akka.Persistence.TCK.Journal; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Persistence.Redis.Tests | ||
{ | ||
[Collection("RedisSpec")] | ||
public class RedisJournalDefaultDatabaseSpec : JournalSpec | ||
{ | ||
public const int Database = 1; | ||
|
||
public static Config Config(RedisFixture fixture, int id) | ||
{ | ||
DbUtils.Initialize(fixture); | ||
|
||
return ConfigurationFactory.ParseString($@" | ||
akka.loglevel = INFO | ||
akka.persistence.journal.plugin = ""akka.persistence.journal.redis"" | ||
akka.persistence.journal.redis {{ | ||
class = ""Akka.Persistence.Redis.Journal.RedisJournal, Akka.Persistence.Redis"" | ||
plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
configuration-string = ""{fixture.ConnectionString},defaultDatabase=1"" | ||
use-database-number-from-connection-string = true | ||
database = {id} | ||
}} | ||
akka.test.single-expect-default = 3s") | ||
.WithFallback(RedisPersistence.DefaultConfig()); | ||
} | ||
|
||
public RedisJournalDefaultDatabaseSpec(ITestOutputHelper output, RedisFixture fixture) : base(Config(fixture, Database), | ||
nameof(RedisJournalSpec), output) | ||
{ | ||
RedisPersistence.Get(Sys); | ||
Initialize(); | ||
} | ||
|
||
protected override bool SupportsRejectingNonSerializableObjects { get; } = false; | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
DbUtils.Clean(Database); | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Akka.Persistence.Redis.Tests/RedisSnapshotStoreDefaultDatabaseSpec.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,64 @@ | ||
// ----------------------------------------------------------------------- | ||
// <copyright file="RedisSnapshotStoreSpec.cs" company="Akka.NET Project"> | ||
// Copyright (C) 2013-2021 .NET Foundation <https://github.com/akkadotnet/akka.net> | ||
// </copyright> | ||
// ----------------------------------------------------------------------- | ||
|
||
using Akka.Configuration; | ||
using Akka.Persistence.TCK.Snapshot; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Akka.Persistence.Redis.Tests | ||
{ | ||
[Collection("RedisSpec")] | ||
public class RedisSnapshotStoreDefaultDatabaseSpec : SnapshotStoreSpec | ||
{ | ||
public const int Database = 1; | ||
|
||
public static Config Config(RedisFixture fixture, int id) | ||
{ | ||
DbUtils.Initialize(fixture); | ||
|
||
return ConfigurationFactory.ParseString($@" | ||
akka.test.single-expect-default = 3s | ||
akka.persistence {{ | ||
publish-plugin-commands = on | ||
snapshot-store {{ | ||
plugin = ""akka.persistence.snapshot-store.redis"" | ||
redis {{ | ||
class = ""Akka.Persistence.Redis.Snapshot.RedisSnapshotStore, Akka.Persistence.Redis"" | ||
configuration-string = ""{fixture.ConnectionString},defaultDatabase=1"" | ||
plugin-dispatcher = ""akka.actor.default-dispatcher"" | ||
use-database-number-from-connection-string = true | ||
database = ""{id}"" | ||
}} | ||
}} | ||
}} | ||
akka.actor {{ | ||
serializers {{ | ||
persistence-snapshot = ""Akka.Persistence.Redis.Serialization.PersistentSnapshotSerializer, Akka.Persistence.Redis"" | ||
}} | ||
serialization-bindings {{ | ||
""Akka.Persistence.SelectedSnapshot, Akka.Persistence"" = persistence-snapshot | ||
}} | ||
serialization-identifiers {{ | ||
""Akka.Persistence.Redis.Serialization.PersistentSnapshotSerializer, Akka.Persistence.Redis"" = 48 | ||
}} | ||
}}").WithFallback(RedisPersistence.DefaultConfig()); | ||
} | ||
|
||
public RedisSnapshotStoreDefaultDatabaseSpec(ITestOutputHelper output, RedisFixture fixture) | ||
: base(Config(fixture, Database), typeof(RedisSnapshotStoreSpec).Name, output) | ||
{ | ||
RedisPersistence.Get(Sys); | ||
Initialize(); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
base.Dispose(disposing); | ||
DbUtils.Clean(Database); | ||
} | ||
} | ||
} |
Oops, something went wrong.