Ejemplo n.º 1
0
        public void Bug_ConcurrentMerge()
        {
            const int reps = 1000;
            var source = Enumerable.Range(0, reps).ToObservable();

            var resultQueue = new System.Collections.Concurrent.ConcurrentQueue<int>();
            var r = new Random();

            source.Select(i => Observable.Create<Unit>(o =>
            {
                resultQueue.Enqueue(i);
                System.Threading.Tasks.Task.Factory.StartNew(
                    () =>
                    {
                        Thread.Sleep(r.Next(10));
                        o.OnCompleted();
                    });
                return () => { };
            })).Merge(3).ForEach(_ => { });

            Assert.IsTrue(Enumerable.Range(0, reps).ToList().SequenceEqual(resultQueue.ToList()));
        }
Ejemplo n.º 2
0
        public void Bug_ConcurrentMerge()
        {
            const int reps   = 1000;
            var       source = Enumerable.Range(0, reps).ToObservable();

            var resultQueue = new System.Collections.Concurrent.ConcurrentQueue <int>();
            var r           = new Random();

            source.Select(i => Observable.Create <Unit>(o =>
            {
                resultQueue.Enqueue(i);
                System.Threading.Tasks.Task.Factory.StartNew(
                    () =>
                {
                    Thread.Sleep(r.Next(10));
                    o.OnCompleted();
                });
                return(() => { });
            })).Merge(3).ForEach(_ => { });

            Assert.IsTrue(Enumerable.Range(0, reps).ToList().SequenceEqual(resultQueue.ToList()));
        }
Ejemplo n.º 3
0
        private void RegistrationTimerCallback(object state)
        {
            if (disposed)
            {
                return;
            }

            try
            {
                StopRegistrationTimer();
                if (!RouteRegistered)
                {
                    try
                    {
                        RegisterRoute(RegisteredContexts.Union(contextsToRegister.ToList()));
                    }
                    catch (Exceptions.CommandFailureException ex)
                    {
                        if (ex.InnerException is WebException && (
                                (ex.InnerException as WebException).Status == WebExceptionStatus.ConnectFailure ||
                                (ex.InnerException as WebException).Status == WebExceptionStatus.Timeout
                                ))
                        {
                            if (log != null && log.IsErrorEnabled)
                            {
                                log.Error("RegistrationTimerCallback() Could not connect to mod_cluster for STATUS command - " + ex.Message + " on " + ClusterUri);
                            }
                            return;
                        }
                        else
                        if (log != null && log.IsErrorEnabled)
                        {
                            log.Error("RegistrationTimerCallback() CommandFailureException on " + ClusterUri, ex);
                        }
                        return;
                    }
                    catch (Exception ex)
                    {
                        if (log != null && log.IsErrorEnabled)
                        {
                            log.Error("RegistrationTimerCallback() failed to RegisterRoute, wait til next timer callback");
                        }
                        return;
                    }
                }
                while (RouteRegistered && contextsToRegister.Count > 0)
                {
                    try
                    {
                        string context = null;
                        if (!contextsToRegister.TryDequeue(out context))
                        {
                            return;
                        }
                        if (log != null && log.IsDebugEnabled)
                        {
                            log.Debug("RegistrationTimerCallback() trying to register context " + context);
                        }
                        RegisterContextPath(context);
                    }
                    catch (Exception ex)
                    {
                        if (log != null && log.IsErrorEnabled)
                        {
                            log.Error("RegistrationTimerCallback() failed to add context, wait til next timer callback");
                        }
                        return;
                    }
                }
            }
            finally
            {
                StartRegistrationTimer();
            }
        }