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
8 changed files
with
322 additions
and
39 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
test/Extensions/Tester.Redis/GrainDirectory/RedisGrainDirectoryTests.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,50 @@ | ||
using System; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
using Orleans.Configuration; | ||
using Orleans.GrainDirectory.Redis; | ||
using Orleans.Hosting; | ||
using Orleans.TestingHost; | ||
using StackExchange.Redis; | ||
using Tester.Directories; | ||
using Tester.Redis.Utility; | ||
using TestExtensions; | ||
using UnitTests.Grains.Directories; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Tester.Redis.GrainDirectory | ||
{ | ||
[TestCategory("Redis"), TestCategory("Directory"), TestCategory("Functional")] | ||
public class RedisGrainDirectoryTests : GrainDirectoryTests<RedisGrainDirectory> | ||
{ | ||
public RedisGrainDirectoryTests(ITestOutputHelper testOutput) | ||
: base(testOutput) | ||
{ | ||
} | ||
|
||
protected override RedisGrainDirectory GetGrainDirectory() | ||
{ | ||
var configuration = TestDefaultConfiguration.RedisConnectionString; | ||
|
||
if (string.IsNullOrWhiteSpace(configuration)) | ||
{ | ||
throw new SkipException("No connection string found. Skipping"); | ||
} | ||
|
||
var directoryOptions = new RedisGrainDirectoryOptions | ||
{ | ||
ConfigurationOptions = ConfigurationOptions.Parse(configuration), | ||
EntryExpiry = TimeSpan.FromMinutes(1), | ||
}; | ||
|
||
var clusterOptions = Options.Create(new ClusterOptions { ServiceId = "SomeServiceId", ClusterId = Guid.NewGuid().ToString("N") }); | ||
var directory = new RedisGrainDirectory( | ||
directoryOptions, | ||
clusterOptions, | ||
this.loggerFactory.CreateLogger<RedisGrainDirectory>()); | ||
directory.Initialize().GetAwaiter().GetResult(); | ||
return directory; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using UnitTests.GrainInterfaces; | ||
|
||
namespace Tester.Redis.Persistence | ||
{ | ||
[GenerateSerializer] | ||
public class GrainState | ||
{ | ||
[Id(0)] | ||
public string StringValue { get; set; } | ||
[Id(1)] | ||
public int IntValue { get; set; } | ||
[Id(2)] | ||
public DateTime DateTimeValue { get; set; } | ||
[Id(3)] | ||
public Guid GuidValue { get; set; } | ||
[Id(4)] | ||
public ITestGrain GrainValue { get; set; } | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
test/Extensions/Tester.Redis/Persistence/RedisPersistenceGrainTests.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,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Orleans.TestingHost; | ||
using Tester.Redis.Utility; | ||
using TestExtensions; | ||
using TestExtensions.Runners; | ||
using UnitTests.GrainInterfaces; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Tester.Redis.Persistence | ||
{ | ||
[TestCategory("Redis"), TestCategory("Persistence"), TestCategory("Functional")] | ||
public partial class RedisPersistenceGrainTests : GrainPersistenceTestsRunner, IClassFixture<RedisPersistenceGrainTests.Fixture> | ||
{ | ||
public static Guid ServiceId = Guid.NewGuid(); | ||
public static string ConnectionStringKey = "ConnectionString"; | ||
public class Fixture : BaseTestClusterFixture | ||
{ | ||
protected override void ConfigureTestCluster(TestClusterBuilder builder) | ||
{ | ||
builder.Options.InitialSilosCount = 4; | ||
builder.Options.UseTestClusterMembership = true; | ||
builder.ConfigureHostConfiguration(configBuilder => configBuilder.AddInMemoryCollection( | ||
new Dictionary<string, string> | ||
{ | ||
{ConnectionStringKey, TestDefaultConfiguration.RedisConnectionString} | ||
})); | ||
builder.Options.ServiceId = ServiceId.ToString(); | ||
builder.AddSiloBuilderConfigurator<MySiloBuilderConfigurator>(); | ||
builder.AddClientBuilderConfigurator<GatewayConnectionTests.ClientBuilderConfigurator>(); | ||
} | ||
|
||
private class MySiloBuilderConfigurator : IHostConfigurator | ||
{ | ||
public void Configure(IHostBuilder hostBuilder) | ||
{ | ||
var connectionString = hostBuilder.GetConfiguration()[ConnectionStringKey]; | ||
hostBuilder.UseOrleans((ctx, siloBuilder) => | ||
{ | ||
siloBuilder | ||
//.UseRedisClustering(options => | ||
//{ | ||
// options.ConnectionString = connectionString; | ||
//}) | ||
.AddRedisGrainStorage("GrainStorageForTest", options => | ||
{ | ||
options.ConnectionString = connectionString; | ||
}) | ||
.AddMemoryGrainStorage("MemoryStore"); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
private Fixture fixture; | ||
|
||
public RedisPersistenceGrainTests(ITestOutputHelper output, Fixture fixture) : base(output, fixture) | ||
{ | ||
this.fixture = fixture; | ||
this.fixture.EnsurePreconditionsMet(); | ||
} | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
test/Extensions/Tester.Redis/Persistence/RedisPersistenceGrainTestsExt.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,93 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Hosting; | ||
using Orleans.Storage; | ||
using Orleans.TestingHost; | ||
using StackExchange.Redis; | ||
using Tester.Redis.Utility; | ||
using TestExtensions; | ||
using TestExtensions.Runners; | ||
using UnitTests.GrainInterfaces; | ||
using UnitTests.Grains; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Tester.Redis.Persistence | ||
{ | ||
public partial class RedisPersistenceGrainTests : GrainPersistenceTestsRunner, IClassFixture<RedisPersistenceGrainTests.Fixture> | ||
{ | ||
[Fact] | ||
public async Task InitializeWithNoStateTest() | ||
{ | ||
var grain = fixture.GrainFactory.GetGrain<IGrainStorageGenericGrain<GrainState>>(0); | ||
var result = await grain.DoRead(); | ||
|
||
//Assert.NotNull(result); | ||
Assert.Equal(default(GrainState), result); | ||
//Assert.Equal(default(string), result.StringValue); | ||
//Assert.Equal(default(int), result.IntValue); | ||
//Assert.Equal(default(DateTime), result.DateTimeValue); | ||
//Assert.Equal(default(Guid), result.GuidValue); | ||
//Assert.Equal(default(ITestGrain), result.GrainValue); | ||
} | ||
|
||
[Fact] | ||
public async Task TestStaticIdentifierGrains() | ||
{ | ||
var grain = fixture.GrainFactory.GetGrain<IGrainStorageGenericGrain<GrainState>>(12345); | ||
GrainState state = new() { | ||
DateTimeValue=DateTime.UtcNow, | ||
GuidValue=Guid.NewGuid(), | ||
IntValue=12345, | ||
StringValue="string value", | ||
GrainValue=fixture.GrainFactory.GetGrain<ITestGrain>(2222) | ||
}; | ||
await grain.DoWrite(state); | ||
|
||
var result = await grain.DoRead(); | ||
Assert.Equal(result.StringValue, state.StringValue); | ||
Assert.Equal(result.IntValue, state.IntValue); | ||
Assert.Equal(result.DateTimeValue, state.DateTimeValue); | ||
Assert.Equal(result.GuidValue, state.GuidValue); | ||
Assert.Equal(result.GrainValue, state.GrainValue); | ||
} | ||
|
||
//[Fact] | ||
//public async Task TestRedisScriptCacheClearBeforeGrainWriteState() | ||
//{ | ||
// var grain = fixture.GrainFactory.GetGrain<ITestGrain>(1111); | ||
// var now = DateTime.UtcNow; | ||
// var guid = Guid.NewGuid(); | ||
|
||
// await _fixture.Database.ExecuteAsync("SCRIPT", "FLUSH", "SYNC"); | ||
// await grain.Set("string value", 12345, now, guid, fixture.GrainFactory.GetGrain<ITestGrain>(2222)); | ||
|
||
// var result = await grain.Get(); | ||
// Assert.Equal("string value", result.Item1); | ||
// Assert.Equal(12345, result.Item2); | ||
// Assert.Equal(now, result.Item3); | ||
// Assert.Equal(guid, result.Item4); | ||
// Assert.Equal(2222, result.Item5.GetPrimaryKeyLong()); | ||
//} | ||
|
||
//[Fact] | ||
//public async Task Double_Activation_ETag_Conflict_Simulation() | ||
//{ | ||
// var now = DateTime.UtcNow; | ||
// var guid = Guid.NewGuid(); | ||
// var grain = fixture.GrainFactory.GetGrain<ITestGrain>(54321); | ||
// var grainId = grain.GetGrainId(); | ||
|
||
// var stuff = await grain.Get(); | ||
// var scheduler = TaskScheduler.Current; | ||
|
||
// var key = grainId.ToString(); | ||
// await _fixture.Database.HashSetAsync(key, new[] { new HashEntry("etag", "derp") }); | ||
|
||
// var otherGrain = fixture.GrainFactory.GetGrain<ITestGrain>(2222); | ||
// await Assert.ThrowsAsync<InconsistentStateException>(() => grain.Set("string value", 12345, now, guid, otherGrain)); | ||
//} | ||
|
||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
test/Extensions/Tester.Redis/Persistence/RedisPersistenceSetupTests.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,37 @@ | ||
using System.Net; | ||
using Microsoft.Extensions.Hosting; | ||
using Xunit; | ||
using Orleans.Configuration; | ||
using Orleans.Runtime; | ||
|
||
namespace Tester.Redis.Persistence | ||
{ | ||
[TestCategory("Redis"), TestCategory("Persistence"), TestCategory("Functional")] | ||
public class RedisPersistenceSetupTests | ||
{ | ||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
[InlineData(" ")] | ||
[InlineData("123")] | ||
public void StorageOptionsValidator(string connectionString) | ||
{ | ||
var siloPort = 11111; | ||
int gatewayPort = 30000; | ||
var siloAddress = IPAddress.Loopback; | ||
|
||
var host = Host.CreateDefaultBuilder() | ||
.UseOrleans((ctx, builder) => { | ||
builder.Configure<ClusterOptions>(options => options.ClusterId = "TESTCLUSTER") | ||
.UseDevelopmentClustering(options => options.PrimarySiloEndpoint = new IPEndPoint(siloAddress, siloPort)) | ||
.ConfigureEndpoints(siloAddress, siloPort, gatewayPort) | ||
.AddRedisGrainStorage("Redis", optionsBuilder => optionsBuilder.Configure(options => | ||
{ | ||
options.ConnectionString = connectionString; | ||
})); | ||
}).Build(); | ||
|
||
Assert.Throws<OrleansConfigurationException>(() => host.Start()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.