Exemplo n.º 1
0
        public async Task BasicExceptionPropagation()
        {
            IExceptionGrain grain     = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             exception = await Assert.ThrowsAsync <InvalidOperationException>(
                () => grain.ThrowsInvalidOperationException());

            Assert.Equal("Test exception", exception.Message);
        }
Exemplo n.º 2
0
        public async Task GrainForwardingExceptionPropagation()
        {
            IExceptionGrain grain        = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             otherGrainId = GetRandomGrainId();
            var             exception    = await Assert.ThrowsAsync <InvalidOperationException>(
                () => grain.GrainCallToThrowsInvalidOperationException(otherGrainId));

            Assert.Equal("Test exception", exception.Message);
        }
Exemplo n.º 3
0
        public async Task BasicExceptionPropagation()
        {
            IExceptionGrain grain     = this.fixture.GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             exception = await Assert.ThrowsAsync <InvalidOperationException>(
                () => grain.ThrowsInvalidOperationException());

            output.WriteLine(exception.ToString());
            Assert.Equal("Test exception", exception.Message);
        }
Exemplo n.º 4
0
        public async Task ExceptionPropagationDoesNotUnwrapAggregateExceptions()
        {
            IExceptionGrain grain     = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             exception = await Assert.ThrowsAsync <AggregateException>(
                () => grain.ThrowsAggregateExceptionWrappingInvalidOperationException());

            var nestedEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerException);

            Assert.Equal("Test exception", nestedEx.Message);
        }
        public async Task SynchronousExceptionThrownShouldResultInFaultedTask()
        {
            IExceptionGrain grain = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());

            // start the grain call but don't await it nor wrap in try/catch, to make sure it doesn't throw synchronously
            var grainCallTask = grain.ThrowsSynchronousInvalidOperationException();

            var exception = await Assert.ThrowsAsync <InvalidOperationException>(() => grainCallTask);

            Assert.Equal("Test exception", exception.Message);
        }
Exemplo n.º 6
0
        public async Task ExceptionPropagationDoesNoFlattenAggregateExceptions()
        {
            IExceptionGrain grain     = this.fixture.GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             exception = await Assert.ThrowsAsync <AggregateException>(
                () => grain.ThrowsNestedAggregateExceptionsWrappingInvalidOperationException());

            var nestedAggEx    = Assert.IsAssignableFrom <AggregateException>(exception.InnerException);
            var doubleNestedEx = Assert.IsAssignableFrom <InvalidOperationException>(nestedAggEx.InnerException);

            Assert.Equal("Test exception", doubleNestedEx.Message);
        }
        public void ExceptionContainsOriginalStackTrace()
        {
            IExceptionGrain grain = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            // Explicitly using .Wait() instead of await the task to avoid any modification of the inner exception
            var aggEx = Assert.Throws <AggregateException>(
                () => grain.ThrowsInvalidOperationException().Wait());

            var exception = aggEx.InnerException;

            output.WriteLine(exception.ToString());
            Assert.IsAssignableFrom <InvalidOperationException>(exception);
            Assert.Equal("Test exception", exception.Message);
            Assert.Contains("ThrowsInvalidOperationException", exception.StackTrace);
        }
Exemplo n.º 8
0
        public void ExceptionPropagationForwardsEntireAggregateException()
        {
            IExceptionGrain grain     = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             grainCall = grain.ThrowsMultipleExceptionsAggregatedInFaultedTask();

            // use Wait() so that we get the entire AggregateException ('await' would just catch the first inner exception)
            var exception = Assert.Throws <AggregateException>(
                () => grainCall.Wait());

            // make sure that all exceptions in the task are present, and not just the first one.
            Assert.Equal(2, exception.InnerExceptions.Count);
            var firstEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[0]);

            Assert.Equal("Test exception 1", firstEx.Message);
            var secondEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[1]);

            Assert.Equal("Test exception 2", secondEx.Message);
        }
Exemplo n.º 9
0
        public async Task ExceptionContainsOriginalStackTraceWhenRethrowingLocally()
        {
            IExceptionGrain grain = this.fixture.GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());

            try
            {
                // Use await to force the exception to be rethrown and validate that the remote stack trace is still present
                await grain.ThrowsInvalidOperationException();

                Assert.True(false, "should have thrown");
            }
            catch (InvalidOperationException exception)
            {
                output.WriteLine(exception.ToString());
                Assert.IsAssignableFrom <InvalidOperationException>(exception);
                Assert.Equal("Test exception", exception.Message);
                Assert.Contains("ThrowsInvalidOperationException", exception.StackTrace);
            }
        }
        public async Task SynchronousAggregateExceptionThrownShouldResultInFaultedTaskWithOriginalAggregateExceptionUnmodifiedAsInnerException()
        {
            IExceptionGrain grain = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());

            // start the grain call but don't await it nor wrap in try/catch, to make sure it doesn't throw synchronously
            var grainCallTask = grain.ThrowsSynchronousAggregateExceptionWithMultipleInnerExceptions();

            // assert that the faulted task has an inner exception of type AggregateException, which should be our original exception
            var exception = await Assert.ThrowsAsync <AggregateException>(() => grainCallTask);

            Assert.Equal("Test AggregateException message", exception.Message);
            // make sure that all exceptions in the task are present, and not just the first one.
            Assert.Equal(2, exception.InnerExceptions.Count);
            var firstEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[0]);

            Assert.Equal("Test exception 1", firstEx.Message);
            var secondEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[1]);

            Assert.Equal("Test exception 2", secondEx.Message);
        }
Exemplo n.º 11
0
        public async Task TaskCancelationPropagation()
        {
            IExceptionGrain grain           = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             actualException = default(Exception);

            try
            {
                await grain.Cancelled();
            }
            catch (Exception exception)
            {
                actualException = exception;
            }

            Assert.IsNotNull(actualException, "Expected grain call to throw a cancellation exception.");
            Assert.IsTrue(actualException is AggregateException);
            Assert.AreEqual(
                typeof(TaskCanceledException),
                ((AggregateException)actualException).InnerException.GetType());
        }
        public void ExceptionPropagationForwardsEntireAggregateException()
        {
            IExceptionGrain grain     = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
            var             grainCall = grain.ThrowsMultipleExceptionsAggregatedInFaultedTask();

            try
            {
                // use Wait() so that we get the entire AggregateException ('await' would just catch the first inner exception)
                // Do not use Assert.Throws to avoid any tampering of the AggregateException itself from the test framework
                grainCall.Wait();
                Assert.True(false, "Expected AggregateException");
            }
            catch (AggregateException exception)
            {
                output.WriteLine(exception.ToString());
                // make sure that all exceptions in the task are present, and not just the first one.
                Assert.Equal(2, exception.InnerExceptions.Count);
                var firstEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[0]);
                Assert.Equal("Test exception 1", firstEx.Message);
                var secondEx = Assert.IsAssignableFrom <InvalidOperationException>(exception.InnerExceptions[1]);
                Assert.Equal("Test exception 2", secondEx.Message);
            }
        }
Exemplo n.º 13
0
 public async Task TaskCancelationPropagation()
 {
     IExceptionGrain grain = GrainFactory.GetGrain <IExceptionGrain>(GetRandomGrainId());
     await Assert.ThrowsAsync <TaskCanceledException>(
         () => grain.Canceled());
 }