Skip to content

Commit 4b890f5

Browse files
committed
fix calls direction
1 parent 709ae7f commit 4b890f5

File tree

14 files changed

+146
-80
lines changed

14 files changed

+146
-80
lines changed

ManagedCode.Orleans.Graph.Tests/Cluster/TestSiloConfigurations.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ public void Configure(ISiloBuilder siloBuilder)
1212
.CreateGraph(graph =>
1313
{
1414
graph.AddGrain<IGrainA>()
15+
.AllowClientCallGrain()
1516
.WithReentrancy();
17+
18+
graph.AllowClientCallGrain<IGrainB>();
1619

1720
graph.AddGrainTransition<IGrainA, IGrainB>().AllMethods().WithReentrancy();
1821
graph.AddGrainTransition<IGrainB, IGrainC>().AllMethods().WithReentrancy();

ManagedCode.Orleans.Graph.Tests/GrainGraphManagerTests.cs renamed to ManagedCode.Orleans.Graph.Tests/GrainTransitionManagerTests.cs

File renamed without changes.

ManagedCode.Orleans.Graph.Tests/GraphTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using FluentAssertions;
12
using ManagedCode.Orleans.Graph.Tests.Cluster;
23
using ManagedCode.Orleans.Graph.Tests.Cluster.Grains.Interfaces;
34
using Xunit;
@@ -25,6 +26,32 @@ await _testApp.Cluster
2526
.GetGrain<IGrainA>("1")
2627
.MethodA1(1);
2728
}
29+
30+
[Fact]
31+
public async Task GrainB_B1Test()
32+
{
33+
await _testApp.Cluster
34+
.Client
35+
.GetGrain<IGrainB>("1")
36+
.MethodB1(1);
37+
}
38+
39+
[Fact]
40+
public async Task GrainC_C1Test()
41+
{
42+
var exception = await Assert.ThrowsAsync<InvalidOperationException>(async () =>
43+
{
44+
await _testApp.Cluster
45+
.Client
46+
.GetGrain<IGrainC>("1")
47+
.MethodC1(1);
48+
});
49+
50+
exception.Message
51+
.Should()
52+
.StartWith("Transition is not allowed.");
53+
}
54+
2855

2956
[Fact]
3057
public async Task GrainA_B1Test()

ManagedCode.Orleans.Graph/Builder/GrainCallsBuilder.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using ManagedCode.Orleans.Graph.Interfaces;
23
using ManagedCode.Orleans.Graph.Models;
34
using Orleans;
45

@@ -14,10 +15,16 @@ public GrainCallsBuilder(bool allowSelfLoops = true)
1415
{
1516
_graph = new DirectedGraph(allowSelfLoops);
1617
}
18+
19+
public IGrainCallsBuilder AllowClientCallGrain<TGrain>() where TGrain : IGrain
20+
{
21+
AddTransition(Constants.ClientCallerId, typeof(TGrain).FullName!);
22+
return this;
23+
}
1724

1825
public ITransitionBuilder<TGrain> From<TGrain>() where TGrain : IGrain
1926
{
20-
return new TransitionBuilder<TGrain>(this, typeof(TGrain).FullName);
27+
return new TransitionBuilder<TGrain>(this, typeof(TGrain).FullName!);
2128
}
2229

2330
public IMethodBuilder<TGrain, TGrain> AddGrain<TGrain>() where TGrain : IGrain

ManagedCode.Orleans.Graph/Builder/Interfaces/IGrainCallsBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ public interface IGrainCallsBuilder
1313
/// <typeparam name="TGrain">The type of the grain.</typeparam>
1414
/// <returns>An instance of <see cref="ITransitionBuilder{TGrain}"/>.</returns>
1515
ITransitionBuilder<TGrain> From<TGrain>() where TGrain : IGrain;
16+
17+
/// <summary>
18+
/// Allows the client to call the specified grain.
19+
/// </summary>
20+
/// <typeparam name="TGrain">The type of the grain.</typeparam>
21+
/// <returns>The current instance of <see cref="IGrainCallsBuilder"/>.</returns>
22+
IGrainCallsBuilder AllowClientCallGrain<TGrain>() where TGrain : IGrain;
1623

1724
/// <summary>
1825
/// Allows all grain calls.

ManagedCode.Orleans.Graph/Builder/Interfaces/IGroupBuilder.cs

Lines changed: 0 additions & 28 deletions
This file was deleted.

ManagedCode.Orleans.Graph/Builder/Interfaces/IMethodBuilder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ public interface IMethodBuilder<TSource, TTarget> where TSource : IGrain where T
3030
/// <returns>The current instance of <see cref="IMethodBuilder{TSource, TTarget}"/>.</returns>
3131
IMethodBuilder<TSource, TTarget> WithReentrancy();
3232

33+
/// <summary>
34+
/// Allows client calls to the grain.
35+
/// </summary>
36+
/// <returns>The current instance of <see cref="IMethodBuilder{TSource, TTarget}"/>.</returns>
37+
IMethodBuilder<TSource, TTarget> AllowClientCallGrain();
38+
3339
/// <summary>
3440
/// Specifies a method transition between two grains using method names.
3541
/// </summary>

ManagedCode.Orleans.Graph/Builder/MethodBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ public IMethodBuilder<TSource, TTarget> MethodsByName(params (string sourceMetho
6464
}
6565
return this;
6666
}
67+
68+
public IMethodBuilder<TSource, TTarget> AllowClientCallGrain()
69+
{
70+
_parent.AllowClientCallGrain<TSource>();
71+
_parent.AllowClientCallGrain<TTarget>();
72+
return this;
73+
}
6774

6875
public IMethodBuilder<TSource, TTarget> AllSourceMethodsToSpecificTargetMethods(params string[] targetMethods)
6976
{

ManagedCode.Orleans.Graph/Extensions/RequestContextHelper.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Linq;
12
using ManagedCode.Orleans.Graph.Interfaces;
23
using ManagedCode.Orleans.Graph.Models;
34
using Orleans;
@@ -20,7 +21,9 @@ public static bool TrackOutgoingCall(this IOutgoingGrainCallContext context)
2021
{
2122
var caller = context.SourceId is null
2223
? Constants.ClientCallerId
23-
: context.SourceContext!.GrainInstance!.GetType().Name;
24+
: context.SourceContext!.GrainInstance!.GetType()
25+
.GetInterfaces()
26+
.FirstOrDefault(i => typeof(IGrain).IsAssignableFrom(i))?.FullName;
2427

2528
var call = context.GetCallHistory();
2629
call.Push(new OutCall(caller, context.InterfaceName, context.MethodName));

ManagedCode.Orleans.Graph/GrainGraphManager.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)