public void OnNext(IFailedTask value) { _numFailedTasksReceived++; if (value.Id != TaskId) { throw new Exception("Received Task ID " + value.Id + " instead of the expected Task ID " + TaskId); } // since in this test exception is thrown by Threading.Tasks.Task spawned in our Task // the exception is wrapped in AggregateException with "One or more errors occurred." message if (value.Message == null || value.Message != "One or more errors occurred.") { throw new Exception("Exception message not properly propagated. Received message " + value.Message); } if (_shouldReceiveSerializableException) { if (value.AsError() == null || !(value.AsError() is AggregateException)) { throw new Exception("Outer exception should have been an AggregateException. " + value.AsError()); } var inner = value.AsError().InnerException; if (inner == null || !(inner is TestSerializableException)) { throw new Exception("Exception should have been serialized properly."); } if (inner.Message != ExpectedExceptionMessage) { throw new Exception("Incorrect Exception message, got message: " + value.AsError().Message); } if (_numFailedTasksReceived == 2) { Logger.Log(Level.Error, FailedTaskMessage); } value.GetActiveContext().Value.Dispose(); } else { var nonSerializableTaskException = value.AsError() as NonSerializableTaskException; if (nonSerializableTaskException == null) { throw new Exception( "Expected a NonSerializableTaskException from Task, instead got Exception of type " + value.AsError().GetType()); } if (!(nonSerializableTaskException.InnerException is SerializationException)) { throw new Exception("Expected a SerializationException as the inner Exception of the Task Exception."); } _shouldReceiveSerializableException = true; value.GetActiveContext().Value.SubmitTask(GetTaskConfiguration()); } }
public void OnNext(IFailedTask value) { _numFailedTasksReceived++; if (value.Id != TaskId) { throw new Exception("Received Task ID " + value.Id + " instead of the expected Task ID " + TaskId); } if (value.Message == null || value.Message != ExpectedExceptionMessage) { throw new Exception("Exception message not properly propagated. Received message " + value.Message); } if (_shouldReceiveSerializableException) { if (_numFailedTasksReceived == NumFailedTasksExpected) { Logger.Log(Level.Error, FailedTaskMessage); } if (value.AsError() == null || !(value.AsError() is TestSerializableException)) { throw new Exception("Exception should have been serialized properly."); } if (value.AsError().Message != ExpectedExceptionMessage) { throw new Exception("Incorrect Exception message, got message: " + value.AsError().Message); } value.GetActiveContext().Value.Dispose(); } else { var taskException = value.AsError(); if (taskException == null) { throw new Exception("Expected a non-null task exception."); } var nonSerializableTaskException = taskException as NonSerializableTaskException; if (nonSerializableTaskException == null) { throw new Exception( "Expected a NonSerializableTaskException from Task, instead got Exception of type " + taskException.GetType()); } if (!(nonSerializableTaskException.InnerException is SerializationException)) { throw new Exception("Expected a SerializationException as the inner Exception of the Task Exception."); } _shouldReceiveSerializableException = true; value.GetActiveContext().Value.SubmitTask(GetTaskConfiguration()); } }
/// <summary> /// Creates a mock FailedTask with specified taskId and error message /// </summary> /// <param name="taskId"></param> /// <param name="errorMsg"></param> /// <returns></returns> private static IFailedTask CreateMockFailedTask(string taskId, string errorMsg) { Exception taskException; switch (errorMsg) { case TaskManager.TaskAppError: taskException = new IMRUTaskAppException(errorMsg); break; case TaskManager.TaskGroupCommunicationError: taskException = new IMRUTaskGroupCommunicationException(errorMsg); break; case TaskManager.TaskSystemError: taskException = new IMRUTaskSystemException(errorMsg); break; default: taskException = new IMRUTaskAppException(errorMsg); break; } IFailedTask failedtask = Substitute.For <IFailedTask>(); failedtask.Id.Returns(taskId); failedtask.Message.Returns(errorMsg); failedtask.AsError().Returns(taskException); failedtask.GetActiveContext().Returns(Optional <IActiveContext> .Empty()); return(failedtask); }
public void OnNext(IFailedTask value) { // Check that Exceptions are deserialized correctly. var ex = value.AsError(); if (ex == null) { throw new Exception("Exception was not expected to be null."); } var taskStartEx = ex as TaskStartExceptionTestException; Assert.True(taskStartEx != null, "Expected Exception to be of type TaskStartExceptionTestException, but instead got type " + ex.GetType().Name); Assert.True(taskStartEx.Message.Equals(TaskStartExceptionMessage), "Expected message to be " + TaskStartExceptionMessage + " but instead got " + taskStartEx.Message + "."); Logger.Log(Level.Info, FailedTaskReceived); // Submit the new Task to verify that the original Context accepts new Tasks. value.GetActiveContext().Value.SubmitTask( TaskConfiguration.ConfigurationModule .Set(TaskConfiguration.Identifier, "TaskID") .Set(TaskConfiguration.Task, GenericType <TaskStartExceptionResubmitTask> .Class) .Build()); }
/// <summary> /// Gets error type (encoded as TaskStateEvent) based on the exception type in IFailedTask. /// For unknown exceptions or exceptions that doesn't belong to defined IMRU task exceptions /// treat then as application error. /// </summary> private TaskStateEvent GetTaskErrorEventByExceptionType(IFailedTask failedTask) { var exception = failedTask.AsError(); var innerExceptionType = exception.InnerException != null?exception.InnerException.GetType().ToString() : "InnerException null"; var innerExceptionMsg = exception.InnerException != null ? exception.InnerException.Message : "No InnerException"; if (failedTask.GetActiveContext().IsPresent()) { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType: with task id: {0}, exception type {1}, innerException type {2}, InnerExceptionMessage {3}, evaluator id: {4}", failedTask.Id, exception.GetType(), innerExceptionType, innerExceptionMsg, failedTask.GetActiveContext().Value.EvaluatorId); } else { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType: with task id: {0}, exception type {1}, innerException type {2}, InnerExceptionMessage {3}", failedTask.Id, exception.GetType(), innerExceptionType, innerExceptionMsg); } if (exception is IMRUTaskAppException) { _numberOfAppErrors++; return(TaskStateEvent.FailedTaskAppError); } if (exception is IMRUTaskGroupCommunicationException) { return(TaskStateEvent.FailedTaskCommunicationError); } if (exception is IMRUTaskSystemException) { return(TaskStateEvent.FailedTaskSystemError); } // special case for communication error during group communication initialization if (exception is TaskClientCodeException) { // try extract cause and check whether it is InjectionException for GroupCommClient if (exception.InnerException != null && exception.InnerException is InjectionException && exception.InnerException.Message.Contains("GroupCommClient")) { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType:FailedTaskCommunicationError with task id {0}", failedTask.Id); return(TaskStateEvent.FailedTaskCommunicationError); } } Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType for un-hanlded exception with task id {0} and exception type {1}", failedTask.Id, exception.GetType()); return(TaskStateEvent.FailedTaskSystemError); }
/// <summary> /// Verify Exception message and exception type for different task id. /// </summary> /// <param name="value"></param> public void OnNext(IFailedTask value) { var msg = string.Format(CultureInfo.InvariantCulture, "In IFailedTask, taskId: {0}, Message {1}, Exception {2}.", value.Id, value.Message, value.AsError().GetType()); Logger.Log(Level.Info, msg); if (value.Id.Equals(TaskId + 1)) { Assert.Equal(TaskManager.TaskAppError, value.Message); if (value.AsError() == null || !(value.AsError() is IMRUTaskAppException)) { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Exception {0} should have been serialized properly.", typeof(IMRUTaskAppException))); } } if (value.Id.Equals(TaskId + 2)) { Assert.Equal(TaskManager.TaskGroupCommunicationError, value.Message); if (value.AsError() == null || !(value.AsError() is IMRUTaskGroupCommunicationException)) { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Exception {0} should have been serialized properly.", typeof(IMRUTaskGroupCommunicationException))); } } if (value.Id.Equals(TaskId + 3)) { Assert.Equal(TaskManager.TaskSystemError, value.Message); if (value.AsError() == null || !(value.AsError() is IMRUTaskSystemException)) { throw new Exception(string.Format(CultureInfo.InvariantCulture, "Exception {0} should have been serialized properly.", typeof(IMRUTaskSystemException))); } Assert.Equal(InnerExceptionMessage, value.AsError().InnerException.Message); Assert.True(value.AsError().InnerException is ReefRuntimeException); } Logger.Log(Level.Info, ValidFailedTaskMessage); value.GetActiveContext().Value.Dispose(); }
/// <summary> /// Verify when exception is shown in task, IFailedTask will be received here with the message set in the task /// And verify the context associated with the failed task is the same as the context that the task was submitted /// </summary> /// <param name="value"></param> public void OnNext(IFailedTask value) { Assert.Equal(TaskId + "2", value.Id); var failedException = ByteUtilities.ByteArraysToString(value.Data.Value); var e = value.AsError(); Logger.Log(Level.Error, "In IFailedTask: e.type: {0}, e.message: {1}.", e.GetType(), e.Message); Logger.Log(Level.Error, "In IFailedTask: value.Data.Value: {0}, value.Message {1}.", failedException, value.Message); Assert.Equal(typeof(Exception), e.GetType()); Assert.Equal(TaskKilledByDriver, e.Message); Assert.Contains(TaskKilledByDriver, failedException); value.GetActiveContext().Value.Dispose(); }
public void OnNext(IFailedTask value) { var taskClientCodeEx = value.AsError() as TaskClientCodeException; if (taskClientCodeEx == null) { throw new Exception("Expected Exception to be a TaskClientCodeException."); } if (taskClientCodeEx.ContextId != ContextId) { throw new Exception("Expected Context ID to be " + ContextId + ", but instead got " + taskClientCodeEx.ContextId); } if (taskClientCodeEx.TaskId != TaskId) { throw new Exception("Expected Task ID to be " + TaskId + ", but instead got " + taskClientCodeEx.TaskId); } Exception error = taskClientCodeEx; var foundErrorMessage = false; while (error != null) { // Using Contains because the Exception may not be serializable // and the message of the wrapping Exception may be expanded to include more details. if (error.Message.Contains(TestConstructorExceptionTask.ConstructorErrorMessage)) { foundErrorMessage = true; break; } error = error.InnerException; } if (!foundErrorMessage) { throw new Exception("Expected to find error message " + TestConstructorExceptionTask.ConstructorErrorMessage + " in the layer of Exceptions."); } Logger.Log(Level.Info, ReceivedFailedTaskEvent); value.GetActiveContext().Value.Dispose(); }
/// <summary> /// Gets error type based on the exception type in IFailedTask /// </summary> /// <param name="failedTask"></param> /// <returns></returns> private TaskStateEvent GetTaskErrorEventByExceptionType(IFailedTask failedTask) { var exception = failedTask.AsError(); if (exception is IMRUTaskAppException) { _numberOfAppErrors++; return(TaskStateEvent.FailedTaskAppError); } if (exception is IMRUTaskGroupCommunicationException) { return(TaskStateEvent.FailedTaskCommunicationError); } else { return(TaskStateEvent.FailedTaskSystemError); } }
/// <summary> /// Gets error type (encoded as TaskStateEvent) based on the exception type in IFailedTask. /// For unknown exceptions or exceptions that doesn't belong to defined IMRU task exceptions /// treat then as application error. /// </summary> /// <param name="failedTask"></param> /// <returns></returns> private TaskStateEvent GetTaskErrorEventByExceptionType(IFailedTask failedTask) { var exception = failedTask.AsError(); var innerExceptionType = exception.InnerException != null ? exception.InnerException.GetType().ToString() : "InnerException null"; var innerExceptionMsg = exception.InnerException != null ? exception.InnerException.Message : "No InnerException"; if (failedTask.GetActiveContext().IsPresent()) { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType: with task id: {0}, exception type {1}, innerException type {2}, InnerExceptionMessage {3}, evaluator id: {4}", failedTask.Id, exception.GetType(), innerExceptionType, innerExceptionMsg, failedTask.GetActiveContext().Value.EvaluatorId); } else { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType: with task id: {0}, exception type {1}, innerException type {2}, InnerExceptionMessage {3}", failedTask.Id, exception.GetType(), innerExceptionType, innerExceptionMsg); } if (exception is IMRUTaskAppException) { _numberOfAppErrors++; return TaskStateEvent.FailedTaskAppError; } if (exception is IMRUTaskGroupCommunicationException) { return TaskStateEvent.FailedTaskCommunicationError; } if (exception is IMRUTaskSystemException) { return TaskStateEvent.FailedTaskSystemError; } // special case for communication error during group communication initialization if (exception is TaskClientCodeException) { // try extract cause and check whether it is InjectionException for GroupCommClient if (exception.InnerException != null && exception.InnerException is InjectionException && exception.InnerException.Message.Contains("GroupCommClient")) { Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType:FailedTaskCommunicationError with task id {0}", failedTask.Id); return TaskStateEvent.FailedTaskCommunicationError; } } Logger.Log(Level.Info, "GetTaskErrorEventByExceptionType for un-hanlded exception with task id {0} and exception type {1}", failedTask.Id, exception.GetType()); return TaskStateEvent.FailedTaskSystemError; }
/// <summary> /// Gets error type based on the exception type in IFailedTask /// </summary> /// <param name="failedTask"></param> /// <returns></returns> private TaskStateEvent GetTaskErrorEventByExceptionType(IFailedTask failedTask) { var exception = failedTask.AsError(); if (exception is IMRUTaskAppException) { _numberOfAppErrors++; return TaskStateEvent.FailedTaskAppError; } if (exception is IMRUTaskGroupCommunicationException) { return TaskStateEvent.FailedTaskCommunicationError; } else { return TaskStateEvent.FailedTaskSystemError; } }