Skip to content

Commit

Permalink
Replace DuplicateActivationException with a strongly-typed return val…
Browse files Browse the repository at this point in the history
…ue (#3130)
  • Loading branch information
ReubenBond authored and sergeybykov committed Jun 19, 2017
1 parent 5604368 commit 5b89ba8
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 170 deletions.
2 changes: 1 addition & 1 deletion src/Orleans/Statistics/StatisticNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ internal class StatisticNames
public static readonly StatisticName CATALOG_ACTIVATION_SHUTDOWN_VIA_DIRECT_SHUTDOWN = new StatisticName("Catalog.Activation.Shutdown.ViaDirectShutdown");
public static readonly StatisticName CATALOG_ACTIVATION_SHUTDOWN_VIA_DEACTIVATE_STUCK_ACTIVATION = new StatisticName("Catalog.Activation.Shutdown.ViaDeactivateStuckActivation");
public static readonly StatisticName CATALOG_ACTIVATION_NON_EXISTENT_ACTIVATIONS = new StatisticName("Catalog.Activation.NonExistentActivations");
public static readonly StatisticName CATALOG_ACTIVATION_DUPLICATE_ACTIVATIONS = new StatisticName("Catalog.Activation.DuplicateActivations");
public static readonly StatisticName CATALOG_ACTIVATION_CONCURRENT_REGISTRATION_ATTEMPTS = new StatisticName("Catalog.Activation.ConcurrentRegistrationAttempts");

// Dispatcher
public static readonly StatisticName DISPATCHER_NEW_PLACEMENT = new StatisticName("Dispatcher.NewPlacement");
Expand Down
299 changes: 156 additions & 143 deletions src/OrleansRuntime/Catalog/Catalog.cs

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/OrleansRuntime/Core/Dispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,14 @@ internal void ProcessRequestsToInvalidActivation(
{
this.localGrainDirectory.InvalidateCacheEntry(oldAddress);
}
logger.Info(ErrorCode.Messaging_Dispatcher_ForwardingRequests,
String.Format("Forwarding {0} requests to old address {1} after {2}.", messages.Count, oldAddress, failedOperation));

if (logger.IsInfo)
{
logger.Info(ErrorCode.Messaging_Dispatcher_ForwardingRequests,
string.Format("Forwarding {0} requests destined for address {1} to address {2} after {3}.",
messages.Count, oldAddress, forwardingAddress,
failedOperation));
}

// IMPORTANT: do not do anything on activation context anymore, since this activation is invalid already.
scheduler.QueueWorkItem(new ClosureWorkItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ internal class PerfCounterConfigData
new PerfCounterConfigData {Name = StatisticNames.MESSAGE_CENTER_SEND_QUEUE_LENGTH},
new PerfCounterConfigData {Name = StatisticNames.SCHEDULER_PENDINGWORKITEMS},
new PerfCounterConfigData {Name = StatisticNames.CATALOG_ACTIVATION_COUNT},
new PerfCounterConfigData {Name = StatisticNames.CATALOG_ACTIVATION_DUPLICATE_ACTIVATIONS},
new PerfCounterConfigData {Name = StatisticNames.CATALOG_ACTIVATION_CONCURRENT_REGISTRATION_ATTEMPTS},
new PerfCounterConfigData {Name = StatisticNames.RUNTIME_GC_TOTALMEMORYKB},
new PerfCounterConfigData {Name = StatisticNames.RUNTIME_DOT_NET_THREADPOOL_INUSE_WORKERTHREADS},
new PerfCounterConfigData {Name = StatisticNames.RUNTIME_DOT_NET_THREADPOOL_INUSE_COMPLETIONPORTTHREADS},
Expand Down
22 changes: 10 additions & 12 deletions test/NonSilo.Tests/OrleansRuntime/ExceptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,28 @@ public ExceptionsTests(TestEnvironmentFixture fixture)
[Fact, TestCategory("Functional"), TestCategory("Serialization")]
public void SerializationTests_Exception_DotNet()
{
ActivationAddress activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());
SiloAddress primaryDirectoryForGrain = SiloAddress.NewLocalAddress(6789);
var activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());

Catalog.DuplicateActivationException original = new Catalog.DuplicateActivationException(activationAddress, primaryDirectoryForGrain);
Catalog.DuplicateActivationException output = TestingUtils.RoundTripDotNetSerializer(original, this.fixture.GrainFactory, this.fixture.SerializationManager);
var original = new Catalog.NonExistentActivationException("Some message", activationAddress, false);
var output = TestingUtils.RoundTripDotNetSerializer(original, this.fixture.GrainFactory, this.fixture.SerializationManager);

Assert.Equal(original.Message, output.Message);
Assert.Equal(original.ActivationToUse, output.ActivationToUse);
Assert.Equal(original.PrimaryDirectoryForGrain, output.PrimaryDirectoryForGrain);
Assert.Equal(original.NonExistentActivation, output.NonExistentActivation);
Assert.Equal(original.IsStatelessWorker, output.IsStatelessWorker);
}
#endif

[Fact, TestCategory("Functional"), TestCategory("Serialization")]
public void SerializationTests_Exception_Orleans()
{
ActivationAddress activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());
SiloAddress primaryDirectoryForGrain = SiloAddress.NewLocalAddress(6789);
var activationAddress = ActivationAddress.NewActivationAddress(SiloAddress.NewLocalAddress(12345), GrainId.NewId());

Catalog.DuplicateActivationException original = new Catalog.DuplicateActivationException(activationAddress, primaryDirectoryForGrain);
Catalog.DuplicateActivationException output = this.fixture.SerializationManager.RoundTripSerializationForTesting(original);
var original = new Catalog.NonExistentActivationException("Some message", activationAddress, false);
var output = this.fixture.SerializationManager.RoundTripSerializationForTesting(original);

Assert.Equal(original.Message, output.Message);
Assert.Equal(original.ActivationToUse, output.ActivationToUse);
Assert.Equal(original.PrimaryDirectoryForGrain, output.PrimaryDirectoryForGrain);
Assert.Equal(original.NonExistentActivation, output.NonExistentActivation);
Assert.Equal(original.IsStatelessWorker, output.IsStatelessWorker);
}
}
}
2 changes: 1 addition & 1 deletion test/TestGrainInterfaces/ICatalogTestGrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace UnitTests.GrainInterfaces
{
public interface ICatalogTestGrain : IGrainWithStringKey
public interface ICatalogTestGrain : IGrainWithIntegerKey
{
Task Initialize();
Task BlastCallNewGrains(int nGrains, long startingKey, int nCallsToEach);
Expand Down
11 changes: 5 additions & 6 deletions test/TestGrains/CatalogTestGrain.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Orleans;
using UnitTests.GrainInterfaces;
Expand All @@ -19,19 +18,19 @@ public Task Initialize()
return Task.CompletedTask;
}

public async Task BlastCallNewGrains(int nGrains, long startingKey, int nCallsToEach)
public Task BlastCallNewGrains(int nGrains, long startingKey, int nCallsToEach)
{
var promises = new List<Task>();
var promises = new List<Task>(nGrains * nCallsToEach);

for (int i = 0; i < nGrains; i++)
{
var grain = GrainFactory.GetGrain<ICatalogTestGrain>((startingKey + i).ToString(CultureInfo.InvariantCulture));
var grain = GrainFactory.GetGrain<ICatalogTestGrain>(startingKey + i);

for(int j=0; j<nCallsToEach; j++)
for (int j = 0; j < nCallsToEach; j++)
promises.Add(grain.Initialize());
}

await Task.WhenAll(promises);
return Task.WhenAll(promises);
}
}
}
9 changes: 5 additions & 4 deletions test/Tester/DuplicateActivationsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using Orleans.Runtime;
using Orleans.Runtime.Configuration;
using Orleans.TestingHost;
using TestExtensions;
Expand Down Expand Up @@ -34,16 +35,16 @@ public DuplicateActivationsTests(Fixture fixture)
public async Task DuplicateActivations()
{
const int nRunnerGrains = 100;
const int nTargetGRain = 10;
const int nTargetGrain = 10;
const int startingKey = 1000;
const int nCallsToEach = 100;

var runnerGrains = new ICatalogTestGrain[nRunnerGrains];

var promises = new List<Task>();
var promises = new List<Task>(nRunnerGrains);
for (int i = 0; i < nRunnerGrains; i++)
{
runnerGrains[i] = this.fixture.GrainFactory.GetGrain<ICatalogTestGrain>(i.ToString(CultureInfo.InvariantCulture));
runnerGrains[i] = this.fixture.GrainFactory.GetGrain<ICatalogTestGrain>(-i);
promises.Add(runnerGrains[i].Initialize());
}

Expand All @@ -52,7 +53,7 @@ public async Task DuplicateActivations()

for (int i = 0; i < nRunnerGrains; i++)
{
promises.Add(runnerGrains[i].BlastCallNewGrains(nTargetGRain, startingKey, nCallsToEach));
promises.Add(runnerGrains[i].BlastCallNewGrains(nTargetGrain, startingKey, nCallsToEach));
}

await Task.WhenAll(promises);
Expand Down

0 comments on commit 5b89ba8

Please sign in to comment.