Beispiel #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);
                    }
                }
            });
        }
        public void JsonConcertCanSerializeMetaData()
        {
            ITransactionTestGrain testGrain = this.RandomTestGrain(TransactionTestConstants.SingleStateTransactionalGrain);
            GrainReference        reference = (GrainReference)testGrain;
            var metaData = new TransactionalStateMetaData();

            metaData.TimeStamp = DateTime.UtcNow;
            metaData.CommitRecords.Add(Guid.NewGuid(), new CommitRecord()
            {
                Timestamp         = DateTime.UtcNow,
                WriteParticipants = new List <ParticipantId>()
                {
                    new ParticipantId("bob", reference, ParticipantId.Role.Resource | ParticipantId.Role.Manager)
                }
            });
            JsonSerializerSettings serializerSettings = TransactionalStateFactory.GetJsonSerializerSettings(
                this.fixture.Client.ServiceProvider.GetService <ITypeResolver>(),
                this.grainFactory);
            //should be able to serialize it
            string jsonMetaData = JsonConvert.SerializeObject(metaData, serializerSettings);

            TransactionalStateMetaData deseriliazedMetaData = JsonConvert.DeserializeObject <TransactionalStateMetaData>(jsonMetaData, serializerSettings);

            Assert.Equal(metaData.TimeStamp, deseriliazedMetaData.TimeStamp);
        }
        /// <summary>
        /// Single transaction containing two grains is dependent on two other transaction, one from each grain
        /// </summary>
        /// <param name="grainStates"></param>
        /// <returns></returns>
        public virtual async Task TransactionTreeTest(string grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain1 = RandomTestGrain(grainStates);
            ITransactionTestGrain        grain2 = RandomTestGrain(grainStates);
            ITransactionTestGrain        grain3 = RandomTestGrain(grainStates);
            ITransactionTestGrain        grain4 = RandomTestGrain(grainStates);
            List <ITransactionTestGrain> transaction1Members = new List <ITransactionTestGrain>(new[] { grain1, grain2 });
            List <ITransactionTestGrain> transaction2Members = new List <ITransactionTestGrain>(new[] { grain3, grain4 });
            List <ITransactionTestGrain> transaction3Members = new List <ITransactionTestGrain>(new[] { grain2, grain3 });

            ITransactionCoordinatorGrain coordinator1 = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());
            ITransactionCoordinatorGrain coordinator2 = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());
            ITransactionCoordinatorGrain coordinator3 = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());
            await Task.WhenAll(
                coordinator1.MultiGrainAdd(transaction1Members, expected),
                coordinator2.MultiGrainAdd(transaction2Members, expected),
                coordinator3.MultiGrainAdd(transaction3Members, expected));

            int[] actual = await grain1.Get();

            actual.FirstOrDefault().Should().Be(expected);
            actual = await grain2.Get();

            actual.FirstOrDefault().Should().Be(expected * 2);
            actual = await grain3.Get();

            actual.FirstOrDefault().Should().Be(expected * 2);
            actual = await grain4.Get();

            actual.FirstOrDefault().Should().Be(expected);
        }
 public virtual void TransactionGrainsThrowWhenTransactions(string transactionTestGrainClassName)
 {
     const int             delta = 5;
     ITransactionTestGrain grain = RandomTestGrain(transactionTestGrainClassName);
     Func <Task>           task  = () => grain.Set(delta);
     var response = task.ShouldThrow <OrleansTransactionsDisabledException>();
 }
Beispiel #5
0
        public virtual async Task SingleSharedGrainTest(string grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain1              = RandomTestGrain(grainStates);
            ITransactionTestGrain        grain2              = RandomTestGrain(grainStates);
            ITransactionTestGrain        sharedGrain         = RandomTestGrain(grainStates);
            List <ITransactionTestGrain> transaction1Members = new List <ITransactionTestGrain>(new[] { grain1, sharedGrain });
            List <ITransactionTestGrain> transaction2Members = new List <ITransactionTestGrain>(new[] { grain2, sharedGrain });

            ITransactionCoordinatorGrain coordinator1 = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());
            ITransactionCoordinatorGrain coordinator2 = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());
            await Task.WhenAll(
                coordinator1.MultiGrainAdd(transaction1Members, expected),
                coordinator2.MultiGrainAdd(transaction2Members, expected));

            int[] actual = await grain1.Get();

            Assert.Equal(expected, actual.FirstOrDefault());
            actual = await grain2.Get();

            Assert.Equal(expected, actual.FirstOrDefault());
            actual = await sharedGrain.Get();

            Assert.Equal(expected * 2, actual.FirstOrDefault());
        }
        public virtual async Task TransactionGrainsThrowWhenTransactions(string transactionTestGrainClassName)
        {
            const int             delta = 5;
            ITransactionTestGrain grain = RandomTestGrain(transactionTestGrainClassName);
            OrleansStartTransactionFailedException exception = await Assert.ThrowsAsync <OrleansStartTransactionFailedException>(() => grain.Set(delta));

            Assert.IsAssignableFrom <OrleansTransactionsDisabledException>(exception.InnerException);
        }
        public virtual async Task SingleGrainReadTransaction(string transactionTestGrainClassName)
        {
            Guid grainId = Guid.NewGuid();
            ITransactionTestGrain grain = TestGrain(transactionTestGrainClassName, grainId);
            await grain.Get();

            await CheckReport(grainId, 1, 0, 1);
        }
        public virtual async Task SingleGrainReadTransaction(string transactionTestGrainClassName)
        {
            const int expected = 0;

            ITransactionTestGrain grain = RandomTestGrain(transactionTestGrainClassName);
            int actual = await grain.Get();

            Assert.Equal(expected, actual);
        }
Beispiel #9
0
        public virtual async Task SingleGrainReadTransaction(string grainStates)
        {
            const int expected = 0;

            ITransactionTestGrain grain = RandomTestGrain(grainStates);
            var actualResults           = await grain.Get();

            //each transaction state should all be 0 since no operation was applied yet
            foreach (var actual in actualResults)
            {
                Assert.Equal(expected, actual);
            }
        }
Beispiel #10
0
        public virtual async Task SingleGrainWriteTransaction(string grainStates)
        {
            const int             delta = 5;
            ITransactionTestGrain grain = RandomTestGrain(grainStates);
            var original = await grain.Get();

            await grain.Add(delta);

            var expected = original.Select(value => value + delta).ToArray();
            var actual   = await grain.Get();

            Assert.Equal(expected, actual);
        }
        public virtual async Task SingleGrainWriteTransaction(string transactionTestGrainClassName)
        {
            const int             delta = 5;
            ITransactionTestGrain grain = RandomTestGrain(transactionTestGrainClassName);
            int original = await grain.Get();

            await grain.Add(delta);

            int expected = original + delta;
            int actual   = await grain.Get();

            Assert.Equal(expected, actual);
        }
        public virtual async Task SingleGrainWriteTransaction(string transactionTestGrainClassName)
        {
            const int             delta   = 5;
            Guid                  grainId = Guid.NewGuid();
            ITransactionTestGrain grain   = TestGrain(transactionTestGrainClassName, grainId);
            await grain.Get();

            await grain.Add(delta);

            await grain.Get();

            await CheckReport(grainId, 3, 0, 3);
        }
        public virtual async Task MultiWriteToSingleGrainTransaction(string transactionTestGrainClassName)
        {
            const int delta            = 5;
            const int concurrentWrites = 3;

            ITransactionTestGrain        grain  = RandomTestGrain(transactionTestGrainClassName);
            List <ITransactionTestGrain> grains = Enumerable.Repeat(grain, concurrentWrites).ToList();

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

            await coordinator.MultiGrainAdd(grains, delta);

            int expected = delta * concurrentWrites;
            int actual   = await grains[0].Get();

            Assert.Equal(expected, actual);
        }
        public virtual async Task MultiWriteToSingleGrainTransaction(string transactionTestGrainClassName)
        {
            const int delta            = 5;
            const int concurrentWrites = TransactionTestConstants.MaxCoordinatedTransactions;

            Guid grainId = Guid.NewGuid();
            ITransactionTestGrain        grain  = TestGrain(transactionTestGrainClassName, grainId);
            List <ITransactionTestGrain> grains = Enumerable.Repeat(grain, concurrentWrites).ToList();

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

            await coordinator.MultiGrainAdd(grains, delta);

            await grains[0].Get();

            await CheckReport(grainId, 2, 0, 2);
        }
Beispiel #15
0
        public async Task AbortTransactionOnExceptions(string transactionTestGrainClassName)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(transactionTestGrainClassName);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(new List <ITransactionTestGrain> {
                grain
            }, expected);

            await Assert.ThrowsAsync <OrleansTransactionAbortedException>(() => coordinator.AddAndThrow(grain, expected));

            await TestAfterDustSettles(async() =>
            {
                int actual = await grain.Get();
                Assert.Equal(expected, actual);
            });
        }
Beispiel #16
0
        public async Task AbortTransactionOnOrphanCalls(string transactionTestGrainClassName)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(transactionTestGrainClassName);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await grain.Set(expected);

            await Assert.ThrowsAsync <OrleansOrphanCallException>(() => coordinator.OrphanCallTransaction(grain));

            //await Task.Delay(20000); // give time for GC

            await TestAfterDustSettles(async() =>
            {
                int actual = await grain.Get();
                Assert.Equal(expected, actual);
            });
        }
        public virtual async Task MultiWriteToSingleGrainTransaction(string grainStates)
        {
            const int delta            = 5;
            const int concurrentWrites = 3;

            ITransactionTestGrain        grain  = RandomTestGrain(grainStates);
            List <ITransactionTestGrain> grains = Enumerable.Repeat(grain, concurrentWrites).ToList();

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

            await coordinator.MultiGrainAdd(grains, delta);

            int expected = delta * concurrentWrites;

            int[] actualValues = await grains[0].Get();
            foreach (var actual in actualValues)
            {
                actual.ShouldBeEquivalentTo(expected);
            }
        }
        public async Task AbortTransactionOnExceptions(TransactionTestConstants.TransactionGrainStates grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(grainStates);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(new List <ITransactionTestGrain> {
                grain
            }, expected);

            await Assert.ThrowsAsync <OrleansTransactionAbortedException>(() => coordinator.AddAndThrow(grain, expected));

            await TestAfterDustSettles(async() =>
            {
                int[] actualValues = await grain.Get();
                foreach (var actual in actualValues)
                {
                    Assert.Equal(expected, actual);
                }
            });
        }
        public async Task AbortTransactionOnOrphanCalls(TransactionTestConstants.TransactionGrainStates grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(grainStates);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await grain.Set(expected);

            await Assert.ThrowsAsync <OrleansOrphanCallException>(() => coordinator.OrphanCallTransaction(grain));

            //await Task.Delay(20000); // give time for GC

            await TestAfterDustSettles(async() =>
            {
                int[] actualValues = await grain.Get();
                foreach (var actual in actualValues)
                {
                    Assert.Equal(expected, actual);
                }
            });
        }
        public virtual async Task AbortTransactionOnOrphanCalls(string grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(grainStates);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await grain.Set(expected);

            Func <Task> task = () => coordinator.OrphanCallTransaction(grain);
            await task.Should().ThrowAsync <OrleansOrphanCallException>();

            //await Task.Delay(20000); // give time for GC

            await TestAfterDustSettles(async() =>
            {
                int[] actualValues = await grain.Get();
                foreach (var actual in actualValues)
                {
                    actual.Should().Be(expected);
                }
            });
        }
        public virtual async Task AbortTransactionOnExceptions(string grainStates)
        {
            const int expected = 5;

            ITransactionTestGrain        grain       = RandomTestGrain(grainStates);
            ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid());

            await coordinator.MultiGrainSet(new List <ITransactionTestGrain> {
                grain
            }, expected);

            Func <Task> task = () => coordinator.AddAndThrow(grain, expected);
            await task.Should().ThrowAsync <OrleansTransactionAbortedException>();

            await TestAfterDustSettles(async() =>
            {
                int[] actualValues = await grain.Get();
                foreach (var actual in actualValues)
                {
                    actual.Should().Be(expected);
                }
            });
        }
Beispiel #22
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);
                    }
                }
            });
        }
Beispiel #23
0
        private async Task Double(ITransactionTestGrain grain)
        {
            int[] values = await grain.Get();

            await grain.Add(values[0]);
        }
Beispiel #24
0
        public async Task AddAndThrow(ITransactionTestGrain grain, int numberToAdd)
        {
            await grain.Add(numberToAdd);

            throw new Exception("This should abort the transaction");
        }
Beispiel #25
0
        public Task OrphanCallTransaction(ITransactionTestGrain grain)
        {
            Task t = grain.Add(1000);

            return(Task.CompletedTask);
        }
        public async Task MultiGrainAddAndThrow(ITransactionTestGrain throwGrain, List <ITransactionTestGrain> grains, int numberToAdd)
        {
            await Task.WhenAll(grains.Select(g => g.Add(numberToAdd)));

            await throwGrain.AddAndThrow(numberToAdd);
        }