Skip to content

Commit

Permalink
Remove activation from message target list if constructor threw an ex…
Browse files Browse the repository at this point in the history
…ception (#5960)
  • Loading branch information
benjaminpetit authored and sergeybykov committed Sep 25, 2019
1 parent 65fa363 commit 6dcda70
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/OrleansRuntime/Catalog/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,17 @@ public ActivationData GetOrCreateActivation(
CounterStatistic.FindOrCreate(StatisticNames.CATALOG_ACTIVATION_NON_EXISTENT_ACTIVATIONS).Increment();
throw new NonExistentActivationException(msg, address, placement is StatelessWorkerPlacement);
}

SetupActivationInstance(result, grainType, genericArguments);

try
{
SetupActivationInstance(result, grainType, genericArguments);
}
catch
{
// Exception was thrown when trying to constuct the grain
UnregisterMessageTarget(result);
throw;
}
activatedPromise = InitActivation(result, grainType, genericArguments, requestContextData);
return result;
}
Expand Down
14 changes: 14 additions & 0 deletions test/DefaultCluster.Tests/StatelessWorkerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public StatelessWorkerTests(DefaultClusterFixture fixture, ITestOutputHelper out
}

[Fact, TestCategory("SlowBVT"), TestCategory("Functional"), TestCategory("StatelessWorker")]




public async Task StatelessWorkerThrowExceptionConstructor()
{
var grain = this.GrainFactory.GetGrain<IStatelessWorkerExceptionGrain>(0);
for (int i = 0; i < 100; i++)
{
await Assert.ThrowsAsync<OrleansException>(() => grain.Ping());
}
}

[Fact, TestCategory("SlowBVT"), TestCategory("Functional"), TestCategory("StatelessWorker")]
public async Task StatelessWorkerActivationsPerSiloDoNotExceedMaxLocalWorkersCount()
{
var gatewaysCount = HostedCluster.ClientConfiguration.Gateways.Count;
Expand Down
12 changes: 12 additions & 0 deletions test/TestGrainInterfaces/IStatelessWorkerExceptionGrain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Orleans;

namespace UnitTests.GrainInterfaces
{
public interface IStatelessWorkerExceptionGrain : IGrainWithIntegerKey
{
Task Ping();
}
}
1 change: 1 addition & 0 deletions test/TestGrainInterfaces/TestGrainInterfaces.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<Compile Include="ISimpleGenericGrain.cs" />
<Compile Include="CodegenTestInterfaces.cs" />
<Compile Include="ISimpleGrainWithAsyncMethods.cs" />
<Compile Include="IStatelessWorkerExceptionGrain.cs" />
<Compile Include="IStatelessWorkerGrain.cs" />
<Compile Include="ISimpleObserverableGrain.cs" />
<Compile Include="IObserverGrain.cs" />
Expand Down
29 changes: 29 additions & 0 deletions test/TestGrains/StatelessWorkerExceptionGrain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Orleans;
using Orleans.Concurrency;
using Orleans.Runtime;
using UnitTests.GrainInterfaces;


namespace UnitTests.Grains
{
[StatelessWorker(MaxLocalWorkers)]
public class StatelessWorkerExceptionGrain : Grain, IStatelessWorkerExceptionGrain
{
public const int MaxLocalWorkers = 1;

public StatelessWorkerExceptionGrain()
{
throw new Exception("oops");
}

public Task Ping()
{
return Task.CompletedTask;
}
}
}
1 change: 1 addition & 0 deletions test/TestGrains/TestGrains.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="SQLAdapter\DeviceGrain.cs" />
<Compile Include="SQLAdapter\ICustomerState.cs" />
<Compile Include="SQLAdapter\IDeviceState.cs" />
<Compile Include="StatelessWorkerExceptionGrain.cs" />
<Compile Include="StatelessWorkerGrain.cs" />
<Compile Include="SimpleObserverableGrain.cs" />
<Compile Include="ObserverGrain.cs" />
Expand Down

0 comments on commit 6dcda70

Please sign in to comment.