Example #1
0
        public void TestTaskAdapter()
        {
            Assert.AreEqual(3, Grid1.Cluster.Nodes().Count);

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

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

                Assert.AreEqual(1, res.Count);

                allNodes.UnionWith(res);
            }

            Assert.AreEqual(3, allNodes.Count);

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

            Assert.IsTrue(res2.Count > 0);

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

            Assert.AreEqual(3, allNodes.Count);
        }
        /// <summary>
        /// Execute task successfully.
        /// </summary>
        /// <returns>Task result.</returns>
        private int Execute()
        {
            JobErrs.Clear();

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

            return(res is GoodTaskResult ? ((GoodTaskResult)res).Res : ((BadTaskResult)res).Res);
        }
Example #3
0
        public void TestReducerInjection()
        {
            int res = Grid1.Compute().Apply(new InjectionClosure(), new List <int> {
                1, 1, 1
            }, new InjectionReducer());

            Assert.AreEqual(Grid1.Cluster.Nodes().Count, res);
        }
Example #4
0
        public void TestPortableJobAdapter()
        {
            for (int i = 0; i < 10; i++)
            {
                bool res = Grid1.Compute().Execute(new TestJobAdapterTask(), false);

                Assert.IsTrue(res);
            }
        }
Example #5
0
        public void TestBroadcastInOut()
        {
            ICollection <object> ress = Grid1.Compute().Broadcast(Func(false), 1);

            foreach (object res in ress)
            {
                CheckResult(res);
            }
        }
Example #6
0
        public void TestOutFuncResultPrimitive1()
        {
            ICollection <int> res = Grid1.Compute().Broadcast(new PortableOutFunc());

            Assert.AreEqual(3, res.Count);

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

            Assert.AreEqual(3, res.Count);

            foreach (int r in res)
            {
                Assert.AreEqual(11, r);
            }
        }
        public void TestClosureFailoverException()
        {
            for (int i = 0; i < 20; i++)
            {
                int res = Grid1.Compute().Call(new TestClosure());

                Assert.AreEqual(2, res);

                Cleanup();
            }
        }
Example #9
0
        public void TestAllTaskTypeAtSameTime()
        {
            Assert.AreEqual(_actions.Count, 6);

            var compute = Grid1.Compute();

            TestUtils.RunMultiThreaded(() =>
            {
                _actions[TestUtils.Random.Next(_actions.Count)](compute);
            }, 4, 60);
        }
Example #10
0
        public void TestTaskResultInt()
        {
            TestTask <int> task = new TestTask <int>();

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

            Assert.AreEqual(10, res);

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

            Assert.AreEqual(11, res);
        }
Example #11
0
        public void TestTaskResultLong()
        {
            TestTask <long> task = new TestTask <long>();

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

            Assert.AreEqual(10000000000, res);

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

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

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

            Assert.AreEqual(1.1f, res);

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

            Assert.AreEqual(-1.1f, res);
        }
Example #13
0
        public void TestExecuteSingleException()
        {
            try
            {
                Grid1.Compute().Call(OutFunc(true));

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

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

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

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

            Assert.AreEqual(101 * 1024, res.Length);
        }
Example #15
0
        public void TestApplyException()
        {
            try
            {
                Grid1.Compute().Apply(Func(true), 1);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
Example #16
0
        public void TestBroadcastInOutException()
        {
            try
            {
                Grid1.Compute().Broadcast(Func(true), 1);

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

            Assert.AreEqual(2, res);

            Cleanup();

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

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

            SerializableResult val = new SerializableResult(100);

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

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

            val.Val = 101;

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

            Assert.AreEqual(val.Val, res.Val);
        }
Example #19
0
        public void TestPortableObjectInTask()
        {
            IPortableObject taskArg = ToPortable(Grid1, new PortableTaskArgument(100));

            TestTask task = new TestTask(Grid1, taskArg);

            IPortableObject res = Grid1.Compute().Execute(task, taskArg);

            Assert.NotNull(res);

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

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

            Assert.AreEqual(400, resObj.Val);
        }
Example #20
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.Compute().Call(clos, new Reducer(false));

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

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

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

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

            Exception err = null;

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

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

            return(err);
        }
Example #23
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.Compute().Call(clos);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
Example #24
0
        public void TestApplyMultiple()
        {
            var args = new List <object>(MultiCloCnt);

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

            Console.WriteLine("START TASK");

            var ress = Grid1.Compute().Apply(Func(false), args);

            Console.WriteLine("END TASK.");

            foreach (object res in ress)
            {
                CheckResult(res);
            }
        }
Example #25
0
        public void TestApplyMultipleException()
        {
            ICollection <int> args = new List <int>(MultiCloCnt);

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

            try
            {
                Grid1.Compute().Apply(Func(true), args);

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
Example #26
0
        public void TestAppylMultipleReducerJobException()
        {
            List <object> args = new List <object>(MultiCloCnt);

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

            try
            {
                Grid1.Compute().Apply(Func(true), args, new Reducer(false));

                Assert.Fail();
            }
            catch (Exception e)
            {
                CheckError(e);
            }
        }
Example #27
0
        public void TestAppylMultipleReducerReduceException()
        {
            var args = new List <object>(MultiCloCnt);

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

            try
            {
                Grid1.Compute().Apply(Func(false), args, new Reducer(true));

                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(typeof(Exception), e.GetType());

                Assert.AreEqual(ErrMsg, e.Message);
            }
        }
Example #28
0
        public void TestApply()
        {
            object res = Grid1.Compute().Apply(Func(false), 1);

            CheckResult(res);
        }
Example #29
0
        public void TestSingleTaskType0()
        {
            Assert.AreEqual(_actions.Count, 6);

            TestUtils.RunMultiThreaded(() => _actions[0](Grid1.Compute()), 4, 20);
        }
Example #30
0
        public void TestExecuteSingle()
        {
            var res = Grid1.Compute().Call(OutFunc(false));

            CheckResult(res);
        }