public async Task ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration() { //make sure default value won't cause activation collection during wait time var defaultCollectionAgeLimit = WAIT_TIME.Multiply(2); Initialize(defaultCollectionAgeLimit); const int grainCount = 1000; var fullGrainTypeName = typeof(IdleActivationGcTestGrain2).FullName; List <Task> tasks = new List <Task>(); logger.Info("ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration: activating {0} grains.", grainCount); for (var i = 0; i < grainCount; ++i) { IIdleActivationGcTestGrain2 g = this.testCluster.GrainFactory.GetGrain <IIdleActivationGcTestGrain2>(Guid.NewGuid()); tasks.Add(g.Nop()); } await Task.WhenAll(tasks); int activationsCreated = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, fullGrainTypeName); Assert.Equal(grainCount, activationsCreated); logger.Info("ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration: grains activated; waiting {0} sec (activation GC idle timeout is {1} sec).", WAIT_TIME.TotalSeconds, DEFAULT_IDLE_TIMEOUT.TotalSeconds); await Task.Delay(WAIT_TIME); int activationsNotCollected = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, fullGrainTypeName); Assert.Equal(0, activationsNotCollected); }
public async Task ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration() { Initialize(); const int grainCount = 1000; var fullGrainTypeName = typeof(IdleActivationGcTestGrain2).FullName; List <Task> tasks = new List <Task>(); logger.Info("ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration: activating {0} grains.", grainCount); for (var i = 0; i < grainCount; ++i) { IIdleActivationGcTestGrain2 g = GrainClient.GrainFactory.GetGrain <IIdleActivationGcTestGrain2>(Guid.NewGuid()); tasks.Add(g.Nop()); } await Task.WhenAll(tasks); int activationsCreated = await TestUtils.GetActivationCount(fullGrainTypeName); Assert.Equal(grainCount, activationsCreated); logger.Info("ActivationCollectorShouldCollectIdleActivationsSpecifiedInPerTypeConfiguration: grains activated; waiting {0} sec (activation GC idle timeout is {1} sec).", WAIT_TIME.TotalSeconds, DEFAULT_IDLE_TIMEOUT.TotalSeconds); await Task.Delay(WAIT_TIME); int activationsNotCollected = await TestUtils.GetActivationCount(fullGrainTypeName); Assert.Equal(0, activationsNotCollected); }
public async Task ActivationCollectorShouldNotCollectBusyActivationsSpecifiedInPerTypeConfiguration() { //make sure default value won't cause activation collection during wait time var defaultCollectionAgeLimit = WAIT_TIME.Multiply(2); Initialize(defaultCollectionAgeLimit); const int idleGrainCount = 500; const int busyGrainCount = 500; var idleGrainTypeName = typeof(IdleActivationGcTestGrain2).FullName; var busyGrainTypeName = typeof(BusyActivationGcTestGrain2).FullName; List <Task> tasks0 = new List <Task>(); List <IBusyActivationGcTestGrain2> busyGrains = new List <IBusyActivationGcTestGrain2>(); logger.Info("ActivationCollectorShouldNotCollectBusyActivationsSpecifiedInPerTypeConfiguration: activating {0} busy grains.", busyGrainCount); for (var i = 0; i < busyGrainCount; ++i) { IBusyActivationGcTestGrain2 g = this.testCluster.GrainFactory.GetGrain <IBusyActivationGcTestGrain2>(Guid.NewGuid()); busyGrains.Add(g); tasks0.Add(g.Nop()); } await Task.WhenAll(tasks0); bool[] quit = new bool[] { false }; Func <Task> busyWorker = async() => { logger.Info("ActivationCollectorShouldNotCollectBusyActivationsSpecifiedInPerTypeConfiguration: busyWorker started"); List <Task> tasks1 = new List <Task>(); while (!quit[0]) { foreach (var g in busyGrains) { tasks1.Add(g.Nop()); } await Task.WhenAll(tasks1); } }; Task.Run(busyWorker).Ignore(); logger.Info("ActivationCollectorShouldNotCollectBusyActivationsSpecifiedInPerTypeConfiguration: activating {0} idle grains.", idleGrainCount); tasks0.Clear(); for (var i = 0; i < idleGrainCount; ++i) { IIdleActivationGcTestGrain2 g = this.testCluster.GrainFactory.GetGrain <IIdleActivationGcTestGrain2>(Guid.NewGuid()); tasks0.Add(g.Nop()); } await Task.WhenAll(tasks0); int activationsCreated = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, idleGrainTypeName) + await TestUtils.GetActivationCount(this.testCluster.GrainFactory, busyGrainTypeName); Assert.Equal(idleGrainCount + busyGrainCount, activationsCreated); logger.Info("IdleActivationCollectorShouldNotCollectBusyActivations: grains activated; waiting {0} sec (activation GC idle timeout is {1} sec).", WAIT_TIME.TotalSeconds, DEFAULT_IDLE_TIMEOUT.TotalSeconds); await Task.Delay(WAIT_TIME); // we should have only collected grains from the idle category (IdleActivationGcTestGrain2). int idleActivationsNotCollected = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, idleGrainTypeName); int busyActivationsNotCollected = await TestUtils.GetActivationCount(this.testCluster.GrainFactory, busyGrainTypeName); Assert.Equal(0, idleActivationsNotCollected); Assert.Equal(busyGrainCount, busyActivationsNotCollected); quit[0] = true; }