Пример #1
0
        public void LocalExecutorTimedOutJoinTest()
        {
            var testMethod = new Func<object[], object>(
                (parameters) =>
                    {
                        while (true)
                        {
                            Thread.Sleep(10);
                        }
                    });

            var executor = new LocalExecutor();
            executor.InitializeNonGeneric(testMethod);
            executor.Execute(null);
            executor.Join(timeout: new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 30));

            executor.ElapsedTime.Value.ShouldBeLessThan(new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 3, milliseconds: 0));

            // join with timeout shouldn't abort thread
            // executor.Exception.GetType().ShouldBe(typeof(ThreadAbortException));
        }
Пример #2
0
        /// <summary>
        /// Initializes remote executor.
        /// </summary>
        /// <param name="methodHandle">Serialized runtime method handle.</param>
        /// <returns>Identifier of the executor.</returns>
        /// <exception cref="ArgumentException">Thrown if method pointed by the handle is not static.</exception>
        public Guid Initialize(byte[] methodHandle)
        {
            try
            {
                var methodFromHandle = methodHandle.DeserializeMethodHandle();
                if (!methodFromHandle.IsStatic)
                {
                    throw new ArgumentException("Executor supports only static methods.", "methodHandle");
                }

                var sourcePort = RemoteExecutorService.GetPortNumberFromRequest();
                if (!Executors.ContainsKey(sourcePort))
                {
                    Executors.TryAdd(sourcePort, new ConcurrentDictionary<Guid, ILocalExecutor>());
                }

                ILocalExecutor executor;
                do
                {
                    executor = new LocalExecutor();
                }
                while (!Executors[sourcePort].TryAdd(executor.Eid, executor));

                InitializeLocalExecutor(executor, methodFromHandle);

                return executor.Eid;
            }
            catch (Exception ex)
            {
                Log.ExceptionMessage(ex, Log.Activity.Info);
                throw;
            }
        }