예제 #1
0
        public void TestExecuteMultipleReduced()
        {
            var clos = Enumerable.Range(0, MultiCloCnt).Select(x => OutFunc(false)).ToArray();

            Grid1.GetCompute().Call(clos, new Reducer(false)).ToList().ForEach(CheckResult);
            Grid1.GetCompute().CallAsync(clos, new Reducer(false)).Result.ToList().ForEach(CheckResult);
        }
예제 #2
0
        public void TestApplyMultipleReducer()
        {
            var args = Enumerable.Repeat(1, MultiCloCnt).Cast <object>().ToArray();

            Grid1.GetCompute().Apply(Func(false), args, new Reducer(false)).ToList().ForEach(CheckResult);
            Grid1.GetCompute().ApplyAsync(Func(false), args, new Reducer(false)).Result.ToList().ForEach(CheckResult);
        }
예제 #3
0
        public void TestAppylMultipleReducerJobException()
        {
            var args = Enumerable.Repeat(1, MultiCloCnt).Cast <object>().ToArray();

            CheckError(Assert.Catch(() => Grid1.GetCompute().Apply(Func(true), args, new Reducer(false))));
            CheckError(Assert.Catch(() => Grid1.GetCompute().ApplyAsync(Func(true), args, new Reducer(false)).Wait()));
        }
예제 #4
0
        public void TestTaskAdapter()
        {
            Assert.AreEqual(3, Grid1.GetCluster().GetNodes().Count);

            HashSet <Guid> allNodes = new HashSet <Guid>();

            for (int i = 0; i < 20 && allNodes.Count < 3; i++)
            {
                HashSet <Guid> res = Grid1.GetCompute().Execute(new TestSplitTask(), 1);

                Assert.AreEqual(1, res.Count);

                allNodes.UnionWith(res);
            }

            Assert.AreEqual(3, allNodes.Count);

            HashSet <Guid> res2 = Grid1.GetCompute().Execute <int, Guid, HashSet <Guid> >(typeof(TestSplitTask), 3);

            Assert.IsTrue(res2.Count > 0);

            Grid1.GetCompute().Execute(new TestSplitTask(), 100);

            Assert.AreEqual(3, allNodes.Count);
        }
예제 #5
0
        public void TestExecuteMultipleException()
        {
            // Some closures will be faulty.
            var clos = Enumerable.Range(0, MultiCloCnt).Select(x => OutFunc(x % 2 == 0)).ToArray();

            CheckError(Assert.Catch(() => Grid1.GetCompute().Call(clos)));
            CheckError(Assert.Catch(() => Grid1.GetCompute().CallAsync(clos).Wait()));
        }
예제 #6
0
        public void TestReducerInjection()
        {
            int res = Grid1.GetCompute().Apply(new InjectionClosure(), new List <int> {
                1, 1, 1
            }, new InjectionReducer());

            Assert.AreEqual(3, res);
        }
예제 #7
0
        /// <summary>
        /// Execute task successfully.
        /// </summary>
        /// <returns>Task result.</returns>
        private int Execute()
        {
            JobErrs.Clear();

            object res = Grid1.GetCompute().Execute(new Task());

            return(res is GoodTaskResult ? ((GoodTaskResult)res).Res : ((BadTaskResult)res).Res);
        }
예제 #8
0
        public void TestAppylMultipleReducerReduceException()
        {
            var args = Enumerable.Repeat(1, MultiCloCnt).Cast <object>().ToArray();

            var e = Assert.Throws <Exception>(() => Grid1.GetCompute().Apply(Func(false), args, new Reducer(true)));

            Assert.AreEqual(ErrMsg, e.Message);
        }
예제 #9
0
        public void TestBinarizableJobAdapter()
        {
            for (int i = 0; i < 10; i++)
            {
                bool res = Grid1.GetCompute().Execute(new TestJobAdapterTask(), false);

                Assert.IsTrue(res);
            }
        }
예제 #10
0
        public void TestBroadcastInOut()
        {
            ICollection <object> ress = Grid1.GetCompute().Broadcast(Func(false), 1);

            foreach (object res in ress)
            {
                CheckResult(res);
            }
        }
        /// <summary>
        /// Execute task with error.
        /// </summary>
        /// <returns>Task</returns>
        private Exception ExecuteWithError()
        {
            JobErrs.Clear();

            var ex = Assert.Throws <AggregateException>(() => Grid1.GetCompute().Execute(new Task()));

            Assert.IsNotNull(ex.InnerException);
            return(ex.InnerException);
        }
        public void TestAllTaskTypeAtSameTime()
        {
            Assert.AreEqual(_actions.Count, 6);

            var compute = Grid1.GetCompute();

            TestUtils.RunMultiThreaded(() =>
            {
                _actions[TestUtils.Random.Next(_actions.Count)](compute);
            }, 4, 60);
        }
예제 #13
0
        public void TestClosureFailoverException()
        {
            for (int i = 0; i < 20; i++)
            {
                int res = Grid1.GetCompute().Call(new TestClosure());

                Assert.AreEqual(2, res);

                Cleanup();
            }
        }
예제 #14
0
        public void TestOutFuncResultPrimitive1()
        {
            ICollection <int> res = Grid1.GetCompute().Broadcast(new BinarizableOutFunc());

            Assert.AreEqual(2, res.Count);

            foreach (int r in res)
            {
                Assert.AreEqual(10, r);
            }
        }
예제 #15
0
        public void TestFuncResultPrimitive2()
        {
            ICollection <int> res = Grid1.GetCompute().Broadcast(new SerializableFunc(), 10);

            Assert.AreEqual(2, res.Count);

            foreach (int r in res)
            {
                Assert.AreEqual(11, r);
            }
        }
예제 #16
0
        public void TestTaskResultLong()
        {
            TestTask <long> task = new TestTask <long>();

            long res = Grid1.GetCompute().Execute(task, new Tuple <bool, long>(true, 10000000000));

            Assert.AreEqual(10000000000, res);

            res = Grid1.GetCompute().Execute(task, new Tuple <bool, long>(false, 10000000001));

            Assert.AreEqual(10000000001, res);
        }
예제 #17
0
        public void TestTaskResultFloat()
        {
            TestTask <float> task = new TestTask <float>();

            float res = Grid1.GetCompute().Execute(task, new Tuple <bool, float>(true, 1.1f));

            Assert.AreEqual(1.1f, res);

            res = Grid1.GetCompute().Execute(task, new Tuple <bool, float>(false, -1.1f));

            Assert.AreEqual(-1.1f, res);
        }
예제 #18
0
        public void TestTaskResultInt()
        {
            TestTask <int> task = new TestTask <int>();

            int res = Grid1.GetCompute().Execute(task, new Tuple <bool, int>(true, 10));

            Assert.AreEqual(10, res);

            res = Grid1.GetCompute().Execute(task, new Tuple <bool, int>(false, 11));

            Assert.AreEqual(11, res);
        }
예제 #19
0
        public void TestBroadcastInOutException()
        {
            try
            {
                Grid1.GetCompute().Broadcast(Func(true), 1);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
예제 #20
0
        public void TestApplyException()
        {
            try
            {
                Grid1.GetCompute().Apply(Func(true), 1);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
예제 #21
0
        public void TestTaskResultLarge()
        {
            TestTask <byte[]> task = new TestTask <byte[]>();

            byte[] res = Grid1.GetCompute().Execute(task,
                                                    new Tuple <bool, byte[]>(true, new byte[100 * 1024]));

            Assert.AreEqual(100 * 1024, res.Length);

            res = Grid1.GetCompute().Execute(task, new Tuple <bool, byte[]>(false, new byte[101 * 1024]));

            Assert.AreEqual(101 * 1024, res.Length);
        }
예제 #22
0
        public void TestExecuteSingleException()
        {
            try
            {
                Grid1.GetCompute().Call(OutFunc(true));

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
예제 #23
0
        /// <summary>
        /// Test for GridComputeJobFailoverException.
        /// </summary>
        private void TestTaskAdapterFailoverException(bool serializable)
        {
            int res = Grid1.GetCompute().Execute(new TestTask(),
                                                 new Tuple <bool, bool>(serializable, true));

            Assert.AreEqual(2, res);

            Cleanup();

            res = Grid1.GetCompute().Execute(new TestTask(),
                                             new Tuple <bool, bool>(serializable, false));

            Assert.AreEqual(2, res);
        }
예제 #24
0
        public void TestTaskResultSerializable()
        {
            TestTask <SerializableResult> task = new TestTask <SerializableResult>();

            SerializableResult val = new SerializableResult(100);

            SerializableResult res = Grid1.GetCompute().Execute(task, new Tuple <bool, SerializableResult>(true, val));

            Assert.AreEqual(val.Val, res.Val);

            val.Val = 101;

            res = Grid1.GetCompute().Execute(task, new Tuple <bool, SerializableResult>(false, val));

            Assert.AreEqual(val.Val, res.Val);
        }
예제 #25
0
        public void TestExecuteMultipleReduced()
        {
            var clos = new List <IComputeFunc <object> >(MultiCloCnt);

            for (int i = 0; i < MultiCloCnt; i++)
            {
                clos.Add(OutFunc(false));
            }

            ICollection <object> ress = Grid1.GetCompute().Call(clos, new Reducer(false));

            foreach (object res in ress)
            {
                CheckResult(res);
            }
        }
예제 #26
0
        public void TestApplyMultipleReducer()
        {
            var args = new List <object>(MultiCloCnt);

            for (int i = 0; i < MultiCloCnt; i++)
            {
                args.Add(1);
            }

            ICollection <object> ress =
                Grid1.GetCompute().Apply(Func(false), args, new Reducer(false));

            foreach (object res in ress)
            {
                CheckResult(res);
            }
        }
예제 #27
0
        public void TestBinarizableObjectInTask()
        {
            var taskArg = new BinarizableWrapper {
                Item = ToBinary(Grid1, new BinarizableTaskArgument(100))
            };

            TestTask task = new TestTask(Grid1, taskArg);

            var res = Grid1.GetCompute().Execute(task, taskArg).Item;

            Assert.NotNull(res);

            Assert.AreEqual(400, res.GetField <int>("val"));

            BinarizableTaskResult resObj = res.Deserialize <BinarizableTaskResult>();

            Assert.AreEqual(400, resObj.Val);
        }
예제 #28
0
        /// <summary>
        /// Execute task successfully.
        /// </summary>
        /// <returns>Task result.</returns>
        private int Execute()
        {
            JobErrs.Clear();

            Func <object, int> getRes = r => r is GoodTaskResult ? ((GoodTaskResult)r).Res : ((BadTaskResult)r).Res;

            var res1 = getRes(Grid1.GetCompute().Execute(new Task()));
            var res2 = getRes(Grid1.GetCompute().Execute <object, object>(typeof(Task)));

            var resAsync1 = getRes(Grid1.GetCompute().ExecuteAsync(new Task()).Result);
            var resAsync2 = getRes(Grid1.GetCompute().ExecuteAsync <object, object>(typeof(Task)).Result);

            Assert.AreEqual(res1, res2);
            Assert.AreEqual(res2, resAsync1);
            Assert.AreEqual(resAsync1, resAsync2);

            return(res1);
        }
예제 #29
0
        /// <summary>
        /// Execute task with error.
        /// </summary>
        /// <returns>Task</returns>
        private Exception ExecuteWithError()
        {
            JobErrs.Clear();

            Exception err = null;

            try
            {
                Grid1.GetCompute().Execute(new Task());

                Assert.Fail();
            }
            catch (Exception e)
            {
                err = e;
            }

            return(err);
        }
예제 #30
0
        public void TestExecuteMultipleException()
        {
            var clos = new List <IComputeFunc <object> >(MultiCloCnt);

            for (int i = 0; i < MultiCloCnt; i++)
            {
                clos.Add(OutFunc(i % 2 == 0)); // Some closures will be faulty.
            }
            try
            {
                Grid1.GetCompute().Call(clos);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }