Exemplo n.º 1
0
        public async Task MultiGrainAbortTransactionOnExceptions(string grainStates)
        {
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions - 1;
            const int expected   = 5;

            ITransactionTestGrain        throwGrain = RandomTestGrain(grainStates);
            List <ITransactionTestGrain> grains     =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await throwGrain.Set(expected);

            await coordinator.MultiGrainSet(grains, expected);

            await Assert.ThrowsAsync <OrleansTransactionAbortedException>(() => coordinator.MultiGrainAddAndThrow(throwGrain, grains, expected));

            grains.Add(throwGrain);

            await TestAfterDustSettles(async() =>
            {
                foreach (var grain in grains)
                {
                    int[] actualValues = await grain.Get();
                    foreach (var actual in actualValues)
                    {
                        Assert.Equal(expected, actual);
                    }
                }
            });
        }
Exemplo n.º 2
0
        public virtual async Task AbortTransactionExceptionInnerExceptionOnlyContainsOneRootCauseException(string grainStates)
        {
            const int throwGrainCount = 3;
            const int grainCount      = TransactionTestConstants.MaxCoordinatedTransactions - throwGrainCount;
            const int expected        = 5;

            List <ITransactionTestGrain> throwGrains = Enumerable.Range(0, throwGrainCount)
                                                       .Select(i => RandomTestGrain(grainStates))
                                                       .ToList();
            List <ITransactionTestGrain> grains =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(throwGrains, expected);

            await coordinator.MultiGrainSet(grains, expected);

            async Task InnerExceptionCheck()
            {
                try
                {
                    await coordinator.MultiGrainAddAndThrow(throwGrains, grains, expected);
                }
                catch (Exception e)
                {
                    e.InnerException.Should().BeOfType <AddAndThrowException>();
                    throw;
                }
            }

            Func <Task> task = () => InnerExceptionCheck();

            task.ShouldThrow <OrleansTransactionAbortedException>();

            grains.AddRange(throwGrains);

            await TestAfterDustSettles(async() =>
            {
                foreach (var grain in grains)
                {
                    int[] actualValues = await grain.Get();
                    foreach (var actual in actualValues)
                    {
                        actual.ShouldBeEquivalentTo(expected);
                    }
                }
            });
        }
Exemplo n.º 3
0
        public async Task AbortTransactionExceptionInnerExceptionOnlyContainsOneRootCauseException(string grainStates)
        {
            const int throwGrainCount = 3;
            const int grainCount      = TransactionTestConstants.MaxCoordinatedTransactions - throwGrainCount;
            const int expected        = 5;

            List <ITransactionTestGrain> throwGrains = Enumerable.Range(0, throwGrainCount)
                                                       .Select(i => RandomTestGrain(grainStates))
                                                       .ToList();
            List <ITransactionTestGrain> grains =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(throwGrains, expected);

            await coordinator.MultiGrainSet(grains, expected);

            async Task InnerExceptionCheck()
            {
                try
                {
                    await coordinator.MultiGrainAddAndThrow(throwGrains, grains, expected);
                }
                catch (Exception e)
                {
                    Assert.True(e.InnerException is AddAndThrowException);
                    throw e;
                }
            }

            await Assert.ThrowsAsync <OrleansTransactionAbortedException>(() => InnerExceptionCheck());

            grains.AddRange(throwGrains);

            await TestAfterDustSettles(async() =>
            {
                foreach (var grain in grains)
                {
                    int[] actualValues = await grain.Get();
                    foreach (var actual in actualValues)
                    {
                        Assert.Equal(expected, actual);
                    }
                }
            });
        }
Exemplo n.º 4
0
        public virtual async Task MultiGrainAbortTransactionOnExceptions(string grainStates)
        {
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions - 1;
            const int expected   = 5;

            ITransactionTestGrain        throwGrain = RandomTestGrain(grainStates);
            List <ITransactionTestGrain> grains     =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await throwGrain.Set(expected);

            await coordinator.MultiGrainSet(grains, expected);

            Func <Task> task = () => coordinator.MultiGrainAddAndThrow(new List <ITransactionTestGrain>()
            {
                throwGrain
            }, grains, expected);

            task.ShouldThrow <OrleansTransactionAbortedException>();
            grains.Add(throwGrain);

            await TestAfterDustSettles(async() =>
            {
                foreach (var grain in grains)
                {
                    int[] actualValues = await grain.Get();
                    foreach (var actual in actualValues)
                    {
                        actual.ShouldBeEquivalentTo(expected);
                    }
                }
            });
        }