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
17 changed files
with
441 additions
and
5 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
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
17 changes: 17 additions & 0 deletions
17
src/Orleans.Transactions.Testkit.Xunit/Orleans.Transactions.Testkit.Xunit.csproj
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,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Orleans.Transactions.TestkitBase\Orleans.Transactions.TestkitBase.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="xunit" Version="$(xUnitVersion)" /> | ||
<PackageReference Include="Xunit.SkippableFact" Version="$(XunitSkippableFactVersion)" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="$(xUnitVersion)" /> | ||
</ItemGroup> | ||
|
||
</Project> |
24 changes: 24 additions & 0 deletions
24
src/Orleans.Transactions.Testkit.Xunit/TransactionalStateStorageTestRunner.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 System; | ||
using System.Threading.Tasks; | ||
using Orleans.Transaction.Testkit; | ||
using Orleans.Transactions.Abstractions; | ||
using Xunit; | ||
|
||
namespace Orleans.Transactions.Testkit.Xunit | ||
{ | ||
public abstract class TransactionalStateStorageTestRunnerXunit<TState> : TransactionalStateStorageTestRunner<TState> | ||
where TState: class, new() | ||
{ | ||
public TransactionalStateStorageTestRunnerXunit(Func<Task<ITransactionalStateStorage<TState>>> stateStorageFactory, | ||
Func<TState> stateFactory, IGrainFactory grainFactory) | ||
: base(stateStorageFactory, stateFactory, grainFactory) | ||
{ | ||
} | ||
|
||
[Fact] | ||
public override Task FirstTime_Load_ShouldReturnEmptyLoadResponse() | ||
{ | ||
return base.FirstTime_Load_ShouldReturnEmptyLoadResponse(); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/Orleans.Transactions.TestkitBase/Grains/ITransactionTestGrain.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,36 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace Orleans.Transactions.Testkit | ||
{ | ||
public interface ITransactionTestGrain : IGrainWithGuidKey | ||
{ | ||
|
||
/// <summary> | ||
/// apply set operation to every transaction state | ||
/// </summary> | ||
/// <param name="newValue"></param> | ||
/// <returns></returns> | ||
[Transaction(TransactionOption.CreateOrJoin)] | ||
Task Set(int newValue); | ||
|
||
/// <summary> | ||
/// apply add operation to every transaction state | ||
/// </summary> | ||
/// <param name="numberToAdd"></param> | ||
/// <returns></returns> | ||
[Transaction(TransactionOption.CreateOrJoin)] | ||
Task<int[]> Add(int numberToAdd); | ||
|
||
/// <summary> | ||
/// apply get operation to every transaction state | ||
/// </summary> | ||
/// <returns></returns> | ||
[Transaction(TransactionOption.CreateOrJoin)] | ||
Task<int[]> Get(); | ||
|
||
[Transaction(TransactionOption.CreateOrJoin)] | ||
Task AddAndThrow(int numberToAdd); | ||
|
||
Task Deactivate(); | ||
} | ||
} |
151 changes: 151 additions & 0 deletions
151
src/Orleans.Transactions.TestkitBase/Grains/MultiStateTransactionalGrain.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,151 @@ | ||
using Microsoft.Extensions.Logging; | ||
using Orleans.Transactions.Abstractions; | ||
using System; | ||
using System.Linq; | ||
using System.Runtime.Serialization; | ||
using System.Threading.Tasks; | ||
|
||
namespace Orleans.Transactions.Testkit | ||
{ | ||
[Serializable] | ||
public class GrainData | ||
{ | ||
public int Value { get; set; } | ||
} | ||
|
||
public class MaxStateTransactionalGrain : MultiStateTransactionalGrainBaseClass | ||
{ | ||
public MaxStateTransactionalGrain(ITransactionalStateFactory stateFactory, | ||
ILoggerFactory loggerFactory) | ||
: base(Enumerable.Range(0, TransactionTestConstants.MaxCoordinatedTransactions) | ||
.Select(i => stateFactory.Create<GrainData>(new TransactionalStateAttribute($"data{i}", TransactionTestConstants.TransactionStore))) | ||
.ToArray(), | ||
loggerFactory) | ||
{ | ||
} | ||
} | ||
|
||
public class DoubleStateTransactionalGrain : MultiStateTransactionalGrainBaseClass | ||
{ | ||
public DoubleStateTransactionalGrain( | ||
[TransactionalState("data1", TransactionTestConstants.TransactionStore)] | ||
ITransactionalState<GrainData> data1, | ||
[TransactionalState("data2", TransactionTestConstants.TransactionStore)] | ||
ITransactionalState<GrainData> data2, | ||
ILoggerFactory loggerFactory) | ||
: base(new ITransactionalState<GrainData>[2] { data1, data2 }, loggerFactory) | ||
{ | ||
} | ||
} | ||
|
||
public class SingleStateTransactionalGrain : MultiStateTransactionalGrainBaseClass | ||
{ | ||
public SingleStateTransactionalGrain( | ||
[TransactionalState("data", TransactionTestConstants.TransactionStore)] | ||
ITransactionalState<GrainData> data, | ||
ILoggerFactory loggerFactory) | ||
: base(new ITransactionalState<GrainData>[1] { data }, loggerFactory) | ||
{ | ||
} | ||
} | ||
|
||
public class NoStateTransactionalGrain : MultiStateTransactionalGrainBaseClass | ||
{ | ||
public NoStateTransactionalGrain( | ||
ILoggerFactory loggerFactory) | ||
: base(Array.Empty<ITransactionalState<GrainData>>(), loggerFactory) | ||
{ | ||
} | ||
} | ||
|
||
public class MultiStateTransactionalGrainBaseClass : Grain, ITransactionTestGrain | ||
{ | ||
protected ITransactionalState<GrainData>[] dataArray; | ||
private readonly ILoggerFactory loggerFactory; | ||
protected ILogger logger; | ||
|
||
public MultiStateTransactionalGrainBaseClass( | ||
ITransactionalState<GrainData>[] dataArray, | ||
ILoggerFactory loggerFactory) | ||
{ | ||
this.dataArray = dataArray; | ||
this.loggerFactory = loggerFactory; | ||
} | ||
|
||
public override Task OnActivateAsync() | ||
{ | ||
this.logger = this.loggerFactory.CreateLogger(this.GetGrainIdentity().ToString()); | ||
return base.OnActivateAsync(); | ||
} | ||
|
||
public async Task Set(int newValue) | ||
{ | ||
foreach(var data in this.dataArray) | ||
{ | ||
await data.PerformUpdate(state => | ||
{ | ||
this.logger.LogInformation($"Setting from {state.Value} to {newValue}."); | ||
state.Value = newValue; | ||
this.logger.LogInformation($"Set to {state.Value}."); | ||
}); | ||
} | ||
} | ||
|
||
public async Task<int[]> Add(int numberToAdd) | ||
{ | ||
var result = new int[dataArray.Length]; | ||
for(int i = 0; i < dataArray.Length; i++) | ||
{ | ||
result[i] = await dataArray[i].PerformUpdate(state => | ||
{ | ||
this.logger.LogInformation($"Adding {numberToAdd} to {state.Value}."); | ||
state.Value += numberToAdd; | ||
this.logger.LogInformation($"Value after Adding {numberToAdd} is {state.Value}."); | ||
return state.Value; | ||
}); | ||
} | ||
return result; | ||
} | ||
|
||
public async Task<int[]> Get() | ||
{ | ||
var result = new int[dataArray.Length]; | ||
for (int i = 0; i < dataArray.Length; i++) | ||
{ | ||
result[i] = await dataArray[i].PerformRead(state => | ||
{ | ||
this.logger.LogInformation($"Get {state.Value}."); | ||
return state.Value; | ||
}); | ||
} | ||
return result; | ||
} | ||
|
||
public async Task AddAndThrow(int numberToAdd) | ||
{ | ||
await Add(numberToAdd); | ||
throw new AddAndThrowException($"{GetType().Name} test exception"); | ||
} | ||
|
||
public Task Deactivate() | ||
{ | ||
DeactivateOnIdle(); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
[Serializable] | ||
public class AddAndThrowException : Exception | ||
{ | ||
public AddAndThrowException() : base("Unexpected error.") { } | ||
|
||
public AddAndThrowException(string message) : base(message) { } | ||
|
||
public AddAndThrowException(string message, Exception innerException) : base(message, innerException) { } | ||
|
||
protected AddAndThrowException(SerializationInfo info, StreamingContext context) | ||
: base(info, context) | ||
{ | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Orleans.Transactions.TestkitBase/Grains/TransactionTestConstants.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,26 @@ | ||
| ||
using Microsoft.Extensions.Logging; | ||
using Orleans.Hosting; | ||
|
||
namespace Orleans.Transactions.Testkit | ||
{ | ||
public static class TransactionTestConstants | ||
{ | ||
/// <summary> | ||
/// Max number of grains to include in a transaction for test purposes. Not a hard limit of the transaction system. | ||
/// </summary> | ||
public const int MaxCoordinatedTransactions = 8; | ||
|
||
// storage providers | ||
public const string TransactionStore = "TransactionStore"; | ||
|
||
// committer service | ||
public const string RemoteCommitService = "RemoteCommitService"; | ||
|
||
// grain implementations | ||
public const string NoStateTransactionalGrain = "NoStateTransactionalGrain"; | ||
public const string SingleStateTransactionalGrain = "SingleStateTransactionalGrain"; | ||
public const string DoubleStateTransactionalGrain = "DoubleStateTransactionalGrain"; | ||
public const string MaxStateTransactionalGrain = "MaxStateTransactionalGrain"; | ||
} | ||
} |
Oops, something went wrong.