public void Then_Should_Throw_Exception_After_Tasks_Fail() { var exceptionToThrow = new ArgumentNullException(); var firstTask = new PandaTask(); var secondTask = new PandaTask(); var continiueTask = firstTask.Then(() => secondTask).Fail(_ => throw exceptionToThrow); Assert.IsNull(continiueTask.Error); Exception finalException = null; try { secondTask.Reject(); firstTask.Reject(); } catch (Exception e) when(e is ArgumentNullException nullException) { finalException = nullException; } Assert.That(exceptionToThrow, Is.EqualTo(finalException)); Assert.IsAssignableFrom <TaskRejectedException>(continiueTask.Error); }
public void RejectTest() { //arrange var testTask = new PandaTask <int>(); //act Exception testException = new Exception(); testTask.Reject(testException); //assert Assert.AreEqual(testException, testTask.Error); Exception realException = null; try { var _ = testTask.Result; } catch (Exception exception) { realException = exception; } Assert.AreEqual(testException, realException); }
public void SetValueTest() { //arrange var testTask = new PandaTask <int>(); int callbackResult = 0; testTask.Done(x => callbackResult = x); bool rejected = false; testTask.Fail(x => rejected = true); //act const int testValue = 32; testTask.SetValue(testValue); //assert Assert.False(rejected); Assert.Null(testTask.Error); Assert.AreEqual(testValue, callbackResult); Assert.AreEqual(testValue, testTask.Result); Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status); }
public void CatchWithTaskTest() { //arrange Exception realEception = null; IPandaTask nextTask = new PandaTask(); IPandaTask NextTaskCallback(Exception ex) { realEception = ex; return(nextTask); } Exception excpectException = new Exception(); _task.Reject(excpectException); //act IPandaTask rejectTask = _task.Catch(NextTaskCallback); var castedTask = rejectTask as ContinuationTaskFromPandaTask; var callback = RuntimeReflection.GetValue <Func <IPandaTask>, ContinuationTaskFromPandaTask>(@"_nextActionDelegate", castedTask); IPandaTask realTask = callback(); //assert Assert.NotNull(castedTask); Assert.True(castedTask.FromCatch); Assert.AreEqual(realTask, nextTask); Assert.AreEqual(excpectException, realEception); }
public void SetValueTest() { //arrange PandaTask <int> testTask = ConstructTask <int, int>(); //act-assert Assert.Throws <InvalidOperationException>(() => testTask.SetValue(42)); }
public void ResolveTest() { //arrange PandaTask <int> testTask = ConstructTask <int, int>(); //act-assert Assert.Throws <InvalidOperationException>(testTask.Resolve); }
/// <summary> /// Do the lookup! /// </summary> protected override void ProcessRecord() { // Setup for verbosity if we need it. var listener = new PSListener(this); Trace.Listeners.Add(listener); try { PandaTask t = null; bool needdatasets = OutputContainerNames.IsPresent || InputContainerNames.IsPresent; if (ParameterSetName == "TaskID") { t = TaskID.FindPandaJobWithTaskName(needdatasets); } if (ParameterSetName == "TaskObject") { t = PandaTaskObject.ID.FindPandaJobWithTaskName(needdatasets); } if (ParameterSetName == "TaskName") { t = TaskName.FindPandaJobWithTaskName(needdatasets); } if (ParameterSetName == "DatasetGRIDJob") { // Get the job and resulting dataset name. var job = JobParser.FindJob(JobName, JobVersion); var ds = job.ResultingDataSetName(DatasetName.Trim(), JobIteration); // Now, look up the job itself. t = (ds + "/").FindPandaJobWithTaskName(); } // We really can't deal with a bad task below. The returned objects are sufficiently complex. if (t == null) { throw new ArgumentException("Unable to find the task in panda: was it ever submitted?"); } // Dump the info to the output pipeline as requested. if (JobStatus.IsPresent) { WriteObject(t.status); } if (InputContainerNames.IsPresent) { WriteObject(t.DataSetNamesIN()); } if (OutputContainerNames.IsPresent) { WriteObject(t.DataSetNamesOUT()); } } finally { Trace.Listeners.Remove(listener); } }
public void SetValueAfterRejectTest() { //arrange var testTask = new PandaTask <int>(); testTask.Reject(); //act-assert Assert.Throws <InvalidOperationException>(() => testTask.SetValue(0)); }
public void DoubleRejectTest() { //arrange var testTask = new PandaTask <int>(); testTask.Reject(); //act-assert Assert.Throws <InvalidOperationException>(testTask.Reject); }
public void DoubleResolveTest() { //arrange var task = new PandaTask(); task.Resolve(); //act-assert Assert.Throws <InvalidOperationException>(task.Resolve); }
public void Init() { //create task _task = new PandaTask(); //exception handling _taskSuccess = false; _realException = null; _task.Fail(x => _realException = _realException == null ? x : null).Done(() => _taskSuccess = true); }
private Tuple <ContinuationTaskFromPandaTask, PandaTask> ConstructTask(bool fromCatch = false, Func <IPandaTask> nextTaskCallback = null) { var firstTask = new PandaTask(); if (nextTaskCallback == null) { nextTaskCallback = () => null; } return(new Tuple <ContinuationTaskFromPandaTask, PandaTask>(new ContinuationTaskFromPandaTask(firstTask, nextTaskCallback, fromCatch), firstTask)); }
/// <summary> /// Do the panda task lookup. Throw if we can't find the job. /// </summary> /// <param name="ds"></param> /// <returns></returns> private PandaTask FindPandaJobForDS(string ds) { PandaTask pandaJob = (ds + "/").FindPandaJobWithTaskName(); if (pandaJob == null) { throw new InvalidOperationException(string.Format("Unknown error - submitted job ({0},{1}) on dataset {2}, but no panda task found!", JobName, JobVersion, DatasetName)); } return(pandaJob); }
public void DisposeTest() { //arrange var testTask = new PandaTask <int>(); //act testTask.Dispose(); //assert Assert.AreEqual(PandaTaskStatus.Rejected, testTask.Status); Assert.IsInstanceOf <ObjectDisposedException>(testTask.Error); }
public void CreateTest() { //act PandaTask <int> testTask = ConstructTask <int, int>(); //assert Assert.AreEqual(PandaTaskStatus.Pending, testTask.Status); Assert.Throws <InvalidOperationException>(() => { var _ = testTask.Result; }); Assert.Null(testTask.Error); }
public void RejectFromCatchReolveTest() { //arrange PandaTask nextTask = new PandaTask(); Tuple <ContinuationTaskFromPandaTask, PandaTask> taskPair = ConstructTask(true, () => nextTask); taskPair.Item2.Reject( ); //act nextTask.Resolve(); //assert Assert.Null(taskPair.Item1.Error); Assert.AreEqual(PandaTaskStatus.Resolved, taskPair.Item1.Status); }
private PandaTask <TResult> ConstructTask <TFirstResult, TResult>(IPandaTask <TFirstResult> firstTask = null, bool fromCatch = false, Func <IPandaTask <TResult> > nextTaskCallback = null) { //create default task if (firstTask == null) { firstTask = new PandaTask <TFirstResult>(); } if (nextTaskCallback == null) { nextTaskCallback = () => null; } return(new ContinuationTaskFromPandaTask <TResult>(firstTask, nextTaskCallback, fromCatch)); }
public void Then_Should_Throw_Exception_After_Tasks_Resolve() { var firstTask = new PandaTask(); var secondTask = new PandaTask(); var continiueTask = firstTask.Then(() => secondTask).Done(() => throw new ArgumentNullException()); Assert.Throws <ArgumentNullException>(() => { secondTask.Resolve(); firstTask.Resolve(); }); Assert.IsNull(continiueTask.Error); }
public void ChainCatchTest() { //arrange var testTask = new PandaTask <int>(); var testTask2 = new PandaTask <int>(); var resultTask = testTask.Catch(x => testTask2); //act const int testValue = 1; testTask.SetValue(testValue); //assert Assert.AreEqual(testValue, resultTask.Result); }
public void ResolveAfterDisposeTest() { //arrange var innerTask = new PandaTask(); var task = new WhenAllPandaTask(new[] { innerTask }, CancellationStrategy.Aggregate); task.Dispose(); //act innerTask.Resolve(); //assert Assert.AreEqual(PandaTaskStatus.Rejected, task.Status); Assert.IsInstanceOf <ObjectDisposedException>(task.Error.GetBaseException()); }
public void ThenResultRejectFirstTest() { //arrange var firstTask = new PandaTask(); var nextTask = new PandaTask <int>(); IPandaTask <int> resultTask = firstTask.Then(() => nextTask); //act var testError = new Exception(); firstTask.Reject(testError); //assert Assert.AreEqual(PandaTaskStatus.Rejected, resultTask.Status); Assert.AreEqual(testError, resultTask.Error); }
public void Then_Should_Save_Exception_In_Stack_After_Tasks_Fail() { var rejectException = new Exception("some text"); var firstTask = new PandaTask(); var secondTask = new PandaTask(); var continiueTask = firstTask.Then(() => secondTask).Fail(_ => throw new ArgumentNullException()); try { secondTask.Reject(rejectException); firstTask.Reject(rejectException); } catch {} Assert.That(continiueTask.Error, Is.EqualTo(rejectException)); }
public void DisposeTest() { //arrange PandaTask <int> testTask = ConstructTask <int, int>(); //act testTask.Dispose(); //assert Assert.AreEqual(PandaTaskStatus.Rejected, testTask.Status); Assert.Throws <ObjectDisposedException>(() => { var _ = testTask.Result; }); Assert.IsInstanceOf <ObjectDisposedException>(testTask.Error); }
public void ThenResultResolveTest() { //arrange var firstTask = new PandaTask(); var nextTask = new PandaTask <int>(); IPandaTask <int> resultTask = firstTask.Then(() => nextTask); //act firstTask.Resolve(); const int testValue = 1; nextTask.SetValue(testValue); //assert Assert.AreEqual(PandaTaskStatus.Resolved, resultTask.Status); Assert.AreEqual(testValue, resultTask.Result); }
public void ResolveFromRejectTest() { //arrange var firstTask = new PandaTask <int>(); var secondTask = new PandaTask <int>(); const int realResult = 3; PandaTask <int> testTask = ConstructTask(firstTask, true, () => { secondTask.SetValue(realResult); return(secondTask); }); //act firstTask.Reject(); //assert Assert.AreEqual(realResult, testTask.Result); Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status); }
public void ResolveTaskTest() { //arrange var firstTask = new PandaTask <int>(); var secondTask = new PandaTask <int>(); const int offset = 3; PandaTask <int> testTask = ConstructTask(firstTask, false, () => { secondTask.SetValue(firstTask.Result + offset); return(secondTask); }); //act firstTask.Resolve(); //assert Assert.AreEqual(firstTask.Result + offset, testTask.Result); Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status); }
public void ChangeCollectionCompleteErrorTest() { //arrange var source = new PandaTask(); var tasks = new List <IPandaTask> { PandaTasksUtilities.CompletedTask, source }; var allTask = new WhenAllPandaTask(tasks, CancellationStrategy.Aggregate); tasks.Add(PandaTasksUtilities.CanceledTask); //act source.Resolve(); //assert Assert.AreEqual(PandaTaskStatus.Resolved, allTask.Status); }
public void RejectResultTest() { //arrange var firstTask = new PandaTask <int>(); var secondTask = new PandaTask <int>(); const int realResult = 3; bool callbackCalled = false; PandaTask <int> testTask = new ContinuationTaskFromPandaTask <int>(firstTask, () => { callbackCalled = true; return(secondTask); }, true); //act firstTask.SetValue(realResult); //assert Assert.False(callbackCalled); Assert.AreEqual(realResult, testTask.Result); Assert.AreEqual(PandaTaskStatus.Resolved, testTask.Status); }
public void ResolveSecondTest() { //arrange PandaTask nextTask = new PandaTask(); Tuple <ContinuationTaskFromPandaTask, PandaTask> taskPair = ConstructTask(false, () => nextTask); bool doneCall = false; bool catchCall = false; taskPair.Item1.Done(() => doneCall = true).Fail(ex => catchCall = true); taskPair.Item2.Resolve(); //act nextTask.Resolve(); //assert Assert.True(doneCall); Assert.False(catchCall); Assert.Null(taskPair.Item1.Error); Assert.AreEqual(taskPair.Item1.Status, PandaTaskStatus.Resolved); }
public void ChangeCollectionCompleteWithErrorTest() { //arrange var source = new PandaTask(); var tasks = new List <IPandaTask> { PandaTasksUtilities.CompletedTask, source }; var allTask = new WhenAllPandaTask(tasks, CancellationStrategy.Aggregate); tasks.Add(PandaTasksUtilities.CanceledTask); //act var testError = new Exception(); source.Reject(testError); //assert Assert.AreEqual(PandaTaskStatus.Rejected, allTask.Status); Assert.IsInstanceOf <AggregateException>(allTask.Error); CollectionAssert.AreEqual(new[] { testError }, (( AggregateException )allTask.Error).InnerExceptions); }