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 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 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); }
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); } }
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 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); }); }
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 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 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); } }); }
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); } }); }
private async Task Double(ITransactionTestGrain grain) { int[] values = await grain.Get(); await grain.Add(values[0]); }