コード例 #1
0
        internal static Task CallNext(IGrainFactory grainFactory, List <Tuple <long, bool> > callChain, int currCallIndex)
        {
            if (currCallIndex >= callChain.Count)
            {
                return(TaskDone.Done);
            }
            Tuple <long, bool> next = callChain[currCallIndex];
            bool call_1             = (currCallIndex % 2) == 1; // odd (1) call 1, even (zero) - call 2.

            if (next.Item2)
            {
                IDeadlockNonReentrantGrain nextGrain = grainFactory.GetGrain <IDeadlockNonReentrantGrain>(next.Item1);
                if (call_1)
                {
                    return(nextGrain.CallNext_1(callChain, currCallIndex + 1));
                }
                else
                {
                    return(nextGrain.CallNext_2(callChain, currCallIndex + 1));
                }
            }
            else
            {
                IDeadlockReentrantGrain nextGrain = grainFactory.GetGrain <IDeadlockReentrantGrain>(next.Item1);
                if (call_1)
                {
                    return(nextGrain.CallNext_1(callChain, currCallIndex + 1));
                }
                else
                {
                    return(nextGrain.CallNext_2(callChain, currCallIndex + 1));
                }
            }
        }
コード例 #2
0
        public async Task DeadlockDetection_3()
        {
            long baseGrainId = random.Next();
            long cBase       = 200;

            for (int i = 0; i < numIterations; i++)
            {
                long grainId = baseGrainId + i;
                IDeadlockReentrantGrain    firstGrain = this.fixture.GrainFactory.GetGrain <IDeadlockReentrantGrain>(grainId);
                List <Tuple <long, bool> > callChain  = new List <Tuple <long, bool> >();
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(grainId, true));
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(grainId, true));

                try
                {
                    await firstGrain.CallNext_1(callChain, 1);
                }
                catch (Exception exc)
                {
                    Exception baseExc = exc.GetBaseException();
                    this.fixture.Logger.Info(baseExc.Message);
                    Assert.Equal(typeof(DeadlockException), baseExc.GetType());
                    DeadlockException deadlockExc = (DeadlockException)baseExc;
                    Assert.Equal(callChain.Count, deadlockExc.CallChain.Count());
                }
            }
        }
コード例 #3
0
        public async Task DeadlockDetection_4()
        {
            long cBase = 200;

            for (int i = 0; i < numIterations; i++)
            {
                long grainId = i;
                IDeadlockReentrantGrain    firstGrain = GrainClient.GrainFactory.GetGrain <IDeadlockReentrantGrain>(grainId);
                List <Tuple <long, bool> > callChain  = new List <Tuple <long, bool> >();
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));

                await firstGrain.CallNext_1(callChain, 1);
            }
        }
コード例 #4
0
        // 4) No Deadlock X, X
        public async Task DeadlockDetection_4()
        {
            long baseGrainId = this.Random.Next();
            long xBase       = 1000;

            for (int i = 0; i < this.NumIterations; i++)
            {
                long grainId = baseGrainId + i;
                IDeadlockReentrantGrain    firstGrain = this.Fixture.GrainFactory.GetGrain <IDeadlockReentrantGrain>(grainId);
                List <Tuple <long, bool> > callChain  = new List <Tuple <long, bool> >();
                callChain.Add(new Tuple <long, bool>(xBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(xBase + grainId, false));

                await firstGrain.CallNext_1(callChain, 1);
            }
        }
コード例 #5
0
        public async Task DeadlockDetection_3()
        {
            long baseGrainId = random.Next();
            long cBase       = 200;

            for (int i = 0; i < numIterations; i++)
            {
                long grainId = baseGrainId + i;
                IDeadlockReentrantGrain    firstGrain = this.fixture.GrainFactory.GetGrain <IDeadlockReentrantGrain>(grainId);
                List <Tuple <long, bool> > callChain  = new List <Tuple <long, bool> >();
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(grainId, true));
                callChain.Add(new Tuple <long, bool>(cBase + grainId, false));
                callChain.Add(new Tuple <long, bool>(grainId, true));
                await Assert.ThrowsAsync <DeadlockException>(() => firstGrain.CallNext_1(callChain, 1));
            }
        }