Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warmup for testing constructor types #237

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions Gigya.Microdot.Orleans.Ninject.Host/GrainsWarmup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Gigya.Microdot.Hosting.HttpService;
using Gigya.Microdot.Interfaces.Logging;
using Ninject;
using Ninject.Extensions.Factory;
using Orleans;
using Orleans.Core;
using Orleans.Runtime;
Expand Down Expand Up @@ -64,17 +66,27 @@ public void Warmup()
{
try
{
foreach (Type parameterType in serviceClass.GetConstructors().SelectMany(ctor => ctor.GetParameters().Select(p => p.ParameterType)).Distinct())
foreach (ConstructorInfo ctorInfo in serviceClass.GetConstructors())
{
try
//IGrainIdentity and IGrainRuntime are used in the constructor intended for tests
//We don't need to warm up it
if (ctorInfo.GetParameters().Any(p => p.ParameterType == typeof(IGrainIdentity) || p.ParameterType == typeof(IGrainRuntime)))
{
_kernel.Get(parameterType);
continue;
}
catch //No exception handling needed. We try to warmup all constructor types. In case of failure, write the warning for non orleans types and go to the next type

foreach (Type parameterType in ctorInfo.GetParameters().Select(p => p.ParameterType).Distinct())
{
if (!_orleansInternalTypes.Contains(parameterType))
try
{
_kernel.Get(parameterType);
}
catch //No exception handling needed. We try to warmup all constructor types. In case of failure, write the warning for non orleans types and go to the next type
{
failedWarmupWarn.Add($"Type {parameterType} of grain {serviceClass}");
if (!_orleansInternalTypes.Contains(parameterType))
{
failedWarmupWarn.Add($"Type {parameterType} of grain {serviceClass}");
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Compile Include="GrainAgeLimitServiceTests.cs" />
<Compile Include="Microservice\CalculatorService\IGarinAgeLimitService.cs" />
<Compile Include="Microservice\WarmupTestService\GigyaSiloHostFake.cs" />
<Compile Include="Microservice\WarmupTestService\TestGrain.cs" />
<Compile Include="Microservice\WarmupTestService\WarmupTestServiceGrain.cs" />
<Compile Include="Microservice\WarmupTestService\WarmupTestServiceHostWithSiloHostFake.cs" />
<Compile Include="Validation\ConfigObjectTypeValidatorTest.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using NUnit.Framework;
using Orleans;
using Orleans.Core;
using Orleans.Runtime;

namespace Gigya.Microdot.Orleans.Hosting.UnitTests.Microservice.WarmupTestService
{
public class TestGrain : Grain, IGrainWithIntegerKey
{
public TestGrain(IGrainIdentity grainIdentity, IGrainRuntime graintRuntime, TestType t, int i) : base(grainIdentity, graintRuntime)
{}
}

public class UsualGrain : Grain, IGrainWithIntegerKey
{
public UsualGrain(UsualType u)
{}
}

public class TestType
{
public TestType()
{
Assert.Fail("Should not warm up grain constructor for testing");
}
}

public class UsualType
{
public UsualType()
{
Console.WriteLine("UsualGrain is warmed as expected");
}
}
}
21 changes: 21 additions & 0 deletions tests/Gigya.Microdot.Orleans.Hosting.UnitTests/WarmupTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using Gigya.Microdot.Fakes;
using Gigya.Microdot.Hosting.HttpService;
using Gigya.Microdot.Ninject;
using Gigya.Microdot.Orleans.Hosting.UnitTests.Microservice.CalculatorService;
using Gigya.Microdot.Orleans.Hosting.UnitTests.Microservice.WarmupTestService;
using Gigya.Microdot.Orleans.Ninject.Host;
using Gigya.Microdot.Testing.Service;
using Gigya.Microdot.Testing.Shared;
using Ninject;
using NUnit.Framework;

Expand Down Expand Up @@ -41,5 +47,20 @@ public async Task VerifyWarmupBeforeSiloStart()
Task.Run(() => host.Run());
await host.WaitForHostDisposed();
}

[Test]
public async Task ShouldNotWarmupGrainTestingConstructor()
{
TestingKernel<ConsoleLog> kernel = new TestingKernel<ConsoleLog>(k =>
{
k.Rebind<TestGrain>().ToSelf();
k.Rebind<UsualGrain>().ToSelf();
k.Rebind<IWarmup>().To<GrainsWarmup>().InSingletonScope();
k.Rebind<IServiceInterfaceMapper>().To<OrleansServiceInterfaceMapper>().InSingletonScope();
});

IWarmup grainsWarmup = kernel.Get<IWarmup>();
grainsWarmup.Warmup();
}
}
}