Ejemplo n.º 1
0
        public virtual async Task MultiGrainReadWriteTransaction(string grainStates)
        {
            const int delta      = 5;
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions;

            List <ITransactionTestGrain> grains =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            await coordinator.MultiGrainDouble(grains);

            int expected = delta + delta;

            foreach (var grain in grains)
            {
                int[] actualValues = await grain.Get();

                foreach (var actual in actualValues)
                {
                    if (expected != actual)
                    {
                        this.output.WriteLine($"{grain} - failed");
                    }
                    Assert.Equal(expected, actual);
                }
            }
        }
        public virtual async Task MultiGrainReadWriteTransaction(string grainStates, int grainCount)
        {
            const int delta = 5;

            List <ITransactionTestGrain> grains =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(grainStates))
                .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            await coordinator.MultiGrainDouble(grains);

            int expected = delta + delta;

            foreach (var grain in grains)
            {
                int[] actualValues = await grain.Get();

                foreach (var actual in actualValues)
                {
                    if (expected != actual)
                    {
                        this.testOutput($"{grain} - failed");
                    }
                    actual.ShouldBeEquivalentTo(expected);
                }
            }
        }
        public virtual async Task RepeatGrainReadWriteTransaction(string transactionTestGrainClassName)
        {
            const int repeat     = 10;
            const int delta      = 5;
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions;

            List <Guid> grainIds = Enumerable.Range(0, grainCount)
                                   .Select(i => Guid.NewGuid())
                                   .ToList();

            List <ITransactionTestGrain> grains = grainIds
                                                  .Select(id => TestGrain(transactionTestGrainClassName, id))
                                                  .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            for (int i = 0; i < repeat; i++)
            {
                await coordinator.MultiGrainDouble(grains);

                int expected = delta * (int)Math.Pow(2, i + 1);
                foreach (var grain in grains)
                {
                    int actual = await grain.Get();

                    if (expected != actual)
                    {
                        this.output.WriteLine($"{grain} - failed");
                    }
                    Assert.Equal(expected, actual);
                }
            }
        }
        public virtual async Task MultiGrainReadWriteTransaction(string transactionTestGrainClassName)
        {
            const int delta      = 5;
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions;

            List <Guid> grainIds = Enumerable.Range(0, grainCount)
                                   .Select(i => Guid.NewGuid())
                                   .ToList();
            List <ITransactionTestGrain> grains = grainIds
                                                  .Select(id => TestGrain(transactionTestGrainClassName, id))
                                                  .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            await coordinator.MultiGrainDouble(grains);

            foreach (var grain in grains)
            {
                await grain.Get();
            }
            foreach (var grainId in grainIds)
            {
                await CheckReport(grainId, 3, 0, 3);
            }
        }
        public virtual async Task MultiGrainReadWriteTransaction(string transactionTestGrainClassName)
        {
            const int delta      = 5;
            const int grainCount = TransactionTestConstants.MaxCoordinatedTransactions;

            List <ITransactionTestGrain> grains =
                Enumerable.Range(0, grainCount)
                .Select(i => RandomTestGrain(transactionTestGrainClassName))
                .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            await coordinator.MultiGrainDouble(grains);

            int expected = delta + delta;

            foreach (var grain in grains)
            {
                int actual = await grain.Get();

                Assert.Equal(expected, actual);
            }
        }
        public virtual async Task RepeatGrainReadWriteTransaction(string grainStates, int grainCount)
        {
            const int repeat = 10;
            const int delta  = 5;

            List <Guid> grainIds = Enumerable.Range(0, grainCount)
                                   .Select(i => Guid.NewGuid())
                                   .ToList();

            List <ITransactionTestGrain> grains = grainIds
                                                  .Select(id => TestGrain(grainStates, id))
                                                  .ToList();

            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(grains, delta);

            for (int i = 0; i < repeat; i++)
            {
                await coordinator.MultiGrainDouble(grains);

                int expected = delta * (int)Math.Pow(2, i + 1);
                foreach (var grain in grains)
                {
                    int[] actualValues = await grain.Get();

                    foreach (var actual in actualValues)
                    {
                        if (expected != actual)
                        {
                            this.testOutput($"{grain} - failed");
                        }
                        actual.ShouldBeEquivalentTo(expected);
                    }
                }
            }
        }