Example #1
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>
        private static void ZipAndOrderingCore(int range)
        {
            //Console.Write("       DOP: ");
            for (int dop = 1; dop <= 30; dop++)
            {
                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;
                }


                Assert.NotNull(ex != null);
                Assert.False(AggregateExceptionContains(ex, typeof(OperationCanceledException)), string.Format("PLinqDelegateExceptions.ZipAndOrdering Range: {0}: the wrong exception was inside the aggregate exception.", range));
                Assert.True(AggregateExceptionContains(ex, typeof(UserDelegateException)), string.Format("PLinqDelegateExceptions.ZipAndOrdering Range: {0}: the wrong exception was inside the aggregate exception.", range));
            }
        }
Example #2
0
        /// <summary>
        /// Heavily exercises OrderBy, but only throws one user delegate exception to simulate an occasional failure.
        /// </summary>
        private static void OrderBy_OnlyOneExceptionCore(int range)
        {
            for (int dop = 1; dop <= 30; dop++)
            {
                int indexForException = range / (2 * dop); // eg 1000 items on 4-core, throws on item 125.

                AggregateException caughtAggregateException = null;

                try
                {
                    var query = Enumerable.Range(0, range)
                                .AsParallel().WithDegreeOfParallelism(dop)
                                .OrderBy(i =>
                    {
                        UserDelegateException.ThrowIf(i == indexForException);
                        return(i);
                    }
                                         );
                    foreach (int i in query)
                    {
                    }
                }
                catch (AggregateException e)
                {
                    caughtAggregateException = e;
                }


                Assert.NotNull(caughtAggregateException);
                Assert.True(caughtAggregateException.InnerExceptions.Count == 1, string.Format("PLinqDelegateExceptions.OrderBy_OnlyOneException Range: {0}:  AggregateException.InnerExceptions != 1.", range));
            }
        }
Example #3
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);
        }
Example #4
0
        /// <summary>
        /// Heavily exercises OrderBy, but only throws one user delegate exception to simulate an occassional failure.
        ///
        /// </summary>
        internal static bool OrderBy_OnlyOneException(int range)
        {
            TestHarness.TestLog(String.Format("* OrderBy_OnlyOneException({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 + "            ");
                }
                int indexForException = range / (2 * dop); // eg 1000 items on 4-core, throws on item 125.

                AggregateException caughtAggregateException = null;

                try
                {
                    var query = Enumerable.Range(0, range)
                                .AsParallel().WithDegreeOfParallelism(dop)
                                .OrderBy(i => {
                        UserDelegateException.ThrowIf(i == indexForException);
                        return(i);
                    }
                                         );
                    foreach (int i in query)
                    {
                    }
                }
                catch (AggregateException e)
                {
                    caughtAggregateException = e;
                }


                success &= (caughtAggregateException != null);
                success &= (caughtAggregateException.InnerExceptions.Count == 1);
            }

            Console.WriteLine();
            return(success);
        }
Example #5
0
        public static void SelectJoin()
        {
            Exception caughtAggregateException = null;

            try
            {
                var query = new int[] { 1, 2, 3 }.AsParallel()
                .Select(i => UserDelegateException.Throw <int, int>(i))
                .Join(new int[] { 1 }.AsParallel(), i => i, j => j, (i, j) => 0);
                foreach (var x in query)
                {
                }
            }
            catch (AggregateException e)
            {
                caughtAggregateException = e;
            }

            Assert.NotNull(caughtAggregateException);
        }
Example #6
0
        public static void DistintOrderBySelect()
        {
            Exception caughtAggregateException = null;

            try
            {
                var query2 = new int[] { 1, 2, 3 }.AsParallel()
                .Distinct()
                .OrderBy(i => i)
                .Select(i => UserDelegateException.Throw <int, int>(i));
                foreach (var x in query2)
                {
                }
            }
            catch (AggregateException e)
            {
                caughtAggregateException = e;
            }
            Assert.NotNull(caughtAggregateException);
        }
Example #7
0
        /// <summary>
        /// Another basic test for a query that throws user delegate exceptions
        /// </summary>
        /// <returns></returns>
        internal static bool SelectJoin()
        {
            TestHarness.TestLog("* SelectJoin()");
            Exception caughtAggregateException = null;

            try
            {
                var query = new int[] { 1, 2, 3 }.AsParallel()
                .Select(i => UserDelegateException.Throw <int, int>(i))
                .Join(new int[] { 1 }.AsParallel(), i => i, j => j, (i, j) => 0);
                foreach (var x in query)
                {
                }
            }
            catch (AggregateException e)
            {
                caughtAggregateException = e;
            }

            return(caughtAggregateException != null);
        }
Example #8
0
        /// <summary>
        /// A basic test for a query that throws user delegate exceptions
        /// </summary>
        /// <returns></returns>
        internal static bool DistintOrderBySelect()
        {
            TestHarness.TestLog("* DistintOrderBySelect()");

            Exception caughtAggregateException = null;

            try
            {
                var query2 = new int[] { 1, 2, 3 }.AsParallel()
                .Distinct()
                .OrderBy(i => i)
                .Select(i => UserDelegateException.Throw <int, int>(i));
                foreach (var x in query2)
                {
                }
            }
            catch (AggregateException e)
            {
                caughtAggregateException = e;
            }

            return(caughtAggregateException != null);
        }
Example #9
0
        /// <summary>
        /// Heavily exercises OrderBy in the face of user-delegate exceptions.
        /// On CTP-M1, this would deadlock for DOP=7,9,11,... on 4-core, but works for DOP=1..6 and 8,10,12, ...
        ///
        /// In this test, every call to the key-selector delegate throws.
        /// </summary>
        private static void OrderByCore(int range)
        {
            for (int dop = 1; dop <= 30; dop++)
            {
                AggregateException caughtAggregateException = null;

                try
                {
                    var query = Enumerable.Range(0, range)
                                .AsParallel().WithDegreeOfParallelism(dop)
                                .OrderBy(i => UserDelegateException.Throw <int, int>(i));
                    foreach (int i in query)
                    {
                    }
                }
                catch (AggregateException e)
                {
                    caughtAggregateException = e;
                }

                Assert.NotNull(caughtAggregateException);
            }
        }
Example #10
0
        /// <summary>
        /// Heavily exercises OrderBy in the face of user-delegate exceptions.
        /// On CTP-M1, this would deadlock for DOP=7,9,11,... on 4-core, but works for DOP=1..6 and 8,10,12, ...
        ///
        /// In this test, every call to the key-selector delegate throws.
        /// </summary>
        internal static bool OrderBy(int range)
        {
            TestHarness.TestLog(String.Format("* OrderBy({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 caughtAggregateException = null;

                try
                {
                    var query = Enumerable.Range(0, range)
                                .AsParallel().WithDegreeOfParallelism(dop)
                                .OrderBy(i => UserDelegateException.Throw <int, int>(i));
                    foreach (int i in query)
                    {
                    }
                }
                catch (AggregateException e)
                {
                    caughtAggregateException = e;
                }

                success &= (caughtAggregateException != null);
            }

            Console.WriteLine();
            return(success);
        }