-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for MayInterleave in StatelessWorker (#9050)
Co-authored-by: Ledjon Behluli <Ledjon@notiphy.io>
- Loading branch information
1 parent
c76b443
commit 7328b28
Showing
4 changed files
with
80 additions
and
2 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
8 changes: 8 additions & 0 deletions
8
test/Grains/TestGrainInterfaces/IStatelessWorkerWithMayInterleaveGrain.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,8 @@ | ||
namespace UnitTests.GrainInterfaces; | ||
|
||
public interface IStatelessWorkerWithMayInterleaveGrain : IGrainWithIntegerKey | ||
{ | ||
Task SetDelay(TimeSpan delay); | ||
Task GoSlow(); | ||
Task GoFast(); | ||
} |
23 changes: 23 additions & 0 deletions
23
test/Grains/TestGrains/StatelessWorkerWithMayInterleaveGrain.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,23 @@ | ||
using Orleans.Concurrency; | ||
using Orleans.Serialization.Invocation; | ||
using UnitTests.GrainInterfaces; | ||
|
||
namespace UnitTests.Grains; | ||
|
||
[StatelessWorker(1)] // '1' to force interleaving, otherwise it just creates a new worker | ||
[MayInterleave(nameof(MayInterleaveMethod))] | ||
public class StatelessWorkerWithMayInterleaveGrain : Grain, IStatelessWorkerWithMayInterleaveGrain | ||
{ | ||
private TimeSpan _delay = TimeSpan.FromMilliseconds(1); | ||
|
||
public static bool MayInterleaveMethod(IInvokable req) => req.GetMethodName() == nameof(GoFast); | ||
|
||
public Task SetDelay(TimeSpan delay) | ||
{ | ||
_delay = delay; | ||
return Task.CompletedTask; | ||
} | ||
|
||
public Task GoSlow() => Task.Delay(_delay); | ||
public Task GoFast() => Task.Delay(_delay); | ||
} |