Example #1
0
        /// <summary>
        /// If the user delegate throws an OperationCanceledException, it should get aggregated.
        /// </summary>
        /// <returns></returns>
        internal static bool OperationCanceledExceptionsGetAggregated()
        {
            TestHarness.TestLog("* OperationCanceledExceptionsGetAggregated()");
            AggregateException caughtAggregateException = null;

            try
            {
                var enum1 = Enumerable.Range(1, 13);

                var query1 =
                    enum1
                    .AsParallel()
                    .Select <int, int>(i => { throw new OperationCanceledException(); });
                var output = query1.ToArray();
            }
            catch (AggregateException ae)
            {
                caughtAggregateException = ae;
            }

            bool success = true;

            success &= caughtAggregateException != null;
            success &= PlinqDelegateExceptionHelpers.AggregateExceptionContains(caughtAggregateException,
                                                                                typeof(OperationCanceledException));
            return(success);
        }
Example #2
0
        /// <summary>
        /// Zip with ordering on showed issues, but it was due to the ordering component.
        /// This is included as a regression test for that particular repro.
        /// </summary>
        /// <param name="range"></param>
        /// <returns></returns>
        internal static bool ZipAndOrdering(int range)
        {
            TestHarness.TestLog(String.Format("* ZipAndOrdering({0})", range));
            bool success = true;

            Console.Write("       DOP: ");
            for (int dop = 1; dop <= 30; dop++)
            {
                Console.Write(dop.ToString("00") + ".. ");
                if (dop % 10 == 0)
                {
                    Console.Write(Environment.NewLine + "            ");
                }
                AggregateException ex = null;
                try
                {
                    var enum1 = Enumerable.Range(1, range);
                    var enum2 = Enumerable.Repeat(1, range * 2);

                    var query1 = enum1
                                 .AsParallel()
                                 .AsOrdered().WithDegreeOfParallelism(dop)
                                 .Zip(enum2.AsParallel().AsOrdered(),
                                      (a, b) => UserDelegateException.Throw <int, int, int>(a, b));

                    var output = query1.ToArray();
                }
                catch (AggregateException ae)
                {
                    ex = ae;
                }


                success &= (ex != null);
                success &= (false ==
                            PlinqDelegateExceptionHelpers.AggregateExceptionContains(ex,
                                                                                     typeof(OperationCanceledException)));
                success &=
                    (PlinqDelegateExceptionHelpers.AggregateExceptionContains(ex, typeof(UserDelegateException)));
            }
            Console.WriteLine();
            return(success);
        }