// check that grain that throws an error breaks its promise and later Wait and GetValue on it will throw public void ErrorHandlingGrainError1() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task <int> intPromise = grain.GetAxBError(); try { intPromise.Wait(); Assert.True(false, "Should have thrown"); } catch (Exception) { Assert.True(intPromise.Status == TaskStatus.Faulted); } try { intPromise.Wait(); Assert.True(false, "Should have thrown"); } catch (Exception exc2) { Assert.True(intPromise.Status == TaskStatus.Faulted); Assert.Equal((new Exception("GetAxBError-Exception")).Message, exc2.GetBaseException().Message); } Assert.True(intPromise.Status == TaskStatus.Faulted); }
// check that premature wait finishes on time but does not throw with false and later wait throws. public void ErrorHandlingTimedMethodWithError() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task promise = grain.LongMethodWithError(2000); // there is a race in the test here. If run in debugger, the invocation can actually finish OK Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Assert.False(promise.Wait(1000), "The task shouldn't have completed yet."); stopwatch.Stop(); Assert.True(stopwatch.ElapsedMilliseconds >= 900, "Waited less than 900ms"); // check that we waited at least 0.9 second Assert.True(stopwatch.ElapsedMilliseconds <= 1100, "Waited longer than 1100ms"); try { promise.Wait(); Assert.True(false, "Should have thrown"); } catch (Exception) { } Assert.True(promise.Status == TaskStatus.Faulted); }
public async Task ErrorGrain_GetGrain() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = this.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); _ = await grain.GetA(); }
public async Task AC_DelayedExecutor_2() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task <bool> promise = grain.ExecuteDelayed(TimeSpan.FromMilliseconds(2000)); bool result = await promise; Assert.Equal(true, result); }
public void Timeout_LongMethod() { originalTimeout = RuntimeClient.Current.GetResponseTimeout(); bool finished = false; var grainName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainName); TimeSpan timeout = TimeSpan.FromMilliseconds(1000); RuntimeClient.Current.SetResponseTimeout(timeout); Task promise = grain.LongMethod((int)timeout.Multiply(4).TotalMilliseconds); //promise = grain.LongMethodWithError(2000); // there is a race in the test here. If run in debugger, the invocation can actually finish OK Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); try { finished = promise.Wait(timeout.Multiply(3)); Assert.Fail("Should have thrown"); } catch (Exception exc) { stopwatch.Stop(); Exception baseExc = exc.GetBaseException(); if (!(baseExc is TimeoutException)) { Assert.Fail("Should not have got here " + exc); } } Console.WriteLine("Waited for " + stopwatch.Elapsed); Assert.IsTrue(!finished); Assert.IsTrue(stopwatch.Elapsed >= timeout.Multiply(0.9), "Waited less than " + timeout.Multiply(0.9) + ". Waited " + stopwatch.Elapsed); Assert.IsTrue(stopwatch.Elapsed <= timeout.Multiply(2), "Waited longer than " + timeout.Multiply(2) + ". Waited " + stopwatch.Elapsed); Assert.IsTrue(promise.Status == TaskStatus.Faulted); // try to re-use the promise and should fail immideately. try { stopwatch = new Stopwatch(); promise.Wait(); Assert.Fail("Should have thrown"); } catch (Exception exc) { stopwatch.Stop(); Exception baseExc = exc.GetBaseException(); if (!(baseExc is TimeoutException)) { Assert.Fail("Should not have got here " + exc); } } Assert.IsTrue(stopwatch.Elapsed <= timeout.Multiply(0.1), "Waited longer than " + timeout.Multiply(0.1) + ". Waited " + stopwatch.Elapsed); Assert.IsTrue(promise.Status == TaskStatus.Faulted); }
public void ArgumentTypes_ListOfGrainReferences() { var grainFullName = typeof(ErrorGrain).FullName; List <IErrorGrain> list = new List <IErrorGrain>(); IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); list.Add(GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName)); list.Add(GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName)); bool ok = grain.AddChildren(list).Wait(timeout); if (!ok) { throw new TimeoutException(); } }
public async Task StressHandlingMultipleDelayedRequests() { IErrorGrain grain = this.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId()); bool once = true; List <Task> tasks = new List <Task>(); for (int i = 0; i < 500; i++) { Task promise = grain.DelayMethod(1); tasks.Add(promise); if (once) { once = false; promise.Wait(); } } await Task.WhenAll(tasks).WithTimeout(TimeSpan.FromSeconds(20)); }
public void StressHandlingMultipleDelayedRequests() { IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId()); bool once = true; List <Task> tasks = new List <Task>(); for (int i = 0; i < 500; i++) { Task promise = grain.DelayMethod(1); tasks.Add(promise); if (once) { once = false; promise.Wait(); } } Task.WhenAll(tasks).Wait(); Logger.Info(1, "DONE."); }
// check that premature wait finishes on time with false. public void ErrorHandlingTimedMethod() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = this.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task promise = grain.LongMethod(2000); // there is a race in the test here. If run in debugger, the invocation can actually finish OK Stopwatch stopwatch = Stopwatch.StartNew(); Assert.False(promise.Wait(1000), "The task shouldn't have completed yet."); // these asserts depend on timing issues and will be wrong for the sync version of OrleansTask Assert.True(stopwatch.ElapsedMilliseconds >= 900, $"Waited less than 900ms: ({stopwatch.ElapsedMilliseconds}ms)"); // check that we waited at least 0.9 second Assert.True(stopwatch.ElapsedMilliseconds <= 1300, $"Waited longer than 1300ms: ({stopwatch.ElapsedMilliseconds}ms)"); promise.Wait(); // just wait for the server side grain invocation to finish Assert.True(promise.Status == TaskStatus.RanToCompletion); }
// check that premature wait finishes on time but does not throw with false and later wait throws. public void ErrorHandlingTimedMethodWithError() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = this.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task promise = grain.LongMethodWithError(2000); // there is a race in the test here. If run in debugger, the invocation can actually finish OK Stopwatch stopwatch = Stopwatch.StartNew(); Assert.False(promise.Wait(1000), "The task shouldn't have completed yet."); stopwatch.Stop(); Assert.True(stopwatch.ElapsedMilliseconds >= 900, $"Waited less than 900ms: ({stopwatch.ElapsedMilliseconds}ms)"); // check that we waited at least 0.9 second Assert.True(stopwatch.ElapsedMilliseconds <= 1300, $"Waited longer than 1300ms: ({stopwatch.ElapsedMilliseconds}ms)"); Assert.ThrowsAsync <Exception>(() => promise).Wait(); Assert.True(promise.Status == TaskStatus.Faulted); }
// check that premature wait finishes on time with false. public void ErrorHandlingTimedMethod() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); Task promise = grain.LongMethod(2000); // there is a race in the test here. If run in debugger, the invocation can actually finish OK Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); bool finished = promise.Wait(TimeSpan.FromMilliseconds(1000)); stopwatch.Stop(); // these asserts depend on timing issues and will be wrong for the sync version of OrleansTask Assert.True(!finished); Assert.True(stopwatch.ElapsedMilliseconds >= 900, "Waited less than 900ms"); // check that we waited at least 0.9 second Assert.True(stopwatch.ElapsedMilliseconds <= 1100, "Waited longer than 1100ms"); promise.Wait(); // just wait for the server side grain invocation to finish Assert.True(promise.Status == TaskStatus.RanToCompletion); }
public async Task ErrorGrain_GetGrain() { var grainFullName = typeof(ErrorGrain).FullName; IErrorGrain grain = GrainClient.GrainFactory.GetGrain <IErrorGrain>(GetRandomGrainId(), grainFullName); int ignored = await grain.GetA(); }