コード例 #1
0
        public void BasicActivation_Reentrant_RecoveryAfterExpiredMessage()
        {
            List <Task> promises    = new List <Task>();
            var         client      = (IInternalClusterClient)this.Client;
            TimeSpan    prevTimeout = this.GetResponseTimeout();

            try
            {
                // set short response time and ask to do long operation, to trigger expired msgs in the silo queues.
                TimeSpan shortTimeout = TimeSpan.FromMilliseconds(1000);
                this.SetResponseTimeout(shortTimeout);

                ITestGrain grain = this.GrainFactory.GetGrain <ITestGrain>(GetRandomGrainId());
                int        num   = 10;
                for (long i = 0; i < num; i++)
                {
                    Task task = grain.DoLongAction(
                        TimeSpan.FromMilliseconds(shortTimeout.TotalMilliseconds * 3),
                        "A_" + i);
                    promises.Add(task);
                }
                try
                {
                    Task.WhenAll(promises).Wait();
                }
                catch (Exception)
                {
                    this.Logger.Info("Done with stress iteration.");
                }

                // wait a bit to make sure expired msgs in the silo is trigered.
                Thread.Sleep(TimeSpan.FromSeconds(10));

                // set the regular response time back, expect msgs ot succeed.
                this.SetResponseTimeout(prevTimeout);

                this.Logger.Info("About to send a next legit request that should succeed.");
                grain.DoLongAction(TimeSpan.FromMilliseconds(1), "B_" + 0).Wait();
                this.Logger.Info("The request succeeded.");
            }
            finally
            {
                // set the regular response time back, expect msgs ot succeed.
                this.SetResponseTimeout(prevTimeout);
            }
        }