public virtual async Task MultiGrainWriteTransactionWithCommitFailure(string grainStates, int grainCount) { const int expected = 5; ITransactionCommitterTestGrain committer = this.grainFactory.GetGrain <ITransactionCommitterTestGrain>(Guid.NewGuid()); List <ITransactionTestGrain> grains = Enumerable.Range(0, grainCount) .Select(i => RandomTestGrain(grainStates)) .ToList(); ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid()); await coordinator.MultiGrainAdd(committer, new PassOperation("pass"), grains, expected); await Assert.ThrowsAsync <OrleansTransactionAbortedException>(() => coordinator.MultiGrainAdd(committer, new FailOperation("fail"), grains, expected)); foreach (var grain in grains) { var actualValues = await grain.Get(); foreach (var actual in actualValues) { Assert.Equal(expected, actual); } } // TODO : Add verification that commit service recieve call with proper args. }
public virtual async Task MultiGrainWriteTransactionWithCommitException(string grainStates, int grainCount) { const int expected = 5; ITransactionCommitterTestGrain committer = this.grainFactory.GetGrain <ITransactionCommitterTestGrain>(Guid.NewGuid()); List <ITransactionTestGrain> grains = Enumerable.Range(0, grainCount) .Select(i => RandomTestGrain(grainStates)) .ToList(); ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid()); await coordinator.MultiGrainAdd(committer, new PassOperation("pass"), grains, expected); Func <Task> task = () => coordinator.MultiGrainAdd(committer, new ThrowOperation("throw"), grains, expected); await task.Should().ThrowAsync <OrleansTransactionInDoubtException>(); foreach (var grain in grains) { var actualValues = await grain.Get(); foreach (var actual in actualValues) { actual.Should().Be(expected); } } // TODO : Add verification that commit service receive call with proper args. }
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()); }
/// <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 async Task MultiGrainWriteTransaction(string transactionTestGrainClassName) { const int expected = 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.MultiGrainAdd(grains, expected); foreach (var grain in grains) { await grain.Get(); } foreach (var grainId in grainIds) { await CheckReport(grainId, 2, 0, 2); } }
public virtual async Task MultiGrainWriteTransaction(string grainStates, int grainCount) { const int expected = 5; ITransactionCommitterTestGrain committer = this.grainFactory.GetGrain <ITransactionCommitterTestGrain>(Guid.NewGuid()); List <ITransactionTestGrain> grains = Enumerable.Range(0, grainCount) .Select(i => RandomTestGrain(grainStates)) .ToList(); ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid()); await coordinator.MultiGrainAdd(committer, new PassOperation("pass"), grains, expected); foreach (var grain in grains) { var actualValues = await grain.Get(); foreach (var actual in actualValues) { actual.ShouldBeEquivalentTo(expected); } } // TODO : Add verification that commit service recieve call with proper args. }
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); }
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 virtual async Task MultiGrainWriteTransaction(string transactionTestGrainClassName) { const int expected = 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.MultiGrainAdd(grains, expected); foreach (var grain in grains) { int actual = await grain.Get(); Assert.Equal(5, actual); } }
public virtual async Task MultiGrainWriteTransaction(string grainStates, int grainCount) { const int expected = 5; List <ITransactionTestGrain> grains = Enumerable.Range(0, grainCount) .Select(i => RandomTestGrain(grainStates)) .ToList(); ITransactionCoordinatorGrain coordinator = this.grainFactory.GetGrain <ITransactionCoordinatorGrain>(Guid.NewGuid()); await coordinator.MultiGrainAdd(grains, expected); foreach (var grain in grains) { var actualValues = await grain.Get(); foreach (var actual in actualValues) { actual.ShouldBeEquivalentTo(expected); } } }